From da038efab3d13da80ec66224989b9646ddff02e6 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 8 Jul 2025 03:34:11 +0200 Subject: [PATCH 1/3] rector: `CombineIfRector` - see https://getrector.com/rule-detail/combine-if-rector --- .rector.php | 1 - .../Block/Catalog/Category/Tab/General.php | 14 +- .../Form/Renderer/Fieldset/Element.php | 10 +- .../Catalog/Product/Edit/Tab/Inventory.php | 6 +- .../Block/Catalog/Product/Edit/Tabs.php | 39 ++-- .../Adminhtml/Block/Catalog/Product/Grid.php | 20 +- .../Catalog/Product/Helper/Form/Price.php | 8 +- .../Block/Permissions/Tab/Rolesedit.php | 8 +- .../Adminhtml/Block/Report/Grid/Abstract.php | 6 +- .../Block/Sales/Order/Create/Items/Grid.php | 20 +- .../Sales/Order/Creditmemo/Create/Items.php | 20 +- .../Block/Sales/Order/Invoice/View.php | 18 +- .../System/Convert/Gui/Edit/Tab/Wizard.php | 6 +- .../Adminhtml/Block/Widget/Grid/Column.php | 6 +- .../Adminhtml/Controller/Sales/Creditmemo.php | 25 ++- .../Adminhtml/Controller/Sales/Invoice.php | 26 ++- app/code/core/Mage/Adminhtml/Model/Config.php | 12 +- .../core/Mage/Adminhtml/Model/Observer.php | 6 +- .../Adminhtml/Model/Sales/Order/Create.php | 6 +- .../Model/System/Config/Backend/Filename.php | 12 +- .../Model/System/Config/Backend/Locale.php | 44 ++--- .../Catalog/CategoryController.php | 10 +- .../controllers/Catalog/ProductController.php | 16 +- .../controllers/CustomerController.php | 14 +- .../Permissions/UserController.php | 12 +- .../Config/System/StorageController.php | 12 +- app/code/core/Mage/Api/Model/Config.php | 6 +- .../Adminhtml/Sales/Order/Items/Renderer.php | 28 +-- .../Sales/Order/View/Items/Renderer.php | 28 +-- .../Block/Sales/Order/Items/Renderer.php | 16 +- .../core/Mage/Bundle/Model/Product/Price.php | 8 +- .../Bundle/Model/Resource/Price/Index.php | 8 +- .../Model/Sales/Order/Pdf/Items/Abstract.php | 22 +-- .../Sales/Order/Pdf/Items/Creditmemo.php | 76 ++++--- .../Model/Sales/Order/Pdf/Items/Invoice.php | 77 ++++---- .../Model/Sales/Order/Pdf/Items/Shipment.php | 77 ++++---- app/code/core/Mage/Captcha/Model/Observer.php | 56 +++--- .../Mage/Catalog/Block/Product/Abstract.php | 12 +- .../core/Mage/Catalog/Block/Product/List.php | 20 +- app/code/core/Mage/Catalog/Helper/Output.php | 12 +- app/code/core/Mage/Catalog/Helper/Product.php | 6 +- .../core/Mage/Catalog/Helper/Product/View.php | 8 +- .../core/Mage/Catalog/Model/Api/Resource.php | 6 +- .../Mage/Catalog/Model/Api2/Product/Rest.php | 26 +-- .../Model/Api2/Product/Rest/Admin/V1.php | 12 +- .../Model/Api2/Product/Validator/Product.php | 44 ++--- .../Category/Attribute/Backend/Sortby.php | 8 +- app/code/core/Mage/Catalog/Model/Design.php | 10 +- .../Model/Layer/Filter/Price/Algorithm.php | 6 +- .../Model/Product/Attribute/Backend/Media.php | 14 +- .../core/Mage/Catalog/Model/Product/Image.php | 6 +- .../Catalog/Model/Product/Option/Observer.php | 18 +- .../Model/Product/Option/Type/File.php | 6 +- .../Model/Product/Type/Configurable.php | 6 +- .../Model/Product/Type/Configurable/Price.php | 16 +- .../Mage/Catalog/Model/Product/Type/Price.php | 6 +- .../Catalog/Model/Resource/Eav/Attribute.php | 18 +- .../Configurable/Attribute/Collection.php | 30 ++- .../core/Mage/Catalog/Model/Resource/Url.php | 28 ++- .../controllers/CategoryController.php | 8 +- .../core/Mage/CatalogIndex/Model/Indexer.php | 187 +++++++++--------- .../CatalogIndex/Model/Resource/Indexer.php | 10 +- .../Mage/CatalogInventory/Model/Observer.php | 10 +- .../core/Mage/CatalogRule/Model/Observer.php | 6 +- .../Mage/CatalogSearch/Model/Advanced.php | 67 +++---- .../CatalogSearch/Model/Resource/Advanced.php | 8 +- .../Block/Adminhtml/Validation/Form.php | 14 +- .../Checkout/Block/Cart/Item/Renderer.php | 6 +- .../Mage/Checkout/Model/Cart/Coupon/Api.php | 6 +- app/code/core/Mage/Checkout/Model/Session.php | 8 +- .../core/Mage/Checkout/Model/Type/Onepage.php | 6 +- app/code/core/Mage/Cms/Helper/Page.php | 12 +- .../Block/Catalog/Layer/State/Swatch.php | 10 +- .../View/Type/Configurable/Swatches.php | 8 +- .../Mage/Core/Controller/Varien/Action.php | 50 ++--- .../Controller/Varien/Router/Standard.php | 18 +- app/code/core/Mage/Core/Helper/String.php | 6 +- app/code/core/Mage/Core/Model/Layout.php | 12 +- .../core/Mage/Core/Model/Layout/Update.php | 6 +- .../core/Mage/Core/Model/Layout/Validator.php | 16 +- app/code/core/Mage/Core/Model/Locale.php | 6 +- .../core/Mage/Core/Model/Resource/Cache.php | 16 +- .../Core/Model/Resource/File/Storage/File.php | 6 +- .../core/Mage/Core/Model/Resource/Session.php | 10 +- .../core/Mage/Core/Model/Session/Abstract.php | 6 +- app/code/core/Mage/Core/Model/Store.php | 30 ++- app/code/core/Mage/Core/Model/Translate.php | 22 +-- app/code/core/Mage/Core/Model/Url.php | 8 +- app/code/core/Mage/Cron/Model/Observer.php | 8 +- .../Model/System/Currencysymbol.php | 6 +- .../Mage/Customer/Model/Address/Abstract.php | 8 +- .../core/Mage/Customer/Model/Config/Share.php | 10 +- .../Customer/Attribute/Backend/Password.php | 6 +- app/code/core/Mage/Customer/Model/Session.php | 6 +- .../Mage/Downloadable/Model/Product/Price.php | 22 +-- .../Mage/Downloadable/Model/Product/Type.php | 12 +- .../Mage/Eav/Model/Attribute/Data/Image.php | 16 +- .../core/Mage/Eav/Model/Entity/Attribute.php | 6 +- .../Entity/Attribute/Backend/Abstract.php | 14 +- app/code/core/Mage/Index/Model/Indexer.php | 6 +- .../Mage/Index/Model/Indexer/Abstract.php | 6 +- app/code/core/Mage/Index/Model/Process.php | 6 +- .../core/Mage/Install/Model/Installer/Db.php | 10 +- app/code/core/Mage/Install/Model/Observer.php | 6 +- .../core/Mage/Log/Model/Resource/Visitor.php | 6 +- app/code/core/Mage/Log/Model/Visitor.php | 8 +- app/code/core/Mage/Page/Block/Html/Pager.php | 6 +- .../Mage/Payment/Block/Form/Container.php | 6 +- .../Mage/Payment/Block/Info/Container.php | 6 +- app/code/core/Mage/Payment/Model/Config.php | 10 +- app/code/core/Mage/Payment/Model/Info.php | 12 +- .../Mage/Payment/Model/Method/Abstract.php | 36 ++-- .../Mage/Payment/Model/Recurring/Profile.php | 8 +- app/code/core/Mage/Paypal/Helper/Data.php | 6 +- app/code/core/Mage/Paypal/Model/Api/Nvp.php | 12 +- .../Mage/Paypal/Model/Express/Checkout.php | 30 ++- .../Mage/Paypal/Model/Report/Settlement.php | 6 +- .../core/Mage/ProductAlert/Helper/Data.php | 6 +- .../ProductAlert/Model/Resource/Price.php | 16 +- .../ProductAlert/Model/Resource/Stock.php | 10 +- .../Report/Product/Viewed/Collection.php | 154 +++++++-------- .../Review/controllers/ProductController.php | 14 +- .../core/Mage/Rss/Block/Catalog/Abstract.php | 12 +- app/code/core/Mage/Rule/Model/Abstract.php | 6 +- app/code/core/Mage/Sales/Model/Order.php | 10 +- .../core/Mage/Sales/Model/Order/Payment.php | 7 +- .../Sales/Model/Order/Payment/Transaction.php | 12 +- app/code/core/Mage/Sales/Model/Quote.php | 12 +- .../Sales/Model/Quote/Address/Total/Tax.php | 41 ++-- app/code/core/Mage/Sales/Model/Quote/Item.php | 6 +- .../Mage/Sales/Model/Quote/Item/Abstract.php | 18 +- .../Report/Bestsellers/Collection.php | 154 +++++++-------- .../core/Mage/SalesRule/Model/Observer.php | 53 +++-- .../core/Mage/SalesRule/Model/Validator.php | 8 +- app/code/core/Mage/Tax/Helper/Data.php | 40 ++-- .../Mage/Tax/Model/Sales/Total/Quote/Tax.php | 14 +- .../Mage/Usa/Model/Shipping/Carrier/Dhl.php | 65 +++--- .../Mage/Usa/Model/Shipping/Carrier/Fedex.php | 16 +- .../Mage/Usa/Model/Shipping/Carrier/Usps.php | 187 +++++++++--------- app/code/core/Mage/Weee/Helper/Data.php | 16 +- .../core/Mage/Weee/Model/Total/Quote/Weee.php | 13 +- app/code/core/Mage/Wishlist/Model/Item.php | 6 +- .../core/Mage/Wishlist/Model/Observer.php | 20 +- install.php | 10 +- lib/Mage/Cache/Backend/File.php | 23 +-- lib/Mage/System/Ftp.php | 6 +- lib/Unserialize/Reader/Arr.php | 6 +- lib/Unserialize/Reader/Str.php | 14 +- lib/Varien/Cache/Backend/Database.php | 6 +- lib/Varien/Data/Form/Element/Date.php | 6 +- lib/Varien/Data/Tree/Dbp.php | 6 +- lib/Varien/Db/Select.php | 10 +- lib/Varien/Image/Adapter/Gd2.php | 8 +- lib/Varien/Io/Ftp.php | 20 +- 154 files changed, 1237 insertions(+), 1769 deletions(-) diff --git a/.rector.php b/.rector.php index 184966c3ef1..76fc08b6ccc 100644 --- a/.rector.php +++ b/.rector.php @@ -58,7 +58,6 @@ CodeQuality\FunctionLike\SimplifyUselessVariableRector::class, # todo: TMP CodeQuality\Identical\SimplifyBoolIdenticalTrueRector::class, # todo: TMP CodeQuality\Identical\SimplifyConditionsRector::class, # todo: TMP - CodeQuality\If_\CombineIfRector::class, # todo: TMP< CodeQuality\If_\CompleteMissingIfElseBracketRector::class, # todo: TMP (!?!) CodeQuality\If_\ExplicitBoolCompareRector::class, # todo: TMP CodeQuality\If_\SimplifyIfElseToTernaryRector::class, diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php index 351251cfa90..d4c5f4d8a47 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php @@ -61,14 +61,12 @@ public function _prepareLayout() $this->_setFieldset($this->getCategory()->getAttributes(true), $fieldset); - if ($this->getCategory()->getId()) { - if ($this->getCategory()->getLevel() == 1) { - $fieldset->removeField('url_key'); - $fieldset->addField('url_key', 'hidden', [ - 'name' => 'url_key', - 'value' => $this->getCategory()->getUrlKey(), - ]); - } + if ($this->getCategory()->getId() && $this->getCategory()->getLevel() == 1) { + $fieldset->removeField('url_key'); + $fieldset->addField('url_key', 'hidden', [ + 'name' => 'url_key', + 'value' => $this->getCategory()->getUrlKey(), + ]); } $form->addValues($this->getCategory()->getData()); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php index 9d5d4d104ee..7d48c1cdaac 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php @@ -59,14 +59,8 @@ public function getAttributeCode() */ public function canDisplayUseDefault() { - if ($attribute = $this->getAttribute()) { - if (!$attribute->isScopeGlobal() - && $this->getDataObject() - && $this->getDataObject()->getId() - && $this->getDataObject()->getStoreId() - ) { - return true; - } + if (($attribute = $this->getAttribute()) && (!$attribute->isScopeGlobal() && $this->getDataObject() && $this->getDataObject()->getId() && $this->getDataObject()->getStoreId())) { + return true; } return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php index d05951c6eb2..8b91d9255b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php @@ -84,10 +84,8 @@ public function getFieldValueAsFloat(string $field): float public function getConfigFieldValue($field) { - if ($this->getStockItem()) { - if ($this->getStockItem()->getData('use_config_' . $field) == 0) { - return $this->getStockItem()->getData($field); - } + if ($this->getStockItem() && $this->getStockItem()->getData('use_config_' . $field) == 0) { + return $this->getStockItem()->getData($field); } return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php index 92107b0c078..739d43fc605 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php @@ -123,29 +123,24 @@ protected function _prepareLayout() } if ($this->getRequest()->getParam('id', false)) { - if ($this->isModuleEnabled('Mage_Review', 'catalog')) { - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')) { - $this->addTab('reviews', [ - 'label' => Mage::helper('catalog')->__('Product Reviews'), - 'url' => $this->getUrl('*/*/reviews', ['_current' => true]), - 'class' => 'ajax', - ]); - } + if ($this->isModuleEnabled('Mage_Review', 'catalog') && Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')) { + $this->addTab('reviews', [ + 'label' => Mage::helper('catalog')->__('Product Reviews'), + 'url' => $this->getUrl('*/*/reviews', ['_current' => true]), + 'class' => 'ajax', + ]); } - if ($this->isModuleEnabled('Mage_Tag', 'catalog')) { - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')) { - $this->addTab('tags', [ - 'label' => Mage::helper('catalog')->__('Product Tags'), - 'url' => $this->getUrl('*/*/tagGrid', ['_current' => true]), - 'class' => 'ajax', - ]); - - $this->addTab('customers_tags', [ - 'label' => Mage::helper('catalog')->__('Customers Tagged Product'), - 'url' => $this->getUrl('*/*/tagCustomerGrid', ['_current' => true]), - 'class' => 'ajax', - ]); - } + if ($this->isModuleEnabled('Mage_Tag', 'catalog') && Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')) { + $this->addTab('tags', [ + 'label' => Mage::helper('catalog')->__('Product Tags'), + 'url' => $this->getUrl('*/*/tagGrid', ['_current' => true]), + 'class' => 'ajax', + ]); + $this->addTab('customers_tags', [ + 'label' => Mage::helper('catalog')->__('Customers Tagged Product'), + 'url' => $this->getUrl('*/*/tagCustomerGrid', ['_current' => true]), + 'class' => 'ajax', + ]); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php index 7a77faf6a79..c4cd11602eb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php @@ -113,17 +113,15 @@ protected function _prepareCollection() protected function _addColumnFilterToCollection($column) { - if ($this->getCollection()) { - if ($column->getId() === 'websites') { - $this->getCollection()->joinField( - 'websites', - 'catalog/product_website', - 'website_id', - 'product_id=entity_id', - null, - 'left', - ); - } + if ($this->getCollection() && $column->getId() === 'websites') { + $this->getCollection()->joinField( + 'websites', + 'catalog/product_website', + 'website_id', + 'product_id=entity_id', + null, + 'left', + ); } return parent::_addColumnFilterToCollection($column); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php index 8810057a38e..b9f3eae72e6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php @@ -40,11 +40,9 @@ public function getAfterElementHtml() } $store = Mage::app()->getStore($storeId); $html .= '[' . (string) $store->getBaseCurrencyCode() . ']'; - if (Mage::helper('tax')->priceIncludesTax($store)) { - if ($attribute->getAttributeCode() !== 'cost') { - $addJsObserver = true; - $html .= ' [' . Mage::helper('tax')->__('Inc. Tax') . ']'; - } + if (Mage::helper('tax')->priceIncludesTax($store) && $attribute->getAttributeCode() !== 'cost') { + $addJsObserver = true; + $html .= ' [' . Mage::helper('tax')->__('Inc. Tax') . ']'; } } if ($addJsObserver) { diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php index 7ef0b78df0e..ac7f38af839 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php @@ -82,11 +82,9 @@ public function __construct() /** @var Mage_Admin_Model_Rules $item */ foreach ($rules->getItems() as $item) { $itemResourceId = $item->getResource_id(); - if (array_key_exists(strtolower($itemResourceId), $resources)) { - if ($item->isAllowed()) { - $resources[$itemResourceId]['checked'] = true; - $selrids[] = $itemResourceId; - } + if (array_key_exists(strtolower($itemResourceId), $resources) && $item->isAllowed()) { + $resources[$itemResourceId]['checked'] = true; + $selrids[] = $itemResourceId; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php index 20a9fc8cf5f..25bbb39139a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php @@ -153,10 +153,8 @@ protected function _prepareCollection() $storeIds = $this->_getStoreIds(); $orderStatuses = $filterData->getData('order_statuses'); - if (is_array($orderStatuses)) { - if (count($orderStatuses) == 1 && str_contains($orderStatuses[0], ',')) { - $filterData->setData('order_statuses', explode(',', $orderStatuses[0])); - } + if (is_array($orderStatuses) && (count($orderStatuses) == 1 && str_contains($orderStatuses[0], ','))) { + $filterData->setData('order_statuses', explode(',', $orderStatuses[0])); } /** @var Mage_Sales_Model_Resource_Report_Collection_Abstract $resourceCollection */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php index b34a323a5a8..b045cad7761 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php @@ -44,17 +44,15 @@ public function getItems() // To dispatch inventory event sales_quote_item_qty_set_after, set item qty $item->setQty($item->getQty()); $stockItem = $item->getProduct()->getStockItem(); - if ($stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) { - // This check has been performed properly in Inventory observer, so it has no sense - /* - $check = $stockItem->checkQuoteItemQty($item->getQty(), $item->getQty(), $item->getQty()); - $item->setMessage($check->getMessage()); - $item->setHasError($check->getHasError()); - */ - if ($item->getProduct()->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { - $item->setMessage(Mage::helper('adminhtml')->__('This product is currently disabled.')); - $item->setHasError(true); - } + // This check has been performed properly in Inventory observer, so it has no sense + /* + $check = $stockItem->checkQuoteItemQty($item->getQty(), $item->getQty(), $item->getQty()); + $item->setMessage($check->getMessage()); + $item->setHasError($check->getHasError()); + */ + if ($stockItem instanceof Mage_CatalogInventory_Model_Stock_Item && $item->getProduct()->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { + $item->setMessage(Mage::helper('adminhtml')->__('This product is currently disabled.')); + $item->setHasError(true); } } $this->getQuote()->setIsSuperMode($oldSuperMode); diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php index b4b068e573b..4a84ed37921 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php @@ -160,19 +160,17 @@ public function canReturnToStock() */ public function canReturnItemsToStock() { - if (is_null($this->_canReturnToStock)) { - if ($this->_canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT)) { - $canReturnToStock = false; - foreach ($this->getCreditmemo()->getAllItems() as $item) { - $product = Mage::getModel('catalog/product')->load($item->getOrderItem()->getProductId()); - if ($product->getId() && $product->getStockItem()->getManageStock()) { - $item->setCanReturnToStock($canReturnToStock = true); - } else { - $item->setCanReturnToStock(false); - } + if (is_null($this->_canReturnToStock) && $this->_canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT)) { + $canReturnToStock = false; + foreach ($this->getCreditmemo()->getAllItems() as $item) { + $product = Mage::getModel('catalog/product')->load($item->getOrderItem()->getProductId()); + if ($product->getId() && $product->getStockItem()->getManageStock()) { + $item->setCanReturnToStock($canReturnToStock = true); + } else { + $item->setCanReturnToStock(false); } - $this->getCreditmemo()->getOrder()->setCanReturnToStock($this->_canReturnToStock = $canReturnToStock); } + $this->getCreditmemo()->getOrder()->setCanReturnToStock($this->_canReturnToStock = $canReturnToStock); } return $this->_canReturnToStock; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php index 5d19c14b6e6..ace2cf0bbd9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php @@ -58,18 +58,12 @@ public function __construct() $orderPayment = $this->getInvoice()->getOrder()->getPayment(); - if ($this->_isAllowedAction('creditmemo') && $this->getInvoice()->getOrder()->canCreditmemo()) { - if (($orderPayment->canRefundPartialPerInvoice() - && $this->getInvoice()->canRefund() - && $orderPayment->getAmountPaid() > $orderPayment->getAmountRefunded()) - || ($orderPayment->canRefund() && !$this->getInvoice()->getIsUsedForRefund()) - ) { - $this->_addButton('capture', [ // capture? - 'label' => Mage::helper('sales')->__('Credit Memo'), - 'class' => 'go', - 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getCreditMemoUrl()), - ]); - } + if ($this->_isAllowedAction('creditmemo') && $this->getInvoice()->getOrder()->canCreditmemo() && ($orderPayment->canRefundPartialPerInvoice() && $this->getInvoice()->canRefund() && $orderPayment->getAmountPaid() > $orderPayment->getAmountRefunded() || $orderPayment->canRefund() && !$this->getInvoice()->getIsUsedForRefund())) { + $this->_addButton('capture', [ // capture? + 'label' => Mage::helper('sales')->__('Credit Memo'), + 'class' => 'go', + 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getCreditMemoUrl()), + ]); } if ($this->_isAllowedAction('capture') && $this->getInvoice()->canCapture()) { diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php index 82a534c0e29..ca6a71b43c4 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php @@ -79,10 +79,8 @@ public function getAttributes($entityType) */ public function getValue($key, $default = '', $defaultNew = null) { - if ($defaultNew !== null) { - if ($this->getProfileId() == 0) { - $default = $defaultNew; - } + if ($defaultNew !== null && $this->getProfileId() == 0) { + $default = $defaultNew; } $value = $this->getData($key); diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php index cc7c2283ce9..49c31b71b74 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php @@ -205,10 +205,8 @@ public function getRowFieldExport(Varien_Object $row) */ protected function &_applyDecorators($value, $decorators) { - if (!is_array($decorators)) { - if (is_string($decorators)) { - $decorators = explode(' ', $decorators); - } + if (!is_array($decorators) && is_string($decorators)) { + $decorators = explode(' ', $decorators); } if ((!is_array($decorators)) || empty($decorators)) { return $value; diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php index e6304242a40..a79c85c0e7e 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php +++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php @@ -70,21 +70,18 @@ public function viewAction() */ public function emailAction() { - if ($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) { - if ($creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId)) { - $creditmemo->sendEmail(); - $historyItem = Mage::getResourceModel('sales/order_status_history_collection') - ->getUnnotifiedForInstance($creditmemo, Mage_Sales_Model_Order_Creditmemo::HISTORY_ENTITY_NAME); - if ($historyItem) { - $historyItem->setIsCustomerNotified(1); - $historyItem->save(); - } - - $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message was sent.')); - $this->_redirect('*/sales_order_creditmemo/view', [ - 'creditmemo_id' => $creditmemoId, - ]); + if (($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) && $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId)) { + $creditmemo->sendEmail(); + $historyItem = Mage::getResourceModel('sales/order_status_history_collection') + ->getUnnotifiedForInstance($creditmemo, Mage_Sales_Model_Order_Creditmemo::HISTORY_ENTITY_NAME); + if ($historyItem) { + $historyItem->setIsCustomerNotified(1); + $historyItem->save(); } + $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message was sent.')); + $this->_redirect('*/sales_order_creditmemo/view', [ + 'creditmemo_id' => $creditmemoId, + ]); } } diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php index bbebc7579bf..c4a3ac3caef 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php +++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php @@ -82,21 +82,19 @@ public function viewAction() */ public function emailAction() { - if ($invoiceId = $this->getRequest()->getParam('invoice_id')) { - if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) { - $invoice->sendEmail(); - $historyItem = Mage::getResourceModel('sales/order_status_history_collection') - ->getUnnotifiedForInstance($invoice, Mage_Sales_Model_Order_Invoice::HISTORY_ENTITY_NAME); - if ($historyItem) { - $historyItem->setIsCustomerNotified(1); - $historyItem->save(); - } - $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message has been sent.')); - $this->_redirect('*/sales_invoice/view', [ - 'order_id' => $invoice->getOrder()->getId(), - 'invoice_id' => $invoiceId, - ]); + if (($invoiceId = $this->getRequest()->getParam('invoice_id')) && $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) { + $invoice->sendEmail(); + $historyItem = Mage::getResourceModel('sales/order_status_history_collection') + ->getUnnotifiedForInstance($invoice, Mage_Sales_Model_Order_Invoice::HISTORY_ENTITY_NAME); + if ($historyItem) { + $historyItem->setIsCustomerNotified(1); + $historyItem->save(); } + $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message has been sent.')); + $this->_redirect('*/sales_invoice/view', [ + 'order_id' => $invoice->getOrder()->getId(), + 'invoice_id' => $invoiceId, + ]); } } diff --git a/app/code/core/Mage/Adminhtml/Model/Config.php b/app/code/core/Mage/Adminhtml/Model/Config.php index 244e7990662..5e8fc268242 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config.php +++ b/app/code/core/Mage/Adminhtml/Model/Config.php @@ -153,16 +153,12 @@ public function hasChildren($node, $websiteCode = null, $storeCode = null, $isFi { $showTab = false; if ($storeCode) { - if (isset($node->show_in_store)) { - if ((int) $node->show_in_store) { - $showTab = true; - } + if (isset($node->show_in_store) && (int) $node->show_in_store) { + $showTab = true; } } elseif ($websiteCode) { - if (isset($node->show_in_website)) { - if ((int) $node->show_in_website) { - $showTab = true; - } + if (isset($node->show_in_website) && (int) $node->show_in_website) { + $showTab = true; } } elseif (isset($node->show_in_default)) { if ((int) $node->show_in_default) { diff --git a/app/code/core/Mage/Adminhtml/Model/Observer.php b/app/code/core/Mage/Adminhtml/Model/Observer.php index 9cdc54d75ad..75005b92696 100644 --- a/app/code/core/Mage/Adminhtml/Model/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Observer.php @@ -16,10 +16,8 @@ class Mage_Adminhtml_Model_Observer { public function bindLocale($observer) { - if ($locale = $observer->getEvent()->getLocale()) { - if ($choosedLocale = Mage::getSingleton('adminhtml/session')->getLocale()) { - $locale->setLocaleCode($choosedLocale); - } + if (($locale = $observer->getEvent()->getLocale()) && $choosedLocale = Mage::getSingleton('adminhtml/session')->getLocale()) { + $locale->setLocaleCode($choosedLocale); } return $this; } diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index 2d5f239cf50..165d87b826c 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -1598,10 +1598,8 @@ protected function _validate() } } - if (!$this->getQuote()->isVirtual()) { - if (!$this->getQuote()->getShippingAddress()->getShippingMethod()) { - $this->_errors[] = Mage::helper('adminhtml')->__('Shipping method must be specified.'); - } + if (!$this->getQuote()->isVirtual() && !$this->getQuote()->getShippingAddress()->getShippingMethod()) { + $this->_errors[] = Mage::helper('adminhtml')->__('Shipping method must be specified.'); } if (!$this->getQuote()->getPayment()->getMethod()) { diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Filename.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Filename.php index 5276e0aa13c..b23a446c94f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Filename.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Filename.php @@ -35,13 +35,11 @@ protected function _beforeSave() $value = basename($value); // if dev/log setting, validate log file extension. - if ($configPath == self::DEV_LOG_FILE_PATH || $configPath == self::DEV_LOG_EXCEPTION_FILE_PATH) { - if (!Mage::helper('log')->isLogFileExtensionValid($value)) { - throw Mage::exception( - 'Mage_Core', - Mage::helper('adminhtml')->__('Invalid file extension used for log file. Allowed file extensions: log, txt, html, csv'), - ); - } + if (($configPath == self::DEV_LOG_FILE_PATH || $configPath == self::DEV_LOG_EXCEPTION_FILE_PATH) && !Mage::helper('log')->isLogFileExtensionValid($value)) { + throw Mage::exception( + 'Mage_Core', + Mage::helper('adminhtml')->__('Invalid file extension used for log file. Allowed file extensions: log, txt, html, csv'), + ); } $this->setValue($value); diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php index 16bae5dfd4e..508554a781a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php @@ -52,33 +52,29 @@ protected function _afterSave() $match = false; $scopeName = Mage::helper('adminhtml')->__('Default scope'); - if (preg_match('/(base|default)$/', $data->getPath(), $match)) { - if (!in_array($data->getValue(), $values)) { - $currencyName = Mage::app()->getLocale()->currency($data->getValue())->getName(); - if ($match[1] == 'base') { - $fieldName = Mage::helper('adminhtml')->__('Base currency'); - } else { - $fieldName = Mage::helper('adminhtml')->__('Display default currency'); - } - - switch ($data->getScope()) { - case 'default': - $scopeName = Mage::helper('adminhtml')->__('Default scope'); - break; - - case 'website': - $websiteName = Mage::getModel('core/website')->load($data->getScopeId())->getName(); - $scopeName = Mage::helper('adminhtml')->__('website(%s) scope', $websiteName); - break; + if (preg_match('/(base|default)$/', $data->getPath(), $match) && !in_array($data->getValue(), $values)) { + $currencyName = Mage::app()->getLocale()->currency($data->getValue())->getName(); + if ($match[1] == 'base') { + $fieldName = Mage::helper('adminhtml')->__('Base currency'); + } else { + $fieldName = Mage::helper('adminhtml')->__('Display default currency'); + } + switch ($data->getScope()) { + case 'default': + $scopeName = Mage::helper('adminhtml')->__('Default scope'); + break; - case 'store': - $storeName = Mage::getModel('core/store')->load($data->getScopeId())->getName(); - $scopeName = Mage::helper('adminhtml')->__('store(%s) scope', $storeName); - break; - } + case 'website': + $websiteName = Mage::getModel('core/website')->load($data->getScopeId())->getName(); + $scopeName = Mage::helper('adminhtml')->__('website(%s) scope', $websiteName); + break; - $exceptions[] = Mage::helper('adminhtml')->__('Currency "%s" is used as %s in %s.', $currencyName, $fieldName, $scopeName); + case 'store': + $storeName = Mage::getModel('core/store')->load($data->getScopeId())->getName(); + $scopeName = Mage::helper('adminhtml')->__('store(%s) scope', $storeName); + break; } + $exceptions[] = Mage::helper('adminhtml')->__('Currency "%s" is used as %s in %s.', $currencyName, $fieldName, $scopeName); } } if ($exceptions) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php index 3c33e2ddaf1..420b91a4523 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php @@ -428,12 +428,10 @@ public function treeAction() $storeId = (int) $this->getRequest()->getParam('store'); $categoryId = (int) $this->getRequest()->getParam('id'); - if ($storeId) { - if (!$categoryId) { - $store = Mage::app()->getStore($storeId); - $rootId = $store->getRootCategoryId(); - $this->getRequest()->setParam('id', $rootId); - } + if ($storeId && !$categoryId) { + $store = Mage::app()->getStore($storeId); + $rootId = $store->getRootCategoryId(); + $this->getRequest()->setParam('id', $rootId); } $category = $this->_initCategory(true); diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index 74e9db47148..e8bdd49be56 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -524,10 +524,8 @@ public function validateAction() $dateFields = []; $attributes = $product->getAttributes(); foreach ($attributes as $attrKey => $attribute) { - if ($attribute->getBackend()->getType() == 'datetime') { - if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { - $dateFields[] = $attrKey; - } + if ($attribute->getBackend()->getType() == 'datetime' && (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '')) { + $dateFields[] = $attrKey; } } $productData = $this->_filterDates($productData, $dateFields); @@ -973,12 +971,10 @@ public function massStatusAction() */ public function _validateMassStatus(array $productIds, $status) { - if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { - if (!Mage::getModel('catalog/product')->isProductsHasSku($productIds)) { - throw new Mage_Core_Exception( - $this->__('Some of the processed products have no SKU value defined. Please fill it prior to performing operations on these products.'), - ); - } + if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED && !Mage::getModel('catalog/product')->isProductsHasSku($productIds)) { + throw new Mage_Core_Exception( + $this->__('Some of the processed products have no SKU value defined. Please fill it prior to performing operations on these products.'), + ); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index fe00eb41d6f..fcf99af61a7 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -476,14 +476,12 @@ public function wishlistAction() { $this->_initCustomer(); $customer = Mage::registry('current_customer'); - if ($customer->getId()) { - if ($itemId = (int) $this->getRequest()->getParam('delete')) { - try { - Mage::getModel('wishlist/item')->load($itemId) - ->delete(); - } catch (Exception $e) { - Mage::logException($e); - } + if ($customer->getId() && $itemId = (int) $this->getRequest()->getParam('delete')) { + try { + Mage::getModel('wishlist/item')->load($itemId) + ->delete(); + } catch (Exception $e) { + Mage::logException($e); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php index d13088504c9..66f7bb398b8 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php @@ -147,13 +147,11 @@ public function saveAction() if (Mage::getStoreConfigFlag('admin/security/crate_admin_user_notification') && $isNew) { Mage::getModel('admin/user')->sendAdminNotification($model); } - if ($uRoles = $this->getRequest()->getParam('roles', false)) { - if (is_array($uRoles) && (count($uRoles) >= 1)) { - // with fix for previous multi-roles logic - $model->setRoleIds(array_slice($uRoles, 0, 1)) - ->setRoleUserId($model->getUserId()) - ->saveRelations(); - } + if (($uRoles = $this->getRequest()->getParam('roles', false)) && (is_array($uRoles) && count($uRoles) >= 1)) { + // with fix for previous multi-roles logic + $model->setRoleIds(array_slice($uRoles, 0, 1)) + ->setRoleUserId($model->getUserId()) + ->saveRelations(); } Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been saved.')); Mage::getSingleton('adminhtml/session')->setUserData(false); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index ff15fa05281..08447019947 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -93,10 +93,8 @@ public function statusAction() switch ($state) { case Mage_Core_Model_File_Storage_Flag::STATE_INACTIVE: $flagData = $flag->getFlagData(); - if (is_array($flagData)) { - if (isset($flagData['destination']) && !empty($flagData['destination'])) { - $result['destination'] = $flagData['destination']; - } + if (is_array($flagData) && (isset($flagData['destination']) && !empty($flagData['destination']))) { + $result['destination'] = $flagData['destination']; } $state = Mage_Core_Model_File_Storage_Flag::STATE_INACTIVE; @@ -148,10 +146,8 @@ public function statusAction() $result['html'] = $block->toHtml(); $flagData = $flag->getFlagData(); - if (is_array($flagData)) { - if (isset($flagData['has_errors']) && $flagData['has_errors']) { - $result['has_errors'] = true; - } + if (is_array($flagData) && (isset($flagData['has_errors']) && $flagData['has_errors'])) { + $result['has_errors'] = true; } break; diff --git a/app/code/core/Mage/Api/Model/Config.php b/app/code/core/Mage/Api/Model/Config.php index dbe7029fbd8..15ac6d74a23 100644 --- a/app/code/core/Mage/Api/Model/Config.php +++ b/app/code/core/Mage/Api/Model/Config.php @@ -36,10 +36,8 @@ public function __construct($sourceData = null) */ protected function _construct() { - if (Mage::app()->useCache('config_api')) { - if ($this->loadCache()) { - return $this; - } + if (Mage::app()->useCache('config_api') && $this->loadCache()) { + return $this; } $config = Mage::getConfig()->loadModulesConfiguration('api.xml'); diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php index 2f38fb3aa20..df6a058eb9f 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php @@ -79,12 +79,8 @@ public function isShipmentSeparately($item = null) } } - if ($options = $this->getOrderItem()->getProductOptions()) { - if (isset($options['shipment_type']) - && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY - ) { - return true; - } + if (($options = $this->getOrderItem()->getProductOptions()) && (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY)) { + return true; } return false; } @@ -122,12 +118,8 @@ public function isChildCalculated($item = null) } } - if ($options = $this->getOrderItem()->getProductOptions()) { - if (isset($options['product_calculations']) - && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD - ) { - return true; - } + if (($options = $this->getOrderItem()->getProductOptions()) && (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD)) { + return true; } return false; } @@ -188,15 +180,11 @@ public function getOrderItem() public function getValueHtml($item) { $result = $this->escapeHtml($item->getName()); - if (!$this->isShipmentSeparately($item)) { - if ($attributes = $this->getSelectionAttributes($item)) { - $result = sprintf('%d', $attributes['qty']) . ' x ' . $result; - } + if (!$this->isShipmentSeparately($item) && $attributes = $this->getSelectionAttributes($item)) { + $result = sprintf('%d', $attributes['qty']) . ' x ' . $result; } - if (!$this->isChildCalculated($item)) { - if ($attributes = $this->getSelectionAttributes($item)) { - $result .= ' ' . $this->getOrderItem()->getOrder()->formatPrice($attributes['price']); - } + if (!$this->isChildCalculated($item) && $attributes = $this->getSelectionAttributes($item)) { + $result .= ' ' . $this->getOrderItem()->getOrder()->formatPrice($attributes['price']); } return $result; } diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index f27e9b189df..0ad31853620 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -44,12 +44,8 @@ public function isShipmentSeparately($item = null) } } - if ($options = $this->getOrderItem()->getProductOptions()) { - if (isset($options['shipment_type']) - && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY - ) { - return true; - } + if (($options = $this->getOrderItem()->getProductOptions()) && (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY)) { + return true; } return false; } @@ -84,12 +80,8 @@ public function isChildCalculated($item = null) } } - if ($options = $this->getItem()->getProductOptions()) { - if (isset($options['product_calculations']) - && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD - ) { - return true; - } + if (($options = $this->getItem()->getProductOptions()) && (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD)) { + return true; } return false; } @@ -138,15 +130,11 @@ public function getOrderOptions() public function getValueHtml($item) { $result = $this->escapeHtml($item->getName()); - if (!$this->isShipmentSeparately($item)) { - if ($attributes = $this->getSelectionAttributes($item)) { - $result = sprintf('%d', $attributes['qty']) . ' x ' . $result; - } + if (!$this->isShipmentSeparately($item) && $attributes = $this->getSelectionAttributes($item)) { + $result = sprintf('%d', $attributes['qty']) . ' x ' . $result; } - if (!$this->isChildCalculated($item)) { - if ($attributes = $this->getSelectionAttributes($item)) { - $result .= ' ' . $this->getItem()->getOrder()->formatPrice($attributes['price']); - } + if (!$this->isChildCalculated($item) && $attributes = $this->getSelectionAttributes($item)) { + $result .= ' ' . $this->getItem()->getOrder()->formatPrice($attributes['price']); } return $result; } diff --git a/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php index aa8a97443f1..71aba2fcfd0 100644 --- a/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php @@ -47,12 +47,8 @@ public function isShipmentSeparately($item = null) } } - if ($options = $this->getOrderItem()->getProductOptions()) { - if (isset($options['shipment_type']) - && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY - ) { - return true; - } + if (($options = $this->getOrderItem()->getProductOptions()) && (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY)) { + return true; } return false; } @@ -90,12 +86,8 @@ public function isChildCalculated($item = null) } } - if ($options = $this->getOrderItem()->getProductOptions()) { - if (isset($options['product_calculations']) - && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD - ) { - return true; - } + if (($options = $this->getOrderItem()->getProductOptions()) && (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD)) { + return true; } return false; } diff --git a/app/code/core/Mage/Bundle/Model/Product/Price.php b/app/code/core/Mage/Bundle/Model/Product/Price.php index f9d36d6723b..1e6d238465b 100644 --- a/app/code/core/Mage/Bundle/Model/Product/Price.php +++ b/app/code/core/Mage/Bundle/Model/Product/Price.php @@ -951,11 +951,9 @@ public static function calculateSpecialPrice( $specialPriceTo, $store = null ) { - if (!is_null($specialPrice) && $specialPrice != false) { - if (Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { - $specialPrice = Mage::app()->getStore()->roundPrice($finalPrice * $specialPrice / 100); - $finalPrice = min($finalPrice, $specialPrice); - } + if (!is_null($specialPrice) && $specialPrice != false && Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { + $specialPrice = Mage::app()->getStore()->roundPrice($finalPrice * $specialPrice / 100); + $finalPrice = min($finalPrice, $specialPrice); } return $finalPrice; diff --git a/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php b/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php index 300bfe4475b..5c85be0cea3 100644 --- a/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php +++ b/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php @@ -808,11 +808,9 @@ public function _calculateSpecialPrice($finalPrice, array $priceData, Mage_Core_ $store = $website->getDefaultStore(); $specialPrice = $priceData['special_price']; - if (!is_null($specialPrice) && $specialPrice != false) { - if (Mage::app()->getLocale()->isStoreDateInInterval($store, $priceData['special_from_date'], $priceData['special_to_date'])) { - $specialPrice = ($finalPrice * $specialPrice) / 100; - $finalPrice = min($finalPrice, $specialPrice); - } + if (!is_null($specialPrice) && $specialPrice != false && Mage::app()->getLocale()->isStoreDateInInterval($store, $priceData['special_from_date'], $priceData['special_to_date'])) { + $specialPrice = ($finalPrice * $specialPrice) / 100; + $finalPrice = min($finalPrice, $specialPrice); } return $finalPrice; diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php index a008f0259cf..b23c5d08e8b 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php @@ -87,12 +87,8 @@ public function isShipmentSeparately($item = null) } $options = $this->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['shipment_type']) - && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY - ) { - return true; - } + if ($options && (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY)) { + return true; } return false; } @@ -137,12 +133,8 @@ public function isChildCalculated($item = null) } $options = $this->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['product_calculations']) - && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD - ) { - return true; - } + if ($options && (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD)) { + return true; } return false; } @@ -156,10 +148,8 @@ public function isChildCalculated($item = null) public function getBundleOptions($item = null) { $options = $this->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['bundle_options'])) { - return $options['bundle_options']; - } + if ($options && isset($options['bundle_options'])) { + return $options['bundle_options']; } return []; } diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index ca06fe6c10c..e57ad45154b 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -50,22 +50,18 @@ public function draw() } // draw selection attributes - if ($orderItem->getOrderItem()->getParentItem()) { - if ($_prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 38, true, true), - 'feed' => $x, - ]; - - $drawItems[$optionId] = [ - 'lines' => [$line], - 'height' => 15, - ]; - - $line = []; - $_prevOptionId = $attributes['option_id']; - } + if ($orderItem->getOrderItem()->getParentItem() && $_prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 38, true, true), + 'feed' => $x, + ]; + $drawItems[$optionId] = [ + 'lines' => [$line], + 'height' => 15, + ]; + $line = []; + $_prevOptionId = $attributes['option_id']; } // draw product titles @@ -161,37 +157,35 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true), - 'font' => 'italic', - 'feed' => $leftBound, - ]; + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true), + 'font' => 'italic', + 'feed' => $leftBound, + ]; - if ($option['value']) { - $text = []; - $printValue = $option['print_value'] ?? strip_tags($option['value']); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach (Mage::helper('core/string')->str_split($value, 30, true, true) as $str) { - $text[] = $str; - } + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? strip_tags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach (Mage::helper('core/string')->str_split($value, 30, true, true) as $str) { + $text[] = $str; } - - $lines[][] = [ - 'text' => $text, - 'feed' => $leftBound + 5, - ]; } - $drawItems[] = [ - 'lines' => $lines, - 'height' => 15, + $lines[][] = [ + 'text' => $text, + 'feed' => $leftBound + 5, ]; } + + $drawItems[] = [ + 'lines' => $lines, + 'height' => 15, + ]; } } diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index c7802885039..04f1ff5d6c8 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -57,23 +57,18 @@ public function draw() ]; } - if ($orderItem->getOrderItem()->getParentItem()) { - if ($_prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => $stringHelper->str_split($attributes['option_label'], 45, true, true), - 'feed' => 35, - ]; - - $drawItems[$optionId] = [ - 'lines' => [$line], - 'height' => 15, - ]; - - $line = []; - - $_prevOptionId = $attributes['option_id']; - } + if ($orderItem->getOrderItem()->getParentItem() && $_prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => $stringHelper->str_split($attributes['option_label'], 45, true, true), + 'feed' => 35, + ]; + $drawItems[$optionId] = [ + 'lines' => [$line], + 'height' => 15, + ]; + $line = []; + $_prevOptionId = $attributes['option_id']; } /* in case Product name is longer than 80 chars - it is written in a few lines */ @@ -146,37 +141,35 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => $stringHelper->str_split(strip_tags($option['label']), 40, true, true), - 'font' => 'italic', - 'feed' => 35, - ]; + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => $stringHelper->str_split(strip_tags($option['label']), 40, true, true), + 'font' => 'italic', + 'feed' => 35, + ]; - if ($option['value']) { - $text = []; - $printValue = $option['print_value'] ?? strip_tags($option['value']); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach ($stringHelper->str_split($value, 30, true, true) as $str) { - $text[] = $str; - } + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? strip_tags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach ($stringHelper->str_split($value, 30, true, true) as $str) { + $text[] = $str; } - - $lines[][] = [ - 'text' => $text, - 'feed' => 40, - ]; } - $drawItems[] = [ - 'lines' => $lines, - 'height' => 15, + $lines[][] = [ + 'text' => $text, + 'feed' => 40, ]; } + + $drawItems[] = [ + 'lines' => $lines, + 'height' => 15, + ]; } } diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index ecb35707005..9a54119c770 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -49,23 +49,18 @@ public function draw() ]; } - if ($orderItem->getParentItem()) { - if ($_prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 60, true, true), - 'feed' => 60, - ]; - - $drawItems[$optionId] = [ - 'lines' => [$line], - 'height' => 15, - ]; - - $line = []; - - $_prevOptionId = $attributes['option_id']; - } + if ($orderItem->getParentItem() && $_prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 60, true, true), + 'feed' => 60, + ]; + $drawItems[$optionId] = [ + 'lines' => [$line], + 'height' => 15, + ]; + $line = []; + $_prevOptionId = $attributes['option_id']; } if (($this->isShipmentSeparately() && $orderItem->getParentItem()) @@ -119,37 +114,35 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true), - 'font' => 'italic', - 'feed' => 60, - ]; + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true), + 'font' => 'italic', + 'feed' => 60, + ]; - if ($option['value']) { - $text = []; - $printValue = $option['print_value'] ?? strip_tags($option['value']); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $str) { - $text[] = $str; - } + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? strip_tags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $str) { + $text[] = $str; } - - $lines[][] = [ - 'text' => $text, - 'feed' => 65, - ]; } - $drawItems[] = [ - 'lines' => $lines, - 'height' => 15, + $lines[][] = [ + 'text' => $text, + 'feed' => 65, ]; } + + $drawItems[] = [ + 'lines' => $lines, + 'height' => 15, + ]; } } diff --git a/app/code/core/Mage/Captcha/Model/Observer.php b/app/code/core/Mage/Captcha/Model/Observer.php index 345dd3bea76..a3f54e06ea6 100644 --- a/app/code/core/Mage/Captcha/Model/Observer.php +++ b/app/code/core/Mage/Captcha/Model/Observer.php @@ -94,14 +94,12 @@ public function checkGuestCheckout(Varien_Event_Observer $observer) $formId = 'guest_checkout'; $captchaModel = Mage::helper('captcha')->getCaptcha($formId); $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod(); - if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST) { - if ($captchaModel->isRequired()) { - $controller = $observer->getControllerAction(); - if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - $result = ['error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.')]; - $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); - } + if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST && $captchaModel->isRequired()) { + $controller = $observer->getControllerAction(); + if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { + $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); + $result = ['error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.')]; + $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } return $this; @@ -118,14 +116,12 @@ public function checkRegisterCheckout($observer) $formId = 'register_during_checkout'; $captchaModel = Mage::helper('captcha')->getCaptcha($formId); $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod(); - if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) { - if ($captchaModel->isRequired()) { - $controller = $observer->getControllerAction(); - if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - $result = ['error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.')]; - $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); - } + if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER && $captchaModel->isRequired()) { + $controller = $observer->getControllerAction(); + if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { + $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); + $result = ['error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.')]; + $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } return $this; @@ -143,11 +139,9 @@ public function checkUserLoginBackend($observer) $captchaModel = Mage::helper('captcha')->getCaptcha($formId); $loginParams = Mage::app()->getRequest()->getPost('login', []); $login = $loginParams['username'] ?? null; - if ($captchaModel->isRequired($login)) { - if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) { - $captchaModel->logAttempt($login); - Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); - } + if ($captchaModel->isRequired($login) && !$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) { + $captchaModel->logAttempt($login); + Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); } $captchaModel->logAttempt($login); return $this; @@ -177,14 +171,12 @@ public function checkUserForgotPasswordBackend($observer) $email = (string) $observer->getControllerAction()->getRequest()->getParam('email'); $params = $observer->getControllerAction()->getRequest()->getParams(); - if (!empty($email) && !empty($params)) { - if ($captchaModel->isRequired()) { - if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - $this->_getBackendSession()->setEmail((string) $controller->getRequest()->getPost('email')); - $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - $this->_getBackendSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); - $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword')); - } + if (!empty($email) && !empty($params) && $captchaModel->isRequired()) { + if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { + $this->_getBackendSession()->setEmail((string) $controller->getRequest()->getPost('email')); + $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); + $this->_getBackendSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword')); } } return $this; @@ -234,10 +226,8 @@ public function deleteExpiredImages() $expire = time() - Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()) * 60; $imageDirectory = Mage::helper('captcha')->getImgDir($website); foreach (new DirectoryIterator($imageDirectory) as $file) { - if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png') { - if ($file->getMTime() < $expire) { - unlink($file->getPathname()); - } + if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png' && $file->getMTime() < $expire) { + unlink($file->getPathname()); } } } diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index b4f8ca69c3b..d6a08484391 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -176,10 +176,8 @@ protected function _getPriceBlock($productTypeId) { if (!isset($this->_priceBlock[$productTypeId])) { $block = $this->_block; - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['block'] != '') { - $block = $this->_priceBlockTypes[$productTypeId]['block']; - } + if (isset($this->_priceBlockTypes[$productTypeId]) && $this->_priceBlockTypes[$productTypeId]['block'] != '') { + $block = $this->_priceBlockTypes[$productTypeId]['block']; } $this->_priceBlock[$productTypeId] = $this->getLayout()->createBlock($block); } @@ -194,10 +192,8 @@ protected function _getPriceBlock($productTypeId) */ protected function _getPriceBlockTemplate($productTypeId) { - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { - return $this->_priceBlockTypes[$productTypeId]['template']; - } + if (isset($this->_priceBlockTypes[$productTypeId]) && $this->_priceBlockTypes[$productTypeId]['template'] != '') { + return $this->_priceBlockTypes[$productTypeId]['template']; } return $this->_priceBlockDefaultTemplate; } diff --git a/app/code/core/Mage/Catalog/Block/Product/List.php b/app/code/core/Mage/Catalog/Block/Product/List.php index 68e237ac236..a86ce24b52f 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List.php +++ b/app/code/core/Mage/Catalog/Block/Product/List.php @@ -165,10 +165,8 @@ protected function _beforeToHtml() */ public function getToolbarBlock() { - if ($blockName = $this->getToolbarBlockName()) { - if ($block = $this->getLayout()->getBlock($blockName)) { - return $block; - } + if (($blockName = $this->getToolbarBlockName()) && $block = $this->getLayout()->getBlock($blockName)) { + return $block; } return $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime()); } @@ -244,14 +242,12 @@ public function prepareSortableFieldsByCategory($category) $this->setAvailableOrders($category->getAvailableSortByOptions()); } $availableOrders = $this->getAvailableOrders(); - if (!$this->getSortBy()) { - if ($categorySortBy = $category->getDefaultSortBy()) { - if (!$availableOrders) { - $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray(); - } - if (isset($availableOrders[$categorySortBy])) { - $this->setSortBy($categorySortBy); - } + if (!$this->getSortBy() && $categorySortBy = $category->getDefaultSortBy()) { + if (!$availableOrders) { + $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray(); + } + if (isset($availableOrders[$categorySortBy])) { + $this->setSortBy($categorySortBy); } } diff --git a/app/code/core/Mage/Catalog/Helper/Output.php b/app/code/core/Mage/Catalog/Helper/Output.php index 6b135ccbe2a..8877c61caf0 100644 --- a/app/code/core/Mage/Catalog/Helper/Output.php +++ b/app/code/core/Mage/Catalog/Helper/Output.php @@ -119,10 +119,8 @@ public function productAttribute($product, $attributeHtml, $attributeName) $attributeHtml = nl2br($attributeHtml); } } - if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) { - if (Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) { - $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml); - } + if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled() && Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) { + $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml); } return $this->process('productAttribute', $attributeHtml, [ @@ -149,10 +147,8 @@ public function categoryAttribute($category, $attributeHtml, $attributeName) ) { $attributeHtml = $this->escapeHtml($attributeHtml); } - if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) { - if (Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) { - $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml); - } + if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled() && Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) { + $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml); } return $this->process('categoryAttribute', $attributeHtml, [ 'category' => $category, diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index 22099e9a83f..95186ddadd0 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -442,10 +442,8 @@ public function getProduct($productId, $store, $identifierType = null) $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore($store)->getId()); $expectedIdType = false; - if ($identifierType === null) { - if (is_string($productId) && !preg_match('/^[+-]?[1-9][0-9]*$|^0$/', $productId)) { - $expectedIdType = 'sku'; - } + if ($identifierType === null && (is_string($productId) && !preg_match('/^[+-]?[1-9][0-9]*$|^0$/', $productId))) { + $expectedIdType = 'sku'; } if ($identifierType == 'sku' || $expectedIdType == 'sku') { diff --git a/app/code/core/Mage/Catalog/Helper/Product/View.php b/app/code/core/Mage/Catalog/Helper/Product/View.php index 1bacd296bc8..67eb971604a 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/View.php +++ b/app/code/core/Mage/Catalog/Helper/Product/View.php @@ -50,11 +50,9 @@ public function initProductLayout($product, $controller) // Apply custom layout update once layout is loaded $layoutUpdates = $settings->getLayoutUpdates(); - if ($layoutUpdates) { - if (is_array($layoutUpdates)) { - foreach ($layoutUpdates as $layoutUpdate) { - $update->addUpdate($layoutUpdate); - } + if ($layoutUpdates && is_array($layoutUpdates)) { + foreach ($layoutUpdates as $layoutUpdate) { + $update->addUpdate($layoutUpdate); } } diff --git a/app/code/core/Mage/Catalog/Model/Api/Resource.php b/app/code/core/Mage/Catalog/Model/Api/Resource.php index 5ddda5b6db0..be8e06dcc12 100644 --- a/app/code/core/Mage/Catalog/Model/Api/Resource.php +++ b/app/code/core/Mage/Catalog/Model/Api/Resource.php @@ -49,10 +49,8 @@ class Mage_Catalog_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract */ protected function _isAllowedAttribute($attribute, $attributes = null) { - if (Mage::getSingleton('api/server')->getApiName() == 'rest') { - if (!$this->_checkAttributeAcl($attribute)) { - return false; - } + if (Mage::getSingleton('api/server')->getApiName() == 'rest' && !$this->_checkAttributeAcl($attribute)) { + return false; } if (is_array($attributes) diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php index acadf6c3cda..934519931ce 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php @@ -273,13 +273,9 @@ protected function _getProduct() } } // Check display settings for customers & guests - if ($this->getApiUser()->getType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) { - // check if product assigned to any website and can be shown - if ((!Mage::app()->isSingleStoreMode() && !count($product->getWebsiteIds())) - || !$productHelper->canShow($product) - ) { - $this->_critical(self::RESOURCE_NOT_FOUND); - } + // check if product assigned to any website and can be shown + if ($this->getApiUser()->getType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE && (!Mage::app()->isSingleStoreMode() && !count($product->getWebsiteIds()) || !$productHelper->canShow($product))) { + $this->_critical(self::RESOURCE_NOT_FOUND); } $this->_product = $product; } @@ -338,12 +334,10 @@ protected function _getPrice( $includingPercent = null; $taxClassId = $product->getTaxClassId(); - if (is_null($percent)) { - if ($taxClassId) { - $request = Mage::getSingleton('tax/calculation') - ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store); - $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId)); - } + if (is_null($percent) && $taxClassId) { + $request = Mage::getSingleton('tax/calculation') + ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store); + $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId)); } if ($taxClassId && $priceIncludesTax) { $taxHelper = Mage::helper('tax'); @@ -356,10 +350,8 @@ protected function _getPrice( } } - if ($percent === false || is_null($percent)) { - if ($priceIncludesTax && !$includingPercent) { - return $price; - } + if (($percent === false || is_null($percent)) && ($priceIncludesTax && !$includingPercent)) { + return $price; } $product->setTaxPercent($percent); diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php index dced7002406..9a9983de413 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php @@ -300,13 +300,11 @@ protected function _prepareDataForSave($product, $productData) $product->setData($attribute->getAttributeCode(), false); } - if ($this->_isAllowedAttribute($attribute)) { - if (array_key_exists($attribute->getAttributeCode(), $productData)) { - $product->setData( - $attribute->getAttributeCode(), - $productData[$attribute->getAttributeCode()], - ); - } + if ($this->_isAllowedAttribute($attribute) && array_key_exists($attribute->getAttributeCode(), $productData)) { + $product->setData( + $attribute->getAttributeCode(), + $productData[$attribute->getAttributeCode()], + ); } } } diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product/Validator/Product.php b/app/code/core/Mage/Catalog/Model/Api2/Product/Validator/Product.php index 80316912e1a..150b856977f 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product/Validator/Product.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product/Validator/Product.php @@ -199,10 +199,8 @@ protected function _validateAttributes($data, $productEntity) } } - if ($applicable && $attribute->getIsRequired() && $attribute->getIsVisible()) { - if (!in_array($attributeCode, $positiveNumberAttributes) || $value !== 0) { - $requiredAttributes[] = $attribute->getAttributeCode(); - } + if ($applicable && $attribute->getIsRequired() && $attribute->getIsVisible() && (!in_array($attributeCode, $positiveNumberAttributes) || $value !== 0)) { + $requiredAttributes[] = $attribute->getAttributeCode(); } } @@ -282,10 +280,8 @@ protected function _validateSku($data) */ protected function _validateGiftOptions($data) { - if (isset($data['gift_wrapping_price'])) { - if (!(is_numeric($data['gift_wrapping_price']) && $data['gift_wrapping_price'] >= 0)) { - $this->_addError('Please enter a number 0 or greater in the "gift_wrapping_price" field.'); - } + if (isset($data['gift_wrapping_price']) && !(is_numeric($data['gift_wrapping_price']) && $data['gift_wrapping_price'] >= 0)) { + $this->_addError('Please enter a number 0 or greater in the "gift_wrapping_price" field.'); } } @@ -534,15 +530,13 @@ protected function _validateNumeric($data, $fieldSet, $field, $required = false, protected function _validateSource($data, $fieldSet, $field, $sourceModelName, $skipIfConfigValueUsed = false) { // in case when 'Use Config Settings' is selected no validation needed - if (!($skipIfConfigValueUsed && $this->_isConfigValueUsed($data, $field))) { - if (isset($data[$field])) { - $sourceModel = Mage::getSingleton($sourceModelName); - if ($sourceModel) { - $allowedValues = $this->_getAttributeAllowedValues($sourceModel->toOptionArray()); - $useStrictMode = !is_numeric($data[$field]); - if (!in_array($data[$field], $allowedValues, $useStrictMode)) { - $this->_addError(sprintf('Invalid "%s" value in the "%s" set.', $field, $fieldSet)); - } + if (!$skipIfConfigValueUsed && $this->_isConfigValueUsed($data, $field) && isset($data[$field])) { + $sourceModel = Mage::getSingleton($sourceModelName); + if ($sourceModel) { + $allowedValues = $this->_getAttributeAllowedValues($sourceModel->toOptionArray()); + $useStrictMode = !is_numeric($data[$field]); + if (!in_array($data[$field], $allowedValues, $useStrictMode)) { + $this->_addError(sprintf('Invalid "%s" value in the "%s" set.', $field, $fieldSet)); } } } @@ -559,15 +553,13 @@ protected function _validateSource($data, $fieldSet, $field, $sourceModelName, $ protected function _validateBoolean($data, $fieldSet, $field, $skipIfConfigValueUsed = false) { // in case when 'Use Config Settings' is selected no validation needed - if (!($skipIfConfigValueUsed && $this->_isConfigValueUsed($data, $field))) { - if (isset($data[$field])) { - $allowedValues = $this->_getAttributeAllowedValues( - Mage::getSingleton('eav/entity_attribute_source_boolean')->getAllOptions(), - ); - $useStrictMode = !is_numeric($data[$field]); - if (!in_array($data[$field], $allowedValues, $useStrictMode)) { - $this->_addError(sprintf('Invalid "%s" value in the "%s" set.', $field, $fieldSet)); - } + if (!$skipIfConfigValueUsed && $this->_isConfigValueUsed($data, $field) && isset($data[$field])) { + $allowedValues = $this->_getAttributeAllowedValues( + Mage::getSingleton('eav/entity_attribute_source_boolean')->getAllOptions(), + ); + $useStrictMode = !is_numeric($data[$field]); + if (!in_array($data[$field], $allowedValues, $useStrictMode)) { + $this->_addError(sprintf('Invalid "%s" value in the "%s" set.', $field, $fieldSet)); } } } diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php index b80cfadac59..71d749e3c99 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php @@ -43,11 +43,9 @@ public function validate($object) } } - if ($this->getAttribute()->getIsUnique()) { - if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { - $label = $this->getAttribute()->getFrontend()->getLabel(); - Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label)); - } + if ($this->getAttribute()->getIsUnique() && !$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { + $label = $this->getAttribute()->getFrontend()->getLabel(); + Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label)); } if ($attributeCode == 'default_sort_by') { diff --git a/app/code/core/Mage/Catalog/Model/Design.php b/app/code/core/Mage/Catalog/Model/Design.php index 73bfac29048..493b240bd57 100644 --- a/app/code/core/Mage/Catalog/Model/Design.php +++ b/app/code/core/Mage/Catalog/Model/Design.php @@ -195,14 +195,8 @@ protected function _inheritDesign($object, $calledFrom = 0) $category = $object->getParentCategory(); $useParentSettings = $object->getCustomUseParentSettings(); - if ($useParentSettings) { - if ($category && - $category->getId() && - $category->getLevel() > 1 && - $category->getId() != Mage_Catalog_Model_Category::TREE_ROOT_ID - ) { - return $this->_inheritDesign($category, $calledFrom); - } + if ($useParentSettings && ($category && $category->getId() && $category->getLevel() > 1 && $category->getId() != Mage_Catalog_Model_Category::TREE_ROOT_ID)) { + return $this->_inheritDesign($category, $calledFrom); } if ($calledFrom == self::APPLY_FOR_PRODUCT) { diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price/Algorithm.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price/Algorithm.php index 559c56b2b6d..c1bbb7d2f07 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price/Algorithm.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price/Algorithm.php @@ -431,10 +431,8 @@ protected function _findRoundPrice($lowerPrice, $upperPrice, $returnEmpty = true if (!is_null($roundingFactor)) { // Can't separate if prices are equal - if ($lowerPrice >= $upperPrice) { - if ($lowerPrice > $upperPrice || $returnEmpty) { - return false; - } + if ($lowerPrice >= $upperPrice && ($lowerPrice > $upperPrice || $returnEmpty)) { + return false; } // round is used for such examples: (1194.32 / 0.02) or (5 / 100000) $lowerDivision = ceil(round($lowerPrice / $roundingFactor, self::TEN_POWER_ROUNDING_FACTOR + 3)); diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php index 42e7536eb0e..957b751f73e 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php @@ -70,17 +70,13 @@ public function validate($object) { if ($this->getAttribute()->getIsRequired()) { $value = $object->getData($this->getAttribute()->getAttributeCode()); - if ($this->getAttribute()->isValueEmpty($value)) { - if (!(is_array($value) && count($value) > 0)) { - return false; - } + if ($this->getAttribute()->isValueEmpty($value) && !(is_array($value) && count($value) > 0)) { + return false; } } - if ($this->getAttribute()->getIsUnique()) { - if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { - $label = $this->getAttribute()->getFrontend()->getLabel(); - Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label)); - } + if ($this->getAttribute()->getIsUnique() && !$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { + $label = $this->getAttribute()->getFrontend()->getLabel(); + Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label)); } return true; diff --git a/app/code/core/Mage/Catalog/Model/Product/Image.php b/app/code/core/Mage/Catalog/Model/Product/Image.php index ac75917c424..5390acbb424 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Image.php +++ b/app/code/core/Mage/Catalog/Model/Product/Image.php @@ -331,10 +331,8 @@ public function setBaseFile($file) if ($file == '/no_selection') { $file = null; } - if ($file) { - if ((!$this->_fileExists($baseDir . $file))) { - $file = null; - } + if ($file && !$this->_fileExists($baseDir . $file)) { + $file = null; } if (!$file) { // check if placeholder defined in config diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php b/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php index 1dc0bff0c72..9569a69c791 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php @@ -28,16 +28,14 @@ public function copyQuoteFilesToOrderFiles($observer) if (is_array($quoteItem->getOptions())) { foreach ($quoteItem->getOptions() as $itemOption) { $code = explode('_', $itemOption->getCode()); - if (isset($code[1]) && is_numeric($code[1]) && ($option = $quoteItem->getProduct()->getOptionById($code[1]))) { - if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE) { - /** @var Mage_Catalog_Model_Product_Option $option */ - try { - $group = $option->groupFactory($option->getType()) - ->setQuoteItemOption($itemOption) - ->copyQuoteToOrder(); - } catch (Exception $e) { - continue; - } + if (isset($code[1]) && is_numeric($code[1]) && ($option = $quoteItem->getProduct()->getOptionById($code[1])) && $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE) { + /** @var Mage_Catalog_Model_Product_Option $option */ + try { + $group = $option->groupFactory($option->getType()) + ->setQuoteItemOption($itemOption) + ->copyQuoteToOrder(); + } catch (Exception $e) { + continue; } } } diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php index 4cc2864166f..bcc76ded1b5 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php @@ -312,10 +312,8 @@ protected function _validateFile($optionValue) $fileFullPath = null; foreach ($checkPaths as $path) { - if (!is_file($path)) { - if (!Mage::helper('core/file_storage_database')->saveFileToFilesystem($fileFullPath)) { - continue; - } + if (!is_file($path) && !Mage::helper('core/file_storage_database')->saveFileToFilesystem($fileFullPath)) { + continue; } $fileFullPath = $path; break; diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php index ad56bdf610c..a4baa51c0c9 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php @@ -717,10 +717,8 @@ public function getOrderOptions($product = null) */ public function isVirtual($product = null) { - if ($productOption = $this->getProduct($product)->getCustomOption('simple_product')) { - if ($optionProduct = $productOption->getProduct()) { - return $optionProduct->isVirtual(); - } + if (($productOption = $this->getProduct($product)->getCustomOption('simple_product')) && $optionProduct = $productOption->getProduct()) { + return $optionProduct->isVirtual(); } return parent::isVirtual($product); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php index 9bff109aeae..33fe72fd174 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php @@ -70,15 +70,13 @@ public function getTotalConfigurableItemsPrice($product, $finalPrice) $selectedAttributes[$attributeId] ?? null, ); $product->setParentId(true); - if ($value) { - if ($value['pricing_value'] != 0) { - $product->setConfigurablePrice($this->_calcSelectionPrice($value, $finalPrice)); - Mage::dispatchEvent( - 'catalog_product_type_configurable_price', - ['product' => $product], - ); - $price += $product->getConfigurablePrice(); - } + if ($value && $value['pricing_value'] != 0) { + $product->setConfigurablePrice($this->_calcSelectionPrice($value, $finalPrice)); + Mage::dispatchEvent( + 'catalog_product_type_configurable_price', + ['product' => $product], + ); + $price += $product->getConfigurablePrice(); } } return $price; diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php index f7672429162..a792754c58c 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php @@ -415,10 +415,8 @@ public static function calculateSpecialPrice( $specialPriceTo, $store = null ) { - if (!is_null($specialPrice) && $specialPrice != false) { - if (Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { - $finalPrice = min($finalPrice, $specialPrice); - } + if (!is_null($specialPrice) && $specialPrice != false && Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { + $finalPrice = min($finalPrice, $specialPrice); } return $finalPrice; } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php index 3b24fe7ad6c..f197cea30ed 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php @@ -103,15 +103,11 @@ protected function _beforeSave() Mage::throwException(Mage::helper('catalog')->__('Scope must not be changed, because the attribute is used in configurable products.')); } } - if ($this->getFrontendInput() == 'price') { - if (!$this->getBackendModel()) { - $this->setBackendModel('catalog/product_attribute_backend_price'); - } + if ($this->getFrontendInput() == 'price' && !$this->getBackendModel()) { + $this->setBackendModel('catalog/product_attribute_backend_price'); } - if ($this->getFrontendInput() == 'textarea') { - if ($this->getIsWysiwygEnabled()) { - $this->setIsHtmlAllowedOnFront(1); - } + if ($this->getFrontendInput() == 'textarea' && $this->getIsWysiwygEnabled()) { + $this->setIsHtmlAllowedOnFront(1); } return parent::_beforeSave(); } @@ -246,10 +242,8 @@ public function getApplyTo() public function getSourceModel() { $model = $this->getData('source_model'); - if (empty($model)) { - if ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select') { - return $this->_getDefaultSourceModel(); - } + if (empty($model) && ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select')) { + return $this->_getDefaultSourceModel(); } return $model; } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php index 1329f3fa491..7c0f3602ef9 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php @@ -241,22 +241,20 @@ protected function _loadPrices() foreach ($productType->getUsedProducts([$productAttributeCode], $this->getProduct()) as $associatedProduct) { $optionValue = $associatedProduct->getData($productAttributeCode); - if (array_key_exists($optionValue, $optionsByValue)) { - // If option available in associated product - if (!isset($values[$item->getId() . ':' . $optionValue])) { - // If option not added, we will add it. - $values[$item->getId() . ':' . $optionValue] = [ - 'product_super_attribute_id' => $item->getId(), - 'value_index' => $optionValue, - 'label' => $optionsByValue[$optionValue]['label'], - 'default_label' => $optionsByValue[$optionValue]['label'], - 'store_label' => $optionsByValue[$optionValue]['label'], - 'is_percent' => 0, - 'pricing_value' => null, - 'use_default_value' => true, - 'order' => $optionsByValue[$optionValue]['order'], - ]; - } + // If option available in associated product + if (array_key_exists($optionValue, $optionsByValue) && !isset($values[$item->getId() . ':' . $optionValue])) { + // If option not added, we will add it. + $values[$item->getId() . ':' . $optionValue] = [ + 'product_super_attribute_id' => $item->getId(), + 'value_index' => $optionValue, + 'label' => $optionsByValue[$optionValue]['label'], + 'default_label' => $optionsByValue[$optionValue]['label'], + 'store_label' => $optionsByValue[$optionValue]['label'], + 'is_percent' => 0, + 'pricing_value' => null, + 'use_default_value' => true, + 'order' => $optionsByValue[$optionValue]['order'], + ]; } } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Url.php b/app/code/core/Mage/Catalog/Model/Resource/Url.php index 2cdd09a3f86..e40fc786e21 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Url.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Url.php @@ -285,19 +285,17 @@ public function saveRewrite($rewriteData, $rewrite) Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite')); } - if ($rewrite && $rewrite->getId()) { - if ($rewriteData['request_path'] != $rewrite->getRequestPath()) { - // Update existing rewrites history and avoid chain redirects - $where = ['target_path = ?' => $rewrite->getRequestPath()]; - if ($rewrite->getStoreId()) { - $where['store_id = ?'] = (int) $rewrite->getStoreId(); - } - $adapter->update( - $this->getMainTable(), - ['target_path' => $rewriteData['request_path']], - $where, - ); + if ($rewrite && $rewrite->getId() && $rewriteData['request_path'] != $rewrite->getRequestPath()) { + // Update existing rewrites history and avoid chain redirects + $where = ['target_path = ?' => $rewrite->getRequestPath()]; + if ($rewrite->getStoreId()) { + $where['store_id = ?'] = (int) $rewrite->getStoreId(); } + $adapter->update( + $this->getMainTable(), + ['target_path' => $rewriteData['request_path']], + $where, + ); } unset($rewriteData); @@ -922,10 +920,8 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId $products = []; $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $adapter = $this->_getReadAdapter(); - if ($productIds !== null) { - if (!is_array($productIds)) { - $productIds = [$productIds]; - } + if ($productIds !== null && !is_array($productIds)) { + $productIds = [$productIds]; } $bind = [ 'website_id' => (int) $websiteId, diff --git a/app/code/core/Mage/Catalog/controllers/CategoryController.php b/app/code/core/Mage/Catalog/controllers/CategoryController.php index 579a92777bb..9327ad1a74a 100644 --- a/app/code/core/Mage/Catalog/controllers/CategoryController.php +++ b/app/code/core/Mage/Catalog/controllers/CategoryController.php @@ -133,11 +133,9 @@ public function viewAction() $this->loadLayoutUpdates(); // apply custom layout update once layout is loaded - if ($layoutUpdates = $settings->getLayoutUpdates()) { - if (is_array($layoutUpdates)) { - foreach ($layoutUpdates as $layoutUpdate) { - $update->addUpdate($layoutUpdate); - } + if (($layoutUpdates = $settings->getLayoutUpdates()) && is_array($layoutUpdates)) { + foreach ($layoutUpdates as $layoutUpdate) { + $update->addUpdate($layoutUpdate); } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Indexer.php index 3dbe6bb7ee6..38a88d49741 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer.php @@ -587,75 +587,71 @@ public function buildEntityPriceFilter($attributes, $values, &$filteredAttribute foreach ($this->_priceIndexers as $indexerName) { $indexer = $this->_indexers[$indexerName]; /** @var Mage_CatalogIndex_Model_Indexer_Abstract $indexer */ - if ($indexer->isAttributeIndexable($attribute)) { - if ($values[$code]) { - if (isset($values[$code]['from']) && isset($values[$code]['to']) - && (strlen($values[$code]['from']) == 0 && strlen($values[$code]['to']) == 0) - ) { - continue; + if ($indexer->isAttributeIndexable($attribute) && $values[$code]) { + if (isset($values[$code]['from']) && isset($values[$code]['to']) + && (strlen($values[$code]['from']) == 0 && strlen($values[$code]['to']) == 0) + ) { + continue; + } + $table = $indexer->getResource()->getMainTable(); + if (!isset($filter[$code])) { + $filter[$code] = $this->_getSelect(); + $filter[$code]->from($table, ['entity_id']); + $filter[$code]->distinct(true); + + $response = new Varien_Object(); + $response->setAdditionalCalculations([]); + $args = [ + 'select' => $filter[$code], + 'table' => $table, + 'store_id' => $store, + 'response_object' => $response, + ]; + Mage::dispatchEvent('catalogindex_prepare_price_select', $args); + $additionalCalculations[$code] = $response->getAdditionalCalculations(); + + if ($indexer->isAttributeIdUsed()) { + //$filter[$code]->where("$table.attribute_id = ?", $attribute->getId()); } - $table = $indexer->getResource()->getMainTable(); - if (!isset($filter[$code])) { - $filter[$code] = $this->_getSelect(); - $filter[$code]->from($table, ['entity_id']); - $filter[$code]->distinct(true); - - $response = new Varien_Object(); - $response->setAdditionalCalculations([]); - $args = [ - 'select' => $filter[$code], - 'table' => $table, - 'store_id' => $store, - 'response_object' => $response, - ]; - Mage::dispatchEvent('catalogindex_prepare_price_select', $args); - $additionalCalculations[$code] = $response->getAdditionalCalculations(); - - if ($indexer->isAttributeIdUsed()) { - //$filter[$code]->where("$table.attribute_id = ?", $attribute->getId()); + } + if (is_array($values[$code])) { + $rateConversion = 1; + $filter[$code]->distinct(true); + + if (isset($values[$code]['from']) && isset($values[$code]['to'])) { + if (isset($values[$code]['currency'])) { + $rateConversion = $this->_getBaseToSpecifiedCurrencyRate( + $values[$code]['currency'], + ); + } else { + $rateConversion = $this->_getBaseToSpecifiedCurrencyRate($currentStoreCurrency); } - } - if (is_array($values[$code])) { - $rateConversion = 1; - $filter[$code]->distinct(true); - - if (isset($values[$code]['from']) && isset($values[$code]['to'])) { - if (isset($values[$code]['currency'])) { - $rateConversion = $this->_getBaseToSpecifiedCurrencyRate( - $values[$code]['currency'], - ); - } else { - $rateConversion = $this->_getBaseToSpecifiedCurrencyRate($currentStoreCurrency); - } - if (strlen($values[$code]['from']) > 0) { - $filter[$code]->where( - "($table.min_price" - . implode('', $additionalCalculations[$code]) . ")*{$rateConversion} >= ?", - $values[$code]['from'], - ); - } - - if (strlen($values[$code]['to']) > 0) { - $filter[$code]->where( - "($table.min_price" - . implode('', $additionalCalculations[$code]) . ")*{$rateConversion} <= ?", - $values[$code]['to'], - ); - } + if (strlen($values[$code]['from']) > 0) { + $filter[$code]->where( + "($table.min_price" + . implode('', $additionalCalculations[$code]) . ")*{$rateConversion} >= ?", + $values[$code]['from'], + ); } - } - $filter[$code]->where("$table.website_id = ?", $website); - if ($code == 'price') { - $filter[$code]->where( - $table . '.customer_group_id = ?', - Mage::getSingleton('customer/session')->getCustomerGroupId(), - ); + if (strlen($values[$code]['to']) > 0) { + $filter[$code]->where( + "($table.min_price" + . implode('', $additionalCalculations[$code]) . ")*{$rateConversion} <= ?", + $values[$code]['to'], + ); + } } - - $filteredAttributes[] = $code; } + $filter[$code]->where("$table.website_id = ?", $website); + if ($code == 'price') { + $filter[$code]->where( + $table . '.customer_group_id = ?', + Mage::getSingleton('customer/session')->getCustomerGroupId(), + ); + } + $filteredAttributes[] = $code; } } } @@ -683,48 +679,45 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p foreach ($this->_attributeIndexers as $indexerName) { $indexer = $this->_indexers[$indexerName]; /** @var Mage_CatalogIndex_Model_Indexer_Abstract $indexer */ - if ($indexer->isAttributeIndexable($attribute)) { - if ($values[$code]) { - if (isset($values[$code]['from']) && isset($values[$code]['to']) - && (!$values[$code]['from'] && !$values[$code]['to']) - ) { - continue; - } - - $table = $indexer->getResource()->getMainTable(); - if (!isset($filter[$code])) { - $filter[$code] = $this->_getSelect(); - $filter[$code]->from($table, ['entity_id']); - } - if ($indexer->isAttributeIdUsed()) { - $filter[$code]->where('attribute_id = ?', $attribute->getId()); - } - if (is_array($values[$code])) { - if (isset($values[$code]['from']) && isset($values[$code]['to'])) { - if ($values[$code]['from']) { - if (!is_numeric($values[$code]['from'])) { - $_date = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from'])); - $values[$code]['from'] = $_date; - } - - $filter[$code]->where('value >= ?', $values[$code]['from']); + if ($indexer->isAttributeIndexable($attribute) && $values[$code]) { + if (isset($values[$code]['from']) && isset($values[$code]['to']) + && (!$values[$code]['from'] && !$values[$code]['to']) + ) { + continue; + } + $table = $indexer->getResource()->getMainTable(); + if (!isset($filter[$code])) { + $filter[$code] = $this->_getSelect(); + $filter[$code]->from($table, ['entity_id']); + } + if ($indexer->isAttributeIdUsed()) { + $filter[$code]->where('attribute_id = ?', $attribute->getId()); + } + if (is_array($values[$code])) { + if (isset($values[$code]['from']) && isset($values[$code]['to'])) { + if ($values[$code]['from']) { + if (!is_numeric($values[$code]['from'])) { + $_date = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from'])); + $values[$code]['from'] = $_date; } - if ($values[$code]['to']) { - if (!is_numeric($values[$code]['to'])) { - $values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to'])); - } - $filter[$code]->where('value <= ?', $values[$code]['to']); + $filter[$code]->where('value >= ?', $values[$code]['from']); + } + + if ($values[$code]['to']) { + if (!is_numeric($values[$code]['to'])) { + $values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to'])); } - } else { - $filter[$code]->where('value in (?)', $values[$code]); + $filter[$code]->where('value <= ?', $values[$code]['to']); } } else { - $filter[$code]->where('value = ?', $values[$code]); + $filter[$code]->where('value in (?)', $values[$code]); } - $filter[$code]->where('store_id = ?', $store); - $filteredAttributes[] = $code; + } else { + $filter[$code]->where('value = ?', $values[$code]); } + $filter[$code]->where('store_id = ?', $store); + $filteredAttributes[] = $code; } } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php index 1a5cce49542..f178788cf0a 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php @@ -271,12 +271,10 @@ public function reindexFinalPrices($products, $store, $forcedId = null) foreach ($productTypes as $type => $products) { $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); foreach ($products as $product) { - if (is_null($forcedId)) { - if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { - $children = $retreiver->getChildProductIds($store, $product); - if ($children) { - $this->reindexFinalPrices($children, $store, $product); - } + if (is_null($forcedId) && $retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { + $children = $retreiver->getChildProductIds($store, $product); + if ($children) { + $this->reindexFinalPrices($children, $store, $product); } } foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { diff --git a/app/code/core/Mage/CatalogInventory/Model/Observer.php b/app/code/core/Mage/CatalogInventory/Model/Observer.php index a0f608a2be7..da13fa25550 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Observer.php +++ b/app/code/core/Mage/CatalogInventory/Model/Observer.php @@ -482,12 +482,10 @@ public function checkQuoteItemQty($observer) } $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type'); - if (!is_null($productTypeCustomOption)) { - // Check if product related to current item is a part of grouped product - if ($productTypeCustomOption->getValue() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { - $stockItem->setProductName($quoteItem->getProduct()->getName()); - $stockItem->setIsChildItem(true); - } + // Check if product related to current item is a part of grouped product + if (!is_null($productTypeCustomOption) && $productTypeCustomOption->getValue() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { + $stockItem->setProductName($quoteItem->getProduct()->getName()); + $stockItem->setIsChildItem(true); } $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty); diff --git a/app/code/core/Mage/CatalogRule/Model/Observer.php b/app/code/core/Mage/CatalogRule/Model/Observer.php index aec52fb175c..433ec9e9354 100644 --- a/app/code/core/Mage/CatalogRule/Model/Observer.php +++ b/app/code/core/Mage/CatalogRule/Model/Observer.php @@ -339,10 +339,8 @@ protected function _removeAttributeFromConditions($combine, $attributeCode) if ($condition instanceof Mage_CatalogRule_Model_Rule_Condition_Combine) { $this->_removeAttributeFromConditions($condition, $attributeCode); } - if ($condition instanceof Mage_Rule_Model_Condition_Product_Abstract) { - if ($condition->getAttribute() == $attributeCode) { - unset($conditions[$conditionId]); - } + if ($condition instanceof Mage_Rule_Model_Condition_Product_Abstract && $condition->getAttribute() == $attributeCode) { + unset($conditions[$conditionId]); } } $combine->setConditions($conditions); diff --git a/app/code/core/Mage/CatalogSearch/Model/Advanced.php b/app/code/core/Mage/CatalogSearch/Model/Advanced.php index b45c3392837..270e2e8b186 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Advanced.php +++ b/app/code/core/Mage/CatalogSearch/Model/Advanced.php @@ -170,17 +170,14 @@ public function addFilters($values) } } } elseif ($attribute->isIndexable()) { - if (!is_string($value) || strlen($value) != 0) { - if ($this->_getResource() - ->addIndexableAttributeModifiedFilter( - $this->getProductCollection(), - $attribute, - $value, - ) - ) { - $hasConditions = true; - $this->_addSearchCriteria($attribute, $value); - } + if ((!is_string($value) || strlen($value) != 0) && $this->_getResource() + ->addIndexableAttributeModifiedFilter( + $this->getProductCollection(), + $attribute, + $value, + )) { + $hasConditions = true; + $this->_addSearchCriteria($attribute, $value); } } else { $condition = $this->_prepareCondition($attribute, $value); @@ -219,33 +216,31 @@ protected function _addSearchCriteria($attribute, $value) { $name = $attribute->getStoreLabel(); - if (is_array($value)) { - if (isset($value['from']) && isset($value['to'])) { - if (!empty($value['from']) || !empty($value['to'])) { - if (isset($value['currency'])) { - $currencyModel = Mage::getModel('directory/currency')->load($value['currency']); - $from = $currencyModel->format($value['from'], [], false); - $to = $currencyModel->format($value['to'], [], false); - } else { - $currencyModel = null; - } - - if (strlen($value['from']) > 0 && strlen($value['to']) > 0) { - $value = sprintf( - '%s - %s', - ($currencyModel ? $from : $value['from']), - ($currencyModel ? $to : $value['to']), - ); - } elseif (strlen($value['from']) > 0) { - // and more - $value = Mage::helper('catalogsearch')->__('%s and greater', ($currencyModel ? $from : $value['from'])); - } elseif (strlen($value['to']) > 0) { - // to - $value = Mage::helper('catalogsearch')->__('up to %s', ($currencyModel ? $to : $value['to'])); - } + if (is_array($value) && (isset($value['from']) && isset($value['to']))) { + if (!empty($value['from']) || !empty($value['to'])) { + if (isset($value['currency'])) { + $currencyModel = Mage::getModel('directory/currency')->load($value['currency']); + $from = $currencyModel->format($value['from'], [], false); + $to = $currencyModel->format($value['to'], [], false); } else { - return $this; + $currencyModel = null; + } + + if (strlen($value['from']) > 0 && strlen($value['to']) > 0) { + $value = sprintf( + '%s - %s', + ($currencyModel ? $from : $value['from']), + ($currencyModel ? $to : $value['to']), + ); + } elseif (strlen($value['from']) > 0) { + // and more + $value = Mage::helper('catalogsearch')->__('%s and greater', ($currencyModel ? $from : $value['from'])); + } elseif (strlen($value['to']) > 0) { + // to + $value = Mage::helper('catalogsearch')->__('up to %s', ($currencyModel ? $to : $value['to'])); } + } else { + return $this; } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php index 4416296f5ba..80954371ffc 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php @@ -143,11 +143,9 @@ public function addIndexableAttributeModifiedFilter($collection, $attribute, $va $storeId = Mage::app()->getStore()->getId(); $select = $collection->getSelect(); - if (is_array($value)) { - if (isset($value['from']) && isset($value['to'])) { - if (empty($value['from']) && empty($value['to'])) { - return false; - } + if (is_array($value) && (isset($value['from']) && isset($value['to']))) { + if (empty($value['from']) && empty($value['to'])) { + return false; } } diff --git a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php index a2ba80c6c58..1d47883cb40 100644 --- a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php +++ b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php @@ -20,14 +20,12 @@ class Mage_Centinel_Block_Adminhtml_Validation_Form extends Mage_Adminhtml_Block protected function _toHtml() { $payment = $this->getQuote()->getPayment(); - if ($payment && $method = $payment->getMethodInstance()) { - if ($method->getIsCentinelValidationEnabled() && $centinel = $method->getCentinelValidator()) { - $this->setFrameUrl($centinel->getValidatePaymentDataUrl()) - ->setContainerId('centinel_authenticate_iframe') - ->setMethodCode($method->getCode()) - ; - return parent::_toHtml(); - } + if ($payment && ($method = $payment->getMethodInstance()) && ($method->getIsCentinelValidationEnabled() && $centinel = $method->getCentinelValidator())) { + $this->setFrameUrl($centinel->getValidatePaymentDataUrl()) + ->setContainerId('centinel_authenticate_iframe') + ->setMethodCode($method->getCode()) + ; + return parent::_toHtml(); } return ''; } diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php index 717cddb063f..0fa852b1bec 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php @@ -299,10 +299,8 @@ public function getQty() */ public function getIsInStock() { - if ($this->getItem()->getProduct()->isSaleable()) { - if ($this->getItem()->getProduct()->getStockItem()->getQty() >= $this->getItem()->getQty()) { - return true; - } + if ($this->getItem()->getProduct()->isSaleable() && $this->getItem()->getProduct()->getStockItem()->getQty() >= $this->getItem()->getQty()) { + return true; } return false; } diff --git a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php index b369f7803cb..229087556f8 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php @@ -76,10 +76,8 @@ protected function _applyCoupon($quoteId, $couponCode, $store = null) $this->_fault('cannot_apply_coupon_code', $e->getMessage()); } - if ($couponCode) { - if (!$couponCode == $quote->getCouponCode()) { - $this->_fault('coupon_code_is_not_valid'); - } + if ($couponCode && !$couponCode == $quote->getCouponCode()) { + $this->_fault('coupon_code_is_not_valid'); } return true; diff --git a/app/code/core/Mage/Checkout/Model/Session.php b/app/code/core/Mage/Checkout/Model/Session.php index 9552bf6b368..7e17392b5c6 100644 --- a/app/code/core/Mage/Checkout/Model/Session.php +++ b/app/code/core/Mage/Checkout/Model/Session.php @@ -221,11 +221,9 @@ public function getQuote() } } - if ($this->getQuoteId()) { - if ($customerSession->isLoggedIn() || $this->_customer) { - $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer(); - $quote->setCustomer($customer); - } + if ($this->getQuoteId() && ($customerSession->isLoggedIn() || $this->_customer)) { + $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer(); + $quote->setCustomer($customer); } $quote->setStore(Mage::app()->getStore()); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 9d27ad7b6f5..baa68634bd2 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -304,10 +304,8 @@ public function saveBilling($data, $customerAddressId) return $result; } - if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) { - if ($this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) { - return ['error' => 1, 'message' => $this->_customerEmailExistsMessage]; - } + if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod() && $this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) { + return ['error' => 1, 'message' => $this->_customerEmailExistsMessage]; } if (!$this->getQuote()->isVirtual()) { diff --git a/app/code/core/Mage/Cms/Helper/Page.php b/app/code/core/Mage/Cms/Helper/Page.php index 710b0a86658..503da819e5a 100644 --- a/app/code/core/Mage/Cms/Helper/Page.php +++ b/app/code/core/Mage/Cms/Helper/Page.php @@ -62,13 +62,11 @@ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pag $inRange = Mage::app()->getLocale() ->isStoreDateInInterval(null, $page->getCustomThemeFrom(), $page->getCustomThemeTo()); - if ($page->getCustomTheme()) { - if ($inRange) { - [$package, $theme] = explode('/', $page->getCustomTheme()); - Mage::getSingleton('core/design_package') - ->setPackageName($package) - ->setTheme($theme); - } + if ($page->getCustomTheme() && $inRange) { + [$package, $theme] = explode('/', $page->getCustomTheme()); + Mage::getSingleton('core/design_package') + ->setPackageName($package) + ->setTheme($theme); } $action->getLayout()->getUpdate() diff --git a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Layer/State/Swatch.php b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Layer/State/Swatch.php index cb314fd3ad3..e4dd90266fe 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Layer/State/Swatch.php +++ b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Layer/State/Swatch.php @@ -35,12 +35,10 @@ class Mage_ConfigurableSwatches_Block_Catalog_Layer_State_Swatch extends Mage_Co public function shouldRender($filter) { $helper = Mage::helper('configurableswatches'); - if ($helper->isEnabled() && $filter->getFilter()->hasAttributeModel()) { - if ($helper->attrIsSwatchType($filter->getFilter()->getAttributeModel())) { - $this->_init($filter); - if ($this->getSwatchUrl()) { - return true; - } + if ($helper->isEnabled() && $filter->getFilter()->hasAttributeModel() && $helper->attrIsSwatchType($filter->getFilter()->getAttributeModel())) { + $this->_init($filter); + if ($this->getSwatchUrl()) { + return true; } } return false; diff --git a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php index 8726c42ff14..c72b0080863 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php +++ b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php @@ -31,11 +31,9 @@ class Mage_ConfigurableSwatches_Block_Catalog_Product_View_Type_Configurable_Swa */ public function shouldRender($attribute, $jsonConfig) { - if (Mage::helper('configurableswatches')->isEnabled()) { - if (Mage::helper('configurableswatches')->attrIsSwatchType($attribute->getProductAttribute())) { - $this->_init($jsonConfig); - return true; - } + if (Mage::helper('configurableswatches')->isEnabled() && Mage::helper('configurableswatches')->attrIsSwatchType($attribute->getProductAttribute())) { + $this->_init($jsonConfig); + return true; } return false; } diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 82d8803dbcd..47634f4712b 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -399,21 +399,17 @@ public function dispatch($action) $this->preDispatch(); Varien_Profiler::stop(self::PROFILER_KEY . '::predispatch'); - if ($this->getRequest()->isDispatched()) { - /** - * preDispatch() didn't change the action, so we can continue - */ - if (!$this->getFlag('', self::FLAG_NO_DISPATCH)) { - $profilerKey = self::PROFILER_KEY . '::' . $this->getFullActionName(); - - Varien_Profiler::start($profilerKey); - $this->$actionMethodName(); - Varien_Profiler::stop($profilerKey); - - Varien_Profiler::start(self::PROFILER_KEY . '::postdispatch'); - $this->postDispatch(); - Varien_Profiler::stop(self::PROFILER_KEY . '::postdispatch'); - } + /** + * preDispatch() didn't change the action, so we can continue + */ + if ($this->getRequest()->isDispatched() && !$this->getFlag('', self::FLAG_NO_DISPATCH)) { + $profilerKey = self::PROFILER_KEY . '::' . $this->getFullActionName(); + Varien_Profiler::start($profilerKey); + $this->$actionMethodName(); + Varien_Profiler::stop($profilerKey); + Varien_Profiler::start(self::PROFILER_KEY . '::postdispatch'); + $this->postDispatch(); + Varien_Profiler::stop(self::PROFILER_KEY . '::postdispatch'); } } catch (Mage_Core_Controller_Varien_Exception $e) { // set prepared flags @@ -460,12 +456,10 @@ public function getActionMethodName($action) */ public function preDispatch() { - if (!$this->getFlag('', self::FLAG_NO_CHECK_INSTALLATION)) { - if (!Mage::isInstalled()) { - $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_redirect('install'); - return; - } + if (!$this->getFlag('', self::FLAG_NO_CHECK_INSTALLATION) && !Mage::isInstalled()) { + $this->setFlag('', self::FLAG_NO_DISPATCH, true); + $this->_redirect('install'); + return; } // Prohibit disabled store actions @@ -792,15 +786,11 @@ protected function _getRefererUrl() */ protected function _isUrlInternal($url) { - if (str_contains($url, 'http')) { - /** - * Url must start from base secure or base unsecure url - */ - if (str_starts_with($url, Mage::app()->getStore()->getBaseUrl()) - || str_starts_with($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) - ) { - return true; - } + /** + * Url must start from base secure or base unsecure url + */ + if (str_contains($url, 'http') && (str_starts_with($url, Mage::app()->getStore()->getBaseUrl()) || str_starts_with($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)))) { + return true; } return false; } diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php index a70374990dd..e279e5ac252 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php @@ -454,20 +454,14 @@ public function getControllerClassName($realModule, $controller) public function rewrite(array $p) { $rewrite = Mage::getConfig()->getNode('global/rewrite'); - if ($module = $rewrite->{$p[0]}) { - if (!$module->children()) { - $p[0] = trim((string) $module); - } + if (($module = $rewrite->{$p[0]}) && !$module->children()) { + $p[0] = trim((string) $module); } - if (isset($p[1]) && ($controller = $rewrite->{$p[0]}->{$p[1]})) { - if (!$controller->children()) { - $p[1] = trim((string) $controller); - } + if (isset($p[1]) && ($controller = $rewrite->{$p[0]}->{$p[1]}) && !$controller->children()) { + $p[1] = trim((string) $controller); } - if (isset($p[2]) && ($action = $rewrite->{$p[0]}->{$p[1]}->{$p[2]})) { - if (!$action->children()) { - $p[2] = trim((string) $action); - } + if (isset($p[2]) && ($action = $rewrite->{$p[0]}->{$p[1]}->{$p[2]}) && !$action->children()) { + $p[2] = trim((string) $action); } return $p; diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index 153f0e0018a..f300db7d732 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -219,10 +219,8 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false, } } // remove last element, if empty - if ($count = count($result)) { - if ($result[$count - 1] === '') { - unset($result[$count - 1]); - } + if (($count = count($result)) && $result[$count - 1] === '') { + unset($result[$count - 1]); } // remove first element, if empty if (isset($result[0]) && $result[0] === '') { diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index fbe0bf291cb..2b6eee5879a 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -275,10 +275,8 @@ protected function _generateBlock($node, $parent) */ protected function _generateAction($node, $parent) { - if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { - if (!Mage::getStoreConfigFlag($configPath)) { - return $this; - } + if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig']) && !Mage::getStoreConfigFlag($configPath)) { + return $this; } $method = (string) $node['method']; @@ -492,10 +490,8 @@ public function addBlock($block, $blockName) protected function _getBlockInstance($block, array $attributes = []) { if (is_string($block)) { - if (str_contains($block, '/')) { - if (!$block = Mage::getConfig()->getBlockClassName($block)) { - Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block)); - } + if (str_contains($block, '/') && !$block = Mage::getConfig()->getBlockClassName($block)) { + Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block)); } if (class_exists($block, false) || mageFindClassFile($block)) { $block = new $block($attributes); diff --git a/app/code/core/Mage/Core/Model/Layout/Update.php b/app/code/core/Mage/Core/Model/Layout/Update.php index 2cde5a543a0..bc1afba3130 100644 --- a/app/code/core/Mage/Core/Model/Layout/Update.php +++ b/app/code/core/Mage/Core/Model/Layout/Update.php @@ -206,10 +206,8 @@ public function loadCache() } // The cache key is just a hash of the real content to de-duplicate the often large XML strings - if (strlen($result) === 40) { // sha1 - if (!$result = Mage::app()->loadCache(self::XML_KEY_PREFIX . $result)) { - return false; - } + // sha1 + if (strlen($result) === 40 && !$result = Mage::app()->loadCache(self::XML_KEY_PREFIX . $result)) { return false; } $this->addUpdate($result); diff --git a/app/code/core/Mage/Core/Model/Layout/Validator.php b/app/code/core/Mage/Core/Model/Layout/Validator.php index d6f10d7b79a..ae65ae6cd5c 100644 --- a/app/code/core/Mage/Core/Model/Layout/Validator.php +++ b/app/code/core/Mage/Core/Model/Layout/Validator.php @@ -199,15 +199,13 @@ public function getDisallowedXpathValidationExpression() */ public function getXpathBlockValidationExpression() { - if (!$this->_xpathBlockValidationExpression) { - if (count($this->_disallowedBlock)) { - foreach ($this->_disallowedBlock as $key => $value) { - $this->_xpathBlockValidationExpression .= $key > 0 ? ' | ' : ''; - $this->_xpathBlockValidationExpression .= - "//block[translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = "; - $this->_xpathBlockValidationExpression .= - "translate('$value', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]"; - } + if (!$this->_xpathBlockValidationExpression && count($this->_disallowedBlock)) { + foreach ($this->_disallowedBlock as $key => $value) { + $this->_xpathBlockValidationExpression .= $key > 0 ? ' | ' : ''; + $this->_xpathBlockValidationExpression .= + "//block[translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = "; + $this->_xpathBlockValidationExpression .= + "translate('$value', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]"; } } return $this->_xpathBlockValidationExpression; diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index e8a9bd9a761..a8b3ae4c5dc 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -516,10 +516,8 @@ public function date($date = null, $part = null, $locale = null, $useTimezone = $date = null; } $date = new Zend_Date($date, $part, $locale); - if ($useTimezone) { - if ($timezone = Mage::app()->getStore()->getConfig(self::XML_PATH_DEFAULT_TIMEZONE)) { - $date->setTimezone($timezone); - } + if ($useTimezone && $timezone = Mage::app()->getStore()->getConfig(self::XML_PATH_DEFAULT_TIMEZONE)) { + $date->setTimezone($timezone); } return $date; diff --git a/app/code/core/Mage/Core/Model/Resource/Cache.php b/app/code/core/Mage/Core/Model/Resource/Cache.php index 60178106322..1d16444130a 100644 --- a/app/code/core/Mage/Core/Model/Resource/Cache.php +++ b/app/code/core/Mage/Core/Model/Resource/Cache.php @@ -27,15 +27,13 @@ protected function _construct() public function getAllOptions() { $adapter = $this->_getReadAdapter(); - if ($adapter) { - /** - * Check if table exist (it protect upgrades. cache settings checked before upgrades) - */ - if ($adapter->isTableExists($this->getMainTable())) { - $select = $adapter->select() - ->from($this->getMainTable(), ['code', 'value']); - return $adapter->fetchPairs($select); - } + /** + * Check if table exist (it protect upgrades. cache settings checked before upgrades) + */ + if ($adapter && $adapter->isTableExists($this->getMainTable())) { + $select = $adapter->select() + ->from($this->getMainTable(), ['code', 'value']); + return $adapter->fetchPairs($select); } return false; } diff --git a/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php b/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php index 4efd9579f99..082ea6c72a9 100644 --- a/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php +++ b/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php @@ -165,10 +165,8 @@ public function saveDir($dir) : $dir['name']; $path = Mage::helper('core/file_storage_database')->getMediaBaseDir() . DS . str_replace('/', DS, $path); - if (!file_exists($path) || !is_dir($path)) { - if (!@mkdir($path, 0777, true)) { - Mage::throwException(Mage::helper('core')->__('Unable to create directory: %s', $path)); - } + if ((!file_exists($path) || !is_dir($path)) && !@mkdir($path, 0777, true)) { + Mage::throwException(Mage::helper('core')->__('Unable to create directory: %s', $path)); } return true; diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index ca86a9b5ecb..f8692eab675 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -256,13 +256,9 @@ public function destroy($sessId) #[\ReturnTypeWillChange] public function gc($sessMaxLifeTime) { - if ($this->_automaticCleaningFactor > 0) { - if ($this->_automaticCleaningFactor == 1 || - random_int(1, $this->_automaticCleaningFactor) == 1 - ) { - $where = ['session_expires < ?' => Varien_Date::toTimestamp(true)]; - $this->_write->delete($this->_sessionTable, $where); - } + if ($this->_automaticCleaningFactor > 0 && ($this->_automaticCleaningFactor == 1 || random_int(1, $this->_automaticCleaningFactor) == 1)) { + $where = ['session_expires < ?' => Varien_Date::toTimestamp(true)]; + $this->_write->delete($this->_sessionTable, $where); } return true; } diff --git a/app/code/core/Mage/Core/Model/Session/Abstract.php b/app/code/core/Mage/Core/Model/Session/Abstract.php index b9a1a37a423..4ce34dd41cd 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract.php @@ -488,10 +488,8 @@ public function isValidForPath($path) */ public function addHost($host) { - if ($host === true) { - if (!$host = Mage::app()->getFrontController()->getRequest()->getHttpHost()) { - return $this; - } + if ($host === true && !$host = Mage::app()->getFrontController()->getRequest()->getHttpHost()) { + return $this; } if (!$host) { diff --git a/app/code/core/Mage/Core/Model/Store.php b/app/code/core/Mage/Core/Model/Store.php index b0670a29402..b05033260d6 100644 --- a/app/code/core/Mage/Core/Model/Store.php +++ b/app/code/core/Mage/Core/Model/Store.php @@ -362,24 +362,22 @@ public function initConfigCache() */ if ($this->_configCache === null) { $code = $this->getCode(); - if ($code) { - if (Mage::app()->useCache('config')) { - $cacheId = 'store_' . $code . '_config_cache'; - $data = Mage::app()->loadCache($cacheId); - if ($data) { - $data = unserialize($data, ['allowed_classes' => false]); - } else { - $data = []; - foreach ($this->_configCacheBaseNodes as $node) { - $data[$node] = $this->getConfig($node); - } - Mage::app()->saveCache(serialize($data), $cacheId, [ - self::CACHE_TAG, - Mage_Core_Model_Config::CACHE_TAG, - ]); + if ($code && Mage::app()->useCache('config')) { + $cacheId = 'store_' . $code . '_config_cache'; + $data = Mage::app()->loadCache($cacheId); + if ($data) { + $data = unserialize($data, ['allowed_classes' => false]); + } else { + $data = []; + foreach ($this->_configCacheBaseNodes as $node) { + $data[$node] = $this->getConfig($node); } - $this->_configCache = $data; + Mage::app()->saveCache(serialize($data), $cacheId, [ + self::CACHE_TAG, + Mage_Core_Model_Config::CACHE_TAG, + ]); } + $this->_configCache = $data; } } return $this; diff --git a/app/code/core/Mage/Core/Model/Translate.php b/app/code/core/Mage/Core/Model/Translate.php index 67d8313e40f..04165f7b85c 100644 --- a/app/code/core/Mage/Core/Model/Translate.php +++ b/app/code/core/Mage/Core/Model/Translate.php @@ -221,15 +221,13 @@ protected function _addData($data, $scope, $forceReload = false) * Checking previous value */ $scopeKey = $this->_dataScope[$key] . self::SCOPE_SEPARATOR . $key; - if (!isset($this->_data[$scopeKey])) { - if (isset($this->_data[$key])) { - $this->_data[$scopeKey] = $this->_data[$key]; - /** - * Not allow use translation not related to module - */ - if (Mage::getIsDeveloperMode()) { - unset($this->_data[$key]); - } + if (!isset($this->_data[$scopeKey]) && isset($this->_data[$key])) { + $this->_data[$scopeKey] = $this->_data[$key]; + /** + * Not allow use translation not related to module + */ + if (Mage::getIsDeveloperMode()) { + unset($this->_data[$key]); } } $scopeKey = $scope . self::SCOPE_SEPARATOR . $key; @@ -411,10 +409,8 @@ public function translate($args) $result = $translated; } - if ($this->_translateInline && $this->getTranslateInline()) { - if (!str_contains($result, '{{{') || !str_contains($result, '}}}') || !str_contains($result, '}}{{')) { - $result = '{{{' . $result . '}}{{' . $translated . '}}{{' . $text . '}}{{' . $module . '}}}'; - } + if ($this->_translateInline && $this->getTranslateInline() && (!str_contains($result, '{{{') || !str_contains($result, '}}}') || !str_contains($result, '}}{{'))) { + $result = '{{{' . $result . '}}{{' . $translated . '}}{{' . $text . '}}{{' . $module . '}}}'; } return $result; diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index ce0754fb262..5a7ebb39880 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -668,12 +668,8 @@ public function setRouteParams(array $data, $unsetOldParams = true) unset($data['_use_rewrite']); } - if (isset($data['_store_to_url']) && (bool) $data['_store_to_url'] === true) { - if (!Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getStore()) - && !Mage::app()->isSingleStoreMode() - ) { - $this->setQueryParam('___store', $this->getStore()->getCode()); - } + if (isset($data['_store_to_url']) && (bool) $data['_store_to_url'] === true && (!Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getStore()) && !Mage::app()->isSingleStoreMode())) { + $this->setQueryParam('___store', $this->getStore()->getCode()); } unset($data['_store_to_url']); diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php index 2313924001c..dbdd433469e 100644 --- a/app/code/core/Mage/Cron/Model/Observer.php +++ b/app/code/core/Mage/Cron/Model/Observer.php @@ -275,11 +275,9 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false) $arguments = []; $errorStatus = Mage_Cron_Model_Schedule::STATUS_ERROR; try { - if (!$isAlways) { - if ($time < $now - $scheduleLifetime) { - $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED; - Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.')); - } + if (!$isAlways && $time < $now - $scheduleLifetime) { + $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED; + Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.')); } if ($runConfig->model) { if (!preg_match(self::REGEX_RUN_MODEL, (string) $runConfig->model, $run)) { diff --git a/app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php index 8f3e58f2080..88d99fc122b 100644 --- a/app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php @@ -178,10 +178,8 @@ public function getCurrencySymbolsData() public function setCurrencySymbolsData($symbols = []) { foreach ($this->getCurrencySymbolsData() as $code => $values) { - if (isset($symbols[$code])) { - if ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code])) { - unset($symbols[$code]); - } + if (isset($symbols[$code]) && ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code]))) { + unset($symbols[$code]); } } if ($symbols) { diff --git a/app/code/core/Mage/Customer/Model/Address/Abstract.php b/app/code/core/Mage/Customer/Model/Address/Abstract.php index 02615e37bc4..c175ff1dc70 100644 --- a/app/code/core/Mage/Customer/Model/Address/Abstract.php +++ b/app/code/core/Mage/Customer/Model/Address/Abstract.php @@ -242,11 +242,9 @@ public function getRegion() $regionId = $this->getData('region_id'); $region = $this->getData('region'); - if ($regionId) { - if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) { - $region = $this->getRegionModel($regionId)->getName(); - $this->setData('region', $region); - } + if ($regionId && $this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) { + $region = $this->getRegionModel($regionId)->getName(); + $this->setData('region', $region); } if (!empty($region) && is_string($region)) { diff --git a/app/code/core/Mage/Customer/Model/Config/Share.php b/app/code/core/Mage/Customer/Model/Config/Share.php index 545248c3875..0828b0e077a 100644 --- a/app/code/core/Mage/Customer/Model/Config/Share.php +++ b/app/code/core/Mage/Customer/Model/Config/Share.php @@ -69,12 +69,10 @@ public function toOptionArray() public function _beforeSave() { $value = $this->getValue(); - if ($value == self::SHARE_GLOBAL) { - if (Mage::getResourceSingleton('customer/customer')->findEmailDuplicates()) { - Mage::throwException( - Mage::helper('customer')->__('Cannot share customer accounts globally because some customer accounts with the same emails exist on multiple websites and cannot be merged.'), - ); - } + if ($value == self::SHARE_GLOBAL && Mage::getResourceSingleton('customer/customer')->findEmailDuplicates()) { + Mage::throwException( + Mage::helper('customer')->__('Cannot share customer accounts globally because some customer accounts with the same emails exist on multiple websites and cannot be merged.'), + ); } return $this; } diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php index 7c6aff75816..03b07fe06ee 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php @@ -49,10 +49,8 @@ public function beforeSave($object) */ public function validate($object) { - if ($password = $object->getPassword()) { - if ($password == $object->getPasswordConfirm()) { - return true; - } + if (($password = $object->getPassword()) && $password == $object->getPasswordConfirm()) { + return true; } return parent::validate($object); diff --git a/app/code/core/Mage/Customer/Model/Session.php b/app/code/core/Mage/Customer/Model/Session.php index fb926bd89e0..dfee7484efc 100644 --- a/app/code/core/Mage/Customer/Model/Session.php +++ b/app/code/core/Mage/Customer/Model/Session.php @@ -96,10 +96,8 @@ public function __construct() public function setCustomer(Mage_Customer_Model_Customer $customer) { // check if customer is not confirmed - if ($customer->isConfirmationRequired()) { - if ($customer->getConfirmation()) { - return $this->_logout(); - } + if ($customer->isConfirmationRequired() && $customer->getConfirmation()) { + return $this->_logout(); } $this->_customer = $customer; $this->setId($customer->getId()); diff --git a/app/code/core/Mage/Downloadable/Model/Product/Price.php b/app/code/core/Mage/Downloadable/Model/Product/Price.php index 0b6bb2fda3b..c4081b4ca61 100644 --- a/app/code/core/Mage/Downloadable/Model/Product/Price.php +++ b/app/code/core/Mage/Downloadable/Model/Product/Price.php @@ -32,20 +32,18 @@ public function getFinalPrice($qty, $product) /** * links prices are added to base product price only if they can be purchased separately */ - if ($product->getLinksPurchasedSeparately()) { - if ($linksIds = $product->getCustomOption('downloadable_link_ids')) { - $linkPrice = 0; - /** @var Mage_Downloadable_Model_Product_Type $productType */ - $productType = $product->getTypeInstance(true); - /** @var Mage_Downloadable_Model_Link[] $links */ - $links = $productType->getLinks($product); - foreach (explode(',', $linksIds->getValue()) as $linkId) { - if (isset($links[$linkId])) { - $linkPrice += $links[$linkId]->getPrice(); - } + if ($product->getLinksPurchasedSeparately() && $linksIds = $product->getCustomOption('downloadable_link_ids')) { + $linkPrice = 0; + /** @var Mage_Downloadable_Model_Product_Type $productType */ + $productType = $product->getTypeInstance(true); + /** @var Mage_Downloadable_Model_Link[] $links */ + $links = $productType->getLinks($product); + foreach (explode(',', $linksIds->getValue()) as $linkId) { + if (isset($links[$linkId])) { + $linkPrice += $links[$linkId]->getPrice(); } - $finalPrice += $linkPrice; } + $finalPrice += $linkPrice; } $product->setData('final_price', $finalPrice); diff --git a/app/code/core/Mage/Downloadable/Model/Product/Type.php b/app/code/core/Mage/Downloadable/Model/Product/Type.php index 5fb8e31bc9f..6657cf894d5 100644 --- a/app/code/core/Mage/Downloadable/Model/Product/Type.php +++ b/app/code/core/Mage/Downloadable/Model/Product/Type.php @@ -381,13 +381,11 @@ public function beforeSave($product = null) // Update links_exist attribute value $linksExist = false; - if ($data = $product->getDownloadableData()) { - if (isset($data['link'])) { - foreach ($data['link'] as $linkItem) { - if (!isset($linkItem['is_delete']) || !$linkItem['is_delete']) { - $linksExist = true; - break; - } + if (($data = $product->getDownloadableData()) && isset($data['link'])) { + foreach ($data['link'] as $linkItem) { + if (!isset($linkItem['is_delete']) || !$linkItem['is_delete']) { + $linksExist = true; + break; } } } diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Image.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Image.php index ffea6d3b975..31f5288da62 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Image.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Image.php @@ -63,17 +63,13 @@ protected function _validateByRules($value) } } - if (!empty($rules['max_image_width'])) { - if ($rules['max_image_width'] < $imageProp[0]) { - $r = $rules['max_image_width']; - $errors[] = Mage::helper('eav')->__('"%s" width exceeds allowed value of %s px.', $label, $r); - } + if (!empty($rules['max_image_width']) && $rules['max_image_width'] < $imageProp[0]) { + $r = $rules['max_image_width']; + $errors[] = Mage::helper('eav')->__('"%s" width exceeds allowed value of %s px.', $label, $r); } - if (!empty($rules['max_image_heght'])) { - if ($rules['max_image_heght'] < $imageProp[1]) { - $r = $rules['max_image_heght']; - $errors[] = Mage::helper('eav')->__('"%s" height exceeds allowed value of %s px.', $label, $r); - } + if (!empty($rules['max_image_heght']) && $rules['max_image_heght'] < $imageProp[1]) { + $r = $rules['max_image_heght']; + $errors[] = Mage::helper('eav')->__('"%s" height exceeds allowed value of %s px.', $label, $r); } return $errors; diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 4b2b91fe89c..03ba7b2d68f 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -178,10 +178,8 @@ protected function _beforeSave() } } - if ($this->getBackendType() == 'gallery') { - if (!$this->getBackendModel()) { - $this->setBackendModel('eav/entity_attribute_backend_media'); - } + if ($this->getBackendType() == 'gallery' && !$this->getBackendModel()) { + $this->setBackendModel('eav/entity_attribute_backend_media'); } return parent::_beforeSave(); diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php index 0d09d6b8ef2..cb810c42c38 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php @@ -241,14 +241,12 @@ public function validate($object) return true; } - if ($this->getAttribute()->getIsUnique()) { - if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { - $label = $this->getAttribute()->getFrontend()->getLabel(); - throw Mage::exception( - 'Mage_Eav', - Mage::helper('eav')->__('The value of attribute "%s" must be unique', $label), - ); - } + if ($this->getAttribute()->getIsUnique() && !$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { + $label = $this->getAttribute()->getFrontend()->getLabel(); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('The value of attribute "%s" must be unique', $label), + ); } return true; diff --git a/app/code/core/Mage/Index/Model/Indexer.php b/app/code/core/Mage/Index/Model/Indexer.php index eea741fdd89..2e654a0b373 100644 --- a/app/code/core/Mage/Index/Model/Indexer.php +++ b/app/code/core/Mage/Index/Model/Indexer.php @@ -377,10 +377,8 @@ protected function _changeKeyStatus($enable = true) if ($process->getDepends()) { foreach ($process->getDepends() as $processCode) { $dependProcess = $this->getProcessByCode($processCode); - if ($dependProcess && !in_array($processCode, $processed)) { - if ($this->_changeProcessKeyStatus($dependProcess, $enable)) { - $processed[] = $processCode; - } + if ($dependProcess && !in_array($processCode, $processed) && $this->_changeProcessKeyStatus($dependProcess, $enable)) { + $processed[] = $processCode; } } } diff --git a/app/code/core/Mage/Index/Model/Indexer/Abstract.php b/app/code/core/Mage/Index/Model/Indexer/Abstract.php index 95b9077f02e..58644618721 100644 --- a/app/code/core/Mage/Index/Model/Indexer/Abstract.php +++ b/app/code/core/Mage/Index/Model/Indexer/Abstract.php @@ -108,10 +108,8 @@ public function matchEvent(Mage_Index_Model_Event $event) */ public function matchEntityAndType($entity, $type) { - if (isset($this->_matchedEntities[$entity])) { - if (in_array($type, $this->_matchedEntities[$entity])) { - return true; - } + if (isset($this->_matchedEntities[$entity]) && in_array($type, $this->_matchedEntities[$entity])) { + return true; } return false; } diff --git a/app/code/core/Mage/Index/Model/Process.php b/app/code/core/Mage/Index/Model/Process.php index 43e854fa7b8..e2e25555994 100644 --- a/app/code/core/Mage/Index/Model/Process.php +++ b/app/code/core/Mage/Index/Model/Process.php @@ -317,10 +317,8 @@ public function indexEvents($entity = null, $type = null) /** * Check if process indexer can match entity code and action type */ - if ($entity !== null && $type !== null) { - if (!$this->getIndexer()->matchEntityAndType($entity, $type)) { - return $this; - } + if ($entity !== null && $type !== null && !$this->getIndexer()->matchEntityAndType($entity, $type)) { + return $this; } if ($this->getMode() == self::MODE_MANUAL) { diff --git a/app/code/core/Mage/Install/Model/Installer/Db.php b/app/code/core/Mage/Install/Model/Installer/Db.php index a8dd695adc0..83122c48870 100644 --- a/app/code/core/Mage/Install/Model/Installer/Db.php +++ b/app/code/core/Mage/Install/Model/Installer/Db.php @@ -99,12 +99,10 @@ protected function _getCheckedData($data) $data['db_prefix'] = strtolower($data['db_prefix']); } //check table prefix - if ($data['db_prefix'] != '') { - if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $data['db_prefix'])) { - Mage::throwException( - Mage::helper('install')->__('The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter.'), - ); - } + if ($data['db_prefix'] != '' && !preg_match('/^[a-z]+[a-z0-9_]*$/', $data['db_prefix'])) { + Mage::throwException( + Mage::helper('install')->__('The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter.'), + ); } //set default db model if (!isset($data['db_model']) || empty($data['db_model'])) { diff --git a/app/code/core/Mage/Install/Model/Observer.php b/app/code/core/Mage/Install/Model/Observer.php index d4bf04892e4..690bf52d03a 100644 --- a/app/code/core/Mage/Install/Model/Observer.php +++ b/app/code/core/Mage/Install/Model/Observer.php @@ -16,10 +16,8 @@ class Mage_Install_Model_Observer { public function bindLocale($observer) { - if ($locale = $observer->getEvent()->getLocale()) { - if ($choosedLocale = Mage::getSingleton('install/session')->getLocale()) { - $locale->setLocaleCode($choosedLocale); - } + if (($locale = $observer->getEvent()->getLocale()) && $choosedLocale = Mage::getSingleton('install/session')->getLocale()) { + $locale->setLocaleCode($choosedLocale); } return $this; } diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor.php b/app/code/core/Mage/Log/Model/Resource/Visitor.php index dbee7eb23ad..5e2341286f7 100644 --- a/app/code/core/Mage/Log/Model/Resource/Visitor.php +++ b/app/code/core/Mage/Log/Model/Resource/Visitor.php @@ -111,10 +111,8 @@ protected function _afterSave(Mage_Core_Model_Abstract $visitor) $this->_saveCustomerInfo($visitor); } } - if ($this->_urlLoggingCondition->isVisitorLogEnabled()) { - if ($visitor->getDoQuoteCreate() || $visitor->getDoQuoteDestroy()) { - $this->_saveQuoteInfo($visitor); - } + if ($this->_urlLoggingCondition->isVisitorLogEnabled() && ($visitor->getDoQuoteCreate() || $visitor->getDoQuoteDestroy())) { + $this->_saveQuoteInfo($visitor); } } return $this; diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index 4b9e448af81..13e8fab989e 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -302,11 +302,9 @@ public function bindQuoteCreate($observer) { /** @var Mage_Sales_Model_Quote $quote */ $quote = $observer->getEvent()->getQuote(); - if ($quote) { - if ($quote->getIsCheckoutCart()) { - $this->setQuoteId($quote->getId()); - $this->setDoQuoteCreate(true); - } + if ($quote && $quote->getIsCheckoutCart()) { + $this->setQuoteId($quote->getId()); + $this->setDoQuoteCreate(true); } return $this; } diff --git a/app/code/core/Mage/Page/Block/Html/Pager.php b/app/code/core/Mage/Page/Block/Html/Pager.php index f7fd414df1b..163c1eb9333 100644 --- a/app/code/core/Mage/Page/Block/Html/Pager.php +++ b/app/code/core/Mage/Page/Block/Html/Pager.php @@ -87,10 +87,8 @@ public function getLimit() return $this->_limit; } $limits = $this->getAvailableLimit(); - if ($limit = $this->getRequest()->getParam($this->getLimitVarName())) { - if (isset($limits[$limit])) { - return $limit; - } + if (($limit = $this->getRequest()->getParam($this->getLimitVarName())) && isset($limits[$limit])) { + return $limit; } $limits = array_keys($limits); return $limits[0]; diff --git a/app/code/core/Mage/Payment/Block/Form/Container.php b/app/code/core/Mage/Payment/Block/Form/Container.php index 987209392da..98a9326bf56 100644 --- a/app/code/core/Mage/Payment/Block/Form/Container.php +++ b/app/code/core/Mage/Payment/Block/Form/Container.php @@ -73,10 +73,8 @@ protected function _assignMethod($method) */ public function setMethodFormTemplate($method = '', $template = '') { - if (!empty($method) && !empty($template)) { - if ($block = $this->getChild('payment.method.' . $method)) { - $block->setTemplate($template); - } + if (!empty($method) && !empty($template) && $block = $this->getChild('payment.method.' . $method)) { + $block->setTemplate($template); } return $this; } diff --git a/app/code/core/Mage/Payment/Block/Info/Container.php b/app/code/core/Mage/Payment/Block/Info/Container.php index 059a485ba74..5d461cdb855 100644 --- a/app/code/core/Mage/Payment/Block/Info/Container.php +++ b/app/code/core/Mage/Payment/Block/Info/Container.php @@ -62,10 +62,8 @@ public function getPaymentInfo() */ public function setInfoTemplate($method = '', $template = '') { - if ($info = $this->getPaymentInfo()) { - if ($info->getMethodInstance()->getCode() == $method) { - $this->getChild($this->_getInfoBlockName())->setTemplate($template); - } + if (($info = $this->getPaymentInfo()) && $info->getMethodInstance()->getCode() == $method) { + $this->getChild($this->_getInfoBlockName())->setTemplate($template); } return $this; } diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 1f9bfebf7e7..b61584e61ff 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -29,12 +29,10 @@ public function getActiveMethods($store = null) $methods = []; $config = Mage::getStoreConfig('payment', $store); foreach ($config as $code => $methodConfig) { - if (Mage::getStoreConfigFlag('payment/' . $code . '/active', $store)) { - if (array_key_exists('model', $methodConfig)) { - $methodModel = Mage::getModel($methodConfig['model']); - if ($methodModel && $methodModel->getConfigData('active', $store)) { - $methods[$code] = $this->_getMethod($code, $methodConfig); - } + if (Mage::getStoreConfigFlag('payment/' . $code . '/active', $store) && array_key_exists('model', $methodConfig)) { + $methodModel = Mage::getModel($methodConfig['model']); + if ($methodModel && $methodModel->getConfigData('active', $store)) { + $methods[$code] = $this->_getMethod($code, $methodConfig); } } } diff --git a/app/code/core/Mage/Payment/Model/Info.php b/app/code/core/Mage/Payment/Model/Info.php index dc641aacdd5..19e48d68d1d 100644 --- a/app/code/core/Mage/Payment/Model/Info.php +++ b/app/code/core/Mage/Payment/Model/Info.php @@ -61,15 +61,11 @@ class Mage_Payment_Model_Info extends Mage_Core_Model_Abstract */ public function getData($key = '', $index = null) { - if ($key === 'cc_number') { - if (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc'])) { - $this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc()); - } + if ($key === 'cc_number' && (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc']))) { + $this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc()); } - if ($key === 'cc_cid') { - if (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc'])) { - $this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc()); - } + if ($key === 'cc_cid' && (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc']))) { + $this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc()); } return parent::getData($key, $index); } diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index 67a98732e9d..3d6053b572c 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -658,30 +658,20 @@ public function isAvailable($quote = null) */ public function isApplicableToQuote($quote, $checksBitMask) { - if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY) { - if (!$this->canUseForCountry($quote->getBillingAddress()->getCountry())) { - return false; - } + if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY && !$this->canUseForCountry($quote->getBillingAddress()->getCountry())) { + return false; } - if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY) { - if (!$this->canUseForCurrency($quote->getStore()->getBaseCurrencyCode())) { - return false; - } + if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY && !$this->canUseForCurrency($quote->getStore()->getBaseCurrencyCode())) { + return false; } - if ($checksBitMask & self::CHECK_USE_CHECKOUT) { - if (!$this->canUseCheckout()) { - return false; - } + if ($checksBitMask & self::CHECK_USE_CHECKOUT && !$this->canUseCheckout()) { + return false; } - if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING) { - if (!$this->canUseForMultishipping()) { - return false; - } + if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING && !$this->canUseForMultishipping()) { + return false; } - if ($checksBitMask & self::CHECK_USE_INTERNAL) { - if (!$this->canUseInternal()) { - return false; - } + if ($checksBitMask & self::CHECK_USE_INTERNAL && !$this->canUseInternal()) { + return false; } if ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) { $total = $quote->getBaseGrandTotal(); @@ -691,10 +681,8 @@ public function isApplicableToQuote($quote, $checksBitMask) return false; } } - if ($checksBitMask & self::CHECK_RECURRING_PROFILES) { - if (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems()) { - return false; - } + if ($checksBitMask & self::CHECK_RECURRING_PROFILES && (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems())) { + return false; } if ($checksBitMask & self::CHECK_ZERO_TOTAL) { $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount(); diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php index 331e86942aa..a553b916dcf 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php @@ -249,11 +249,9 @@ public function importProduct(Mage_Catalog_Model_Product $product) $options = $product->getCustomOption(self::PRODUCT_OPTIONS_KEY); if ($options) { $options = unserialize($options->getValue(), ['allowed_classes' => false]); - if (is_array($options)) { - if (isset($options['start_datetime'])) { - $startDatetime = new Zend_Date($options['start_datetime'], Varien_Date::DATETIME_INTERNAL_FORMAT); - $this->setNearestStartDatetime($startDatetime); - } + if (is_array($options) && isset($options['start_datetime'])) { + $startDatetime = new Zend_Date($options['start_datetime'], Varien_Date::DATETIME_INTERNAL_FORMAT); + $this->setNearestStartDatetime($startDatetime); } } diff --git a/app/code/core/Mage/Paypal/Helper/Data.php b/app/code/core/Mage/Paypal/Helper/Data.php index 6522de53d95..0f2ae5a0da0 100644 --- a/app/code/core/Mage/Paypal/Helper/Data.php +++ b/app/code/core/Mage/Paypal/Helper/Data.php @@ -43,10 +43,8 @@ public function shouldAskToCreateBillingAgreement(Mage_Paypal_Model_Config $conf { if (self::$_shouldAskToCreateBillingAgreement === null) { self::$_shouldAskToCreateBillingAgreement = false; - if ($customerId && $config->shouldAskToCreateBillingAgreement()) { - if (Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($customerId)) { - self::$_shouldAskToCreateBillingAgreement = true; - } + if ($customerId && $config->shouldAskToCreateBillingAgreement() && Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($customerId)) { + self::$_shouldAskToCreateBillingAgreement = true; } } return self::$_shouldAskToCreateBillingAgreement; diff --git a/app/code/core/Mage/Paypal/Model/Api/Nvp.php b/app/code/core/Mage/Paypal/Model/Api/Nvp.php index 97e001377b3..56ab3ca2406 100644 --- a/app/code/core/Mage/Paypal/Model/Api/Nvp.php +++ b/app/code/core/Mage/Paypal/Model/Api/Nvp.php @@ -916,10 +916,8 @@ public function call($methodName, array $request) { $request = $this->_addMethodToRequest($methodName, $request); $eachCallRequest = $this->_prepareEachCallRequest($methodName); - if ($this->getUseCertAuthentication()) { - if ($key = array_search('SIGNATURE', $eachCallRequest)) { - unset($eachCallRequest[$key]); - } + if ($this->getUseCertAuthentication() && $key = array_search('SIGNATURE', $eachCallRequest)) { + unset($eachCallRequest[$key]); } $request = $this->_exportToRequest($eachCallRequest, $request); $debugData = ['url' => $this->getApiEndpoint(), $methodName => $request]; @@ -1529,10 +1527,8 @@ protected function _prepareEachCallRequest($methodName) */ protected function _prepareExpressCheckoutCallRequest(&$requestFields) { - if (!$this->_config->shouldUseUnilateralPayments()) { - if ($key = array_search('SUBJECT', $requestFields)) { - unset($requestFields[$key]); - } + if (!$this->_config->shouldUseUnilateralPayments() && $key = array_search('SUBJECT', $requestFields)) { + unset($requestFields[$key]); } } diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index b70d94eb6b1..bb07f79b132 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -340,13 +340,11 @@ public function start($returnUrl, $cancelUrl, $button = null) ; // add shipping options if needed and line items are available - if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) { - if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) { - if ($options = $this->_prepareShippingOptions($address, true)) { - $this->_api->setShippingOptionsCallbackUrl( - Mage::getUrl('*/*/shippingOptionsCallback', ['quote_id' => $this->_quote->getId()]), - )->setShippingOptions($options); - } + if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems() && (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems())) { + if ($options = $this->_prepareShippingOptions($address, true)) { + $this->_api->setShippingOptionsCallbackUrl( + Mage::getUrl('*/*/shippingOptionsCallback', ['quote_id' => $this->_quote->getId()]), + )->setShippingOptions($options); } } @@ -433,11 +431,9 @@ public function returnFromPaypal($token) // import shipping method $code = ''; - if ($this->_api->getShippingRateCode()) { - if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) { - // possible bug of double collecting rates :-/ - $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true); - } + if ($this->_api->getShippingRateCode() && $code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) { + // possible bug of double collecting rates :-/ + $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true); } $quote->getPayment()->setAdditionalInformation( self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, @@ -542,12 +538,10 @@ public function getShippingOptionsCallbackResponse(array $request) */ public function updateShippingMethod($methodCode) { - if (!$this->_quote->getIsVirtual() && $shippingAddress = $this->_quote->getShippingAddress()) { - if ($methodCode != $shippingAddress->getShippingMethod()) { - $this->_ignoreAddressValidation(); - $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true); - $this->_quote->collectTotals()->save(); - } + if (!$this->_quote->getIsVirtual() && ($shippingAddress = $this->_quote->getShippingAddress()) && $methodCode != $shippingAddress->getShippingMethod()) { + $this->_ignoreAddressValidation(); + $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true); + $this->_quote->collectTotals()->save(); } } diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Report/Settlement.php index 702569d8cf6..fab1c5f8f06 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement.php @@ -158,10 +158,8 @@ protected function _construct() protected function _beforeSave() { $this->_dataSaveAllowed = true; - if ($this->getId()) { - if ($this->getLastModified() == $this->getReportLastModified()) { - $this->_dataSaveAllowed = false; - } + if ($this->getId() && $this->getLastModified() == $this->getReportLastModified()) { + $this->_dataSaveAllowed = false; } $this->setLastModified($this->getReportLastModified()); return parent::_beforeSave(); diff --git a/app/code/core/Mage/ProductAlert/Helper/Data.php b/app/code/core/Mage/ProductAlert/Helper/Data.php index f68731ac24f..2afc26af5cf 100644 --- a/app/code/core/Mage/ProductAlert/Helper/Data.php +++ b/app/code/core/Mage/ProductAlert/Helper/Data.php @@ -86,10 +86,8 @@ public function createBlock($block) { $error = Mage::helper('core')->__('Invalid block type: %s', $block); if (is_string($block)) { - if (str_contains($block, '/')) { - if (!$block = Mage::getConfig()->getBlockClassName($block)) { - Mage::throwException($error); - } + if (str_contains($block, '/') && !$block = Mage::getConfig()->getBlockClassName($block)) { + Mage::throwException($error); } $fileName = mageFindClassFile($block); if ($fileName !== false) { diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Price.php b/app/code/core/Mage/ProductAlert/Model/Resource/Price.php index e9835f50c69..8c7bf68a93a 100644 --- a/app/code/core/Mage/ProductAlert/Model/Resource/Price.php +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Price.php @@ -27,17 +27,13 @@ protected function _construct() */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { - if (is_null($object->getId()) && $object->getCustomerId() - && $object->getProductId() && $object->getWebsiteId() - ) { - if ($row = $this->_getAlertRow($object)) { - $price = $object->getPrice(); - $object->addData($row); - if ($price) { - $object->setPrice($price); - } - $object->setStatus(0); + if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId() && $row = $this->_getAlertRow($object)) { + $price = $object->getPrice(); + $object->addData($row); + if ($price) { + $object->setPrice($price); } + $object->setStatus(0); } if (is_null($object->getAddDate())) { $object->setAddDate(Mage::getModel('core/date')->gmtDate()); diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php b/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php index e49862e5551..e30c1297c1f 100644 --- a/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php @@ -27,13 +27,9 @@ protected function _construct() */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { - if (is_null($object->getId()) && $object->getCustomerId() - && $object->getProductId() && $object->getWebsiteId() - ) { - if ($row = $this->_getAlertRow($object)) { - $object->addData($row); - $object->setStatus(0); - } + if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId() && $row = $this->_getAlertRow($object)) { + $object->addData($row); + $object->setStatus(0); } if (is_null($object->getAddDate())) { $object->setAddDate(Mage::getModel('core/date')->gmtDate()); diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php index 1fc582dac26..5cf569c9463 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php @@ -169,113 +169,99 @@ protected function _beforeLoad() $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { - if ($periodFrom) { - // not the first day of the year - if ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the year - $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // first day of the next year - $this->_from = $periodFrom->getDate() - ->addYear(1) - ->setMonth(1) - ->setDay(1) - ->toString($dtFormat); - } - } - } + // not the first day of the year + if ($periodFrom && ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1)) { + $dtFrom = $periodFrom->getDate(); + // last day of the year + $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); - if ($periodTo) { - // not the last day of the year - if ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31) { - $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); // first day of the year - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // last day of the previous year - $this->_to = $periodTo->getDate() - ->subYear(1) - ->setMonth(12) - ->setDay(31) - ->toString($dtFormat); - } + // first day of the next year + $this->_from = $periodFrom->getDate() + ->addYear(1) + ->setMonth(1) + ->setDay(1) + ->toString($dtFormat); } } - if ($periodFrom && $periodTo) { - // the same year - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + // not the last day of the year + if ($periodTo && ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31)) { + $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); + // first day of the year + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { $selectUnions[] = $this->_makeBoundarySelect( $dtFrom->toString($dtFormat), $dtTo->toString($dtFormat), ); - $this->getSelect()->where('1<>1'); + // last day of the previous year + $this->_to = $periodTo->getDate() + ->subYear(1) + ->setMonth(12) + ->setDay(31) + ->toString($dtFormat); } } - } elseif ($this->_period == 'month') { - if ($periodFrom) { - // not the first day of the month - if ($periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the month - $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // first day of the next month - $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); - } - } + + // the same year + if ($periodFrom && $periodTo && $periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); + $this->getSelect()->where('1<>1'); } + } elseif ($this->_period == 'month') { + // not the first day of the month + if ($periodFrom && $periodFrom->toValue(Zend_Date::DAY) != 1) { + $dtFrom = $periodFrom->getDate(); + // last day of the month + $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); - if ($periodTo) { - // not the last day of the month - if ($periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { - $dtFrom = $periodTo->getDate()->setDay(1); // first day of the month - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // last day of the previous month - $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); - } + // first day of the next month + $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); } } - if ($periodFrom && $periodTo) { - // the same month - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) - && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH) - ) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + // not the last day of the month + if ($periodTo && $periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { + $dtFrom = $periodTo->getDate()->setDay(1); + // first day of the month + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { $selectUnions[] = $this->_makeBoundarySelect( $dtFrom->toString($dtFormat), $dtTo->toString($dtFormat), ); - $this->getSelect()->where('1<>1'); + // last day of the previous month + $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); } } + + // the same month + if ($periodFrom && $periodTo && ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH))) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); + $this->getSelect()->where('1<>1'); + } } $this->_applyDateRangeFilter(); diff --git a/app/code/core/Mage/Review/controllers/ProductController.php b/app/code/core/Mage/Review/controllers/ProductController.php index 46f24c78bcf..39bda582a74 100644 --- a/app/code/core/Mage/Review/controllers/ProductController.php +++ b/app/code/core/Mage/Review/controllers/ProductController.php @@ -34,14 +34,12 @@ public function preDispatch() } $action = strtolower($this->getRequest()->getActionName()); - if (!$allowGuest && $action == 'post' && $this->getRequest()->isPost()) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { - $this->setFlag('', self::FLAG_NO_DISPATCH, true); - Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_current' => true])); - Mage::getSingleton('review/session')->setFormData($this->getRequest()->getPost()) - ->setRedirectUrl($this->_getRefererUrl()); - $this->_redirectUrl(Mage::helper('customer')->getLoginUrl()); - } + if (!$allowGuest && $action == 'post' && $this->getRequest()->isPost() && !Mage::getSingleton('customer/session')->isLoggedIn()) { + $this->setFlag('', self::FLAG_NO_DISPATCH, true); + Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_current' => true])); + Mage::getSingleton('review/session')->setFormData($this->getRequest()->getPost()) + ->setRedirectUrl($this->_getRefererUrl()); + $this->_redirectUrl(Mage::helper('customer')->getLoginUrl()); } return $this; diff --git a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php index b1d04eff7b8..c985f5b8737 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php @@ -54,10 +54,8 @@ protected function _getPriceBlock($productTypeId) { if (!isset($this->_priceBlock[$productTypeId])) { $block = $this->_priceBlockDefaultType; - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['block'] != '') { - $block = $this->_priceBlockTypes[$productTypeId]['block']; - } + if (isset($this->_priceBlockTypes[$productTypeId]) && $this->_priceBlockTypes[$productTypeId]['block'] != '') { + $block = $this->_priceBlockTypes[$productTypeId]['block']; } $this->_priceBlock[$productTypeId] = $this->getLayout()->createBlock($block); } @@ -72,10 +70,8 @@ protected function _getPriceBlock($productTypeId) */ protected function _getPriceBlockTemplate($productTypeId) { - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { - return $this->_priceBlockTypes[$productTypeId]['template']; - } + if (isset($this->_priceBlockTypes[$productTypeId]) && $this->_priceBlockTypes[$productTypeId]['template'] != '') { + return $this->_priceBlockTypes[$productTypeId]['template']; } return $this->_priceBlockDefaultTemplate; } diff --git a/app/code/core/Mage/Rule/Model/Abstract.php b/app/code/core/Mage/Rule/Model/Abstract.php index f2f5fb27b9d..c1c1f4d2fca 100644 --- a/app/code/core/Mage/Rule/Model/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Abstract.php @@ -103,10 +103,8 @@ public function getProductFlatSelect($storeId) protected function _beforeSave() { // Check if discount amount not negative - if ($this->hasDiscountAmount()) { - if ((int) $this->getDiscountAmount() < 0) { - Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.')); - } + if ($this->hasDiscountAmount() && (int) $this->getDiscountAmount() < 0) { + Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.')); } // Serialize conditions diff --git a/app/code/core/Mage/Sales/Model/Order.php b/app/code/core/Mage/Sales/Model/Order.php index 3c3f413d523..e253725708f 100644 --- a/app/code/core/Mage/Sales/Model/Order.php +++ b/app/code/core/Mage/Sales/Model/Order.php @@ -1085,12 +1085,10 @@ protected function _setState( $shouldProtectState = false ) { // attempt to set the specified state - if ($shouldProtectState) { - if ($this->isStateProtected($state)) { - Mage::throwException( - Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state), - ); - } + if ($shouldProtectState && $this->isStateProtected($state)) { + Mage::throwException( + Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state), + ); } $this->setData('state', $state); diff --git a/app/code/core/Mage/Sales/Model/Order/Payment.php b/app/code/core/Mage/Sales/Model/Order/Payment.php index 850f6f6ddd4..03622468152 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment.php @@ -1191,12 +1191,9 @@ protected function _void($isOnline, $amount = null, $gatewayCallback = 'void') // if the authorization was untouched, we may assume voided amount = order grand total // but only if the payment auth amount equals to order grand total - if ($authTransaction && ($order->getBaseGrandTotal() == $this->getBaseAmountAuthorized()) - && ($this->getBaseAmountCanceled() == 0) + if ($authTransaction && $order->getBaseGrandTotal() == $this->getBaseAmountAuthorized() && $this->getBaseAmountCanceled() == 0 && $authTransaction->canVoidAuthorizationCompletely() ) { - if ($authTransaction->canVoidAuthorizationCompletely()) { - $amount = (float) $order->getBaseGrandTotal(); - } + $amount = (float) $order->getBaseGrandTotal(); } if ($amount) { diff --git a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php index cff16ca70ad..3943f36ab2d 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php @@ -306,10 +306,8 @@ public function closeAuthorization($shouldSave = true, $dryRun = false) break; // case self::TYPE_PAYMENT? } - if ($authTransaction) { - if (!$dryRun) { - $authTransaction->close($shouldSave); - } + if ($authTransaction && !$dryRun) { + $authTransaction->close($shouldSave); } return $authTransaction; } @@ -761,10 +759,8 @@ protected function _verifyTxnType($txnType = null) */ protected function _verifyPaymentObject($dryRun = false) { - if (!$this->_paymentObject || !$this->getOrderId()) { - if (!$dryRun) { - Mage::throwException(Mage::helper('sales')->__('Proper payment object must be set.')); - } + if ((!$this->_paymentObject || !$this->getOrderId()) && !$dryRun) { + Mage::throwException(Mage::helper('sales')->__('Proper payment object must be set.')); } return $this->_paymentObject; } diff --git a/app/code/core/Mage/Sales/Model/Quote.php b/app/code/core/Mage/Sales/Model/Quote.php index 51f9fc816ea..d51e4b461c5 100644 --- a/app/code/core/Mage/Sales/Model/Quote.php +++ b/app/code/core/Mage/Sales/Model/Quote.php @@ -1211,13 +1211,11 @@ public function updateItem($itemId, $buyRequest, $params = null) $items = $this->getAllItems(); foreach ($items as $item) { - if (($item->getProductId() == $productId) && ($item->getId() != $resultItem->getId())) { - if ($resultItem->compare($item)) { - // Product configuration is same as in other quote item - $resultItem->setQty($resultItem->getQty() + $item->getQty()); - $this->removeItem($item->getId()); - break; - } + if ($item->getProductId() == $productId && $item->getId() != $resultItem->getId() && $resultItem->compare($item)) { + // Product configuration is same as in other quote item + $resultItem->setQty($resultItem->getQty() + $item->getQty()); + $this->removeItem($item->getId()); + break; } } } else { diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php index a16421dac76..ae12e282b3c 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php @@ -146,30 +146,25 @@ public function collect(Mage_Sales_Model_Quote_Address $address) $shippingTax = 0; $shippingBaseTax = 0; - if ($shippingTaxClass) { - if ($rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass))) { - if (!Mage::helper('tax')->shippingPriceIncludesTax()) { - $shippingTax = $address->getShippingAmount() * $rate / 100; - $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100; - } else { - $shippingTax = $address->getShippingTaxAmount(); - $shippingBaseTax = $address->getBaseShippingTaxAmount(); - } - - $shippingTax = $store->roundPrice($shippingTax); - $shippingBaseTax = $store->roundPrice($shippingBaseTax); - - $address->setTaxAmount($address->getTaxAmount() + $shippingTax); - $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax); - - $this->_saveAppliedTaxes( - $address, - $taxCalculationModel->getAppliedRates($request), - $shippingTax, - $shippingBaseTax, - $rate, - ); + if ($shippingTaxClass && $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass))) { + if (!Mage::helper('tax')->shippingPriceIncludesTax()) { + $shippingTax = $address->getShippingAmount() * $rate / 100; + $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100; + } else { + $shippingTax = $address->getShippingTaxAmount(); + $shippingBaseTax = $address->getBaseShippingTaxAmount(); } + $shippingTax = $store->roundPrice($shippingTax); + $shippingBaseTax = $store->roundPrice($shippingBaseTax); + $address->setTaxAmount($address->getTaxAmount() + $shippingTax); + $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax); + $this->_saveAppliedTaxes( + $address, + $taxCalculationModel->getAppliedRates($request), + $shippingTax, + $shippingBaseTax, + $rate, + ); } if (!Mage::helper('tax')->shippingPriceIncludesTax()) { diff --git a/app/code/core/Mage/Sales/Model/Quote/Item.php b/app/code/core/Mage/Sales/Model/Quote/Item.php index 67e905b122f..0f3211b50d1 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item.php @@ -438,10 +438,8 @@ public function representProduct($product) * only within same parent item */ $stickWithinParent = $product->getStickWithinParent(); - if ($stickWithinParent) { - if ($this->getParentItem() !== $stickWithinParent) { - return false; - } + if ($stickWithinParent && $this->getParentItem() !== $stickWithinParent) { + return false; } // Check options diff --git a/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php b/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php index 81af1dd1997..45975abb1ab 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php @@ -775,17 +775,13 @@ public function calcTaxAmount() } } - if (Mage::helper('tax')->discountTax($store) && !Mage::helper('tax')->applyTaxAfterDiscount($store)) { - if ($this->getDiscountPercent()) { - $baseTaxAmount = $this->getBaseTaxBeforeDiscount(); - $taxAmount = $this->getTaxBeforeDiscount(); - - $baseDiscountDisposition = $baseTaxAmount / 100 * $this->getDiscountPercent(); - $discountDisposition = $taxAmount / 100 * $this->getDiscountPercent(); - - $this->setDiscountAmount($this->getDiscountAmount() + $discountDisposition); - $this->setBaseDiscountAmount($this->getBaseDiscountAmount() + $baseDiscountDisposition); - } + if (Mage::helper('tax')->discountTax($store) && !Mage::helper('tax')->applyTaxAfterDiscount($store) && $this->getDiscountPercent()) { + $baseTaxAmount = $this->getBaseTaxBeforeDiscount(); + $taxAmount = $this->getTaxBeforeDiscount(); + $baseDiscountDisposition = $baseTaxAmount / 100 * $this->getDiscountPercent(); + $discountDisposition = $taxAmount / 100 * $this->getDiscountPercent(); + $this->setDiscountAmount($this->getDiscountAmount() + $discountDisposition); + $this->setBaseDiscountAmount($this->getBaseDiscountAmount() + $baseDiscountDisposition); } return $this; diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php index 9cafe7e315e..0e2db42b64e 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -170,113 +170,99 @@ protected function _beforeLoad() $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { - if ($periodFrom) { - // not the first day of the year - if ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the year - $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // first day of the next year - $this->_from = $periodFrom->getDate() - ->addYear(1) - ->setMonth(1) - ->setDay(1) - ->toString($dtFormat); - } - } - } + // not the first day of the year + if ($periodFrom && ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1)) { + $dtFrom = $periodFrom->getDate(); + // last day of the year + $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); - if ($periodTo) { - // not the last day of the year - if ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31) { - $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); // first day of the year - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // last day of the previous year - $this->_to = $periodTo->getDate() - ->subYear(1) - ->setMonth(12) - ->setDay(31) - ->toString($dtFormat); - } + // first day of the next year + $this->_from = $periodFrom->getDate() + ->addYear(1) + ->setMonth(1) + ->setDay(1) + ->toString($dtFormat); } } - if ($periodFrom && $periodTo) { - // the same year - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + // not the last day of the year + if ($periodTo && ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31)) { + $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); + // first day of the year + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { $selectUnions[] = $this->_makeBoundarySelect( $dtFrom->toString($dtFormat), $dtTo->toString($dtFormat), ); - $this->getSelect()->where('1<>1'); + // last day of the previous year + $this->_to = $periodTo->getDate() + ->subYear(1) + ->setMonth(12) + ->setDay(31) + ->toString($dtFormat); } } - } elseif ($this->_period == 'month') { - if ($periodFrom) { - // not the first day of the month - if ($periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the month - $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // first day of the next month - $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); - } - } + + // the same year + if ($periodFrom && $periodTo && $periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); + $this->getSelect()->where('1<>1'); } + } elseif ($this->_period == 'month') { + // not the first day of the month + if ($periodFrom && $periodFrom->toValue(Zend_Date::DAY) != 1) { + $dtFrom = $periodFrom->getDate(); + // last day of the month + $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); - if ($periodTo) { - // not the last day of the month - if ($periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { - $dtFrom = $periodTo->getDate()->setDay(1); // first day of the month - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat), - ); - - // last day of the previous month - $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); - } + // first day of the next month + $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); } } - if ($periodFrom && $periodTo) { - // the same month - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) - && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH) - ) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + // not the last day of the month + if ($periodTo && $periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { + $dtFrom = $periodTo->getDate()->setDay(1); + // first day of the month + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { $selectUnions[] = $this->_makeBoundarySelect( $dtFrom->toString($dtFormat), $dtTo->toString($dtFormat), ); - $this->getSelect()->where('1<>1'); + // last day of the previous month + $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); } } + + // the same month + if ($periodFrom && $periodTo && ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH))) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat), + ); + $this->getSelect()->where('1<>1'); + } } $this->_applyDateRangeFilter(); diff --git a/app/code/core/Mage/SalesRule/Model/Observer.php b/app/code/core/Mage/SalesRule/Model/Observer.php index 483f0eaa388..ba1ea509d86 100644 --- a/app/code/core/Mage/SalesRule/Model/Observer.php +++ b/app/code/core/Mage/SalesRule/Model/Observer.php @@ -133,33 +133,30 @@ public function sales_order_paymentCancel($observer) /** @var Mage_Sales_Model_Order $order */ $order = $event->getPayment()->getOrder(); - if ($order->canCancel()) { - if ($code = $order->getCouponCode()) { - // Decrement coupon times_used - $coupon = Mage::getModel('salesrule/coupon')->loadByCode($code); - - if ($coupon->getId()) { - $coupon->setTimesUsed($coupon->getTimesUsed() - 1); - $coupon->save(); - - // Decrement times_used on rule - $rule = Mage::getModel('salesrule/rule'); - $rule->load($coupon->getRuleId()); - if ($rule->getId()) { - $rule->setTimesUsed($rule->getTimesUsed() - 1); - $rule->save(); - } + if ($order->canCancel() && $code = $order->getCouponCode()) { + // Decrement coupon times_used + $coupon = Mage::getModel('salesrule/coupon')->loadByCode($code); + if ($coupon->getId()) { + $coupon->setTimesUsed($coupon->getTimesUsed() - 1); + $coupon->save(); + + // Decrement times_used on rule + $rule = Mage::getModel('salesrule/rule'); + $rule->load($coupon->getRuleId()); + if ($rule->getId()) { + $rule->setTimesUsed($rule->getTimesUsed() - 1); + $rule->save(); + } - if ($customerId = $order->getCustomerId()) { - // Decrement coupon_usage times_used - Mage::getResourceModel('salesrule/coupon_usage')->updateCustomerCouponTimesUsed($customerId, $coupon->getId(), true); + if ($customerId = $order->getCustomerId()) { + // Decrement coupon_usage times_used + Mage::getResourceModel('salesrule/coupon_usage')->updateCustomerCouponTimesUsed($customerId, $coupon->getId(), true); - // Decrement rule times_used - $customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId()); - if ($customerCoupon->getId()) { - $customerCoupon->setTimesUsed($customerCoupon->getTimesUsed() - 1); - $customerCoupon->save(); - } + // Decrement rule times_used + $customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId()); + if ($customerCoupon->getId()) { + $customerCoupon->setTimesUsed($customerCoupon->getTimesUsed() - 1); + $customerCoupon->save(); } } } @@ -230,10 +227,8 @@ protected function _removeAttributeFromConditions($combine, $attributeCode) if ($condition instanceof Mage_Rule_Model_Condition_Combine) { $this->_removeAttributeFromConditions($condition, $attributeCode); } - if ($condition instanceof Mage_SalesRule_Model_Rule_Condition_Product) { - if ($condition->getAttribute() == $attributeCode) { - unset($conditions[$conditionId]); - } + if ($condition instanceof Mage_SalesRule_Model_Rule_Condition_Product && $condition->getAttribute() == $attributeCode) { + unset($conditions[$conditionId]); } } $combine->setConditions($conditions); diff --git a/app/code/core/Mage/SalesRule/Model/Validator.php b/app/code/core/Mage/SalesRule/Model/Validator.php index 42260c2951e..5caf3a20b51 100644 --- a/app/code/core/Mage/SalesRule/Model/Validator.php +++ b/app/code/core/Mage/SalesRule/Model/Validator.php @@ -203,11 +203,9 @@ protected function _canProcessRule($rule, $address) $customerId = $address->getQuote()->getCustomerId(); $ruleCustomer = Mage::getModel('salesrule/rule_customer'); $ruleCustomer->loadByCustomerRule($customerId, $ruleId); - if ($ruleCustomer->getId()) { - if ($ruleCustomer->getTimesUsed() >= $rule->getUsesPerCustomer()) { - $rule->setIsValidForAddress($address, false); - return false; - } + if ($ruleCustomer->getId() && $ruleCustomer->getTimesUsed() >= $rule->getUsesPerCustomer()) { + $rule->setIsValidForAddress($address, false); + return false; } } $rule->afterLoad(); diff --git a/app/code/core/Mage/Tax/Helper/Data.php b/app/code/core/Mage/Tax/Helper/Data.php index 3a7aac51703..6479f55c92e 100644 --- a/app/code/core/Mage/Tax/Helper/Data.php +++ b/app/code/core/Mage/Tax/Helper/Data.php @@ -494,13 +494,11 @@ public function getPrice( $includingPercent = null; $taxClassId = $product->getTaxClassId(); - if (is_null($percent)) { - if ($taxClassId) { - $request = Mage::getSingleton('tax/calculation') - ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store); - $percent = Mage::getSingleton('tax/calculation') - ->getRate($request->setProductClassId($taxClassId)); - } + if (is_null($percent) && $taxClassId) { + $request = Mage::getSingleton('tax/calculation') + ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store); + $percent = Mage::getSingleton('tax/calculation') + ->getRate($request->setProductClassId($taxClassId)); } if ($taxClassId && $priceIncludesTax) { if ($this->isCrossBorderTradeEnabled($store)) { @@ -512,10 +510,8 @@ public function getPrice( } } - if ($percent === false || is_null($percent)) { - if ($priceIncludesTax && !$includingPercent) { - return $price; - } + if (($percent === false || is_null($percent)) && ($priceIncludesTax && !$includingPercent)) { + return $price; } $product->setTaxPercent($percent); @@ -841,10 +837,8 @@ public function getPriceTaxSql($priceField, $taxClassField) $result .= "+(({$priceField}{$result})*{$currentTaxString})"; } } else { - if ($this->displayPriceIncludingTax()) { - if ($currentTaxString) { - $result .= "+({$priceField}*{$currentTaxString})"; - } + if ($this->displayPriceIncludingTax() && $currentTaxString) { + $result .= "+({$priceField}*{$currentTaxString})"; } } return $result; @@ -1097,16 +1091,14 @@ public function getShippingTax($source) } $taxClassAmount = []; - if ($current && $source) { - if ($current->getShippingTaxAmount() != 0 && $current->getBaseShippingTaxAmount() != 0) { - $taxClassAmount[0]['tax_amount'] = $current->getShippingTaxAmount(); - $taxClassAmount[0]['base_tax_amount'] = $current->getBaseShippingTaxAmount(); - if ($current->getShippingHiddenTaxAmount() > 0) { - $taxClassAmount[0]['hidden_tax_amount'] = $current->getShippingHiddenTaxAmount(); - } - $taxClassAmount[0]['title'] = $this->__('Shipping & Handling Tax'); - $taxClassAmount[0]['percent'] = null; + if ($current && $source && ($current->getShippingTaxAmount() != 0 && $current->getBaseShippingTaxAmount() != 0)) { + $taxClassAmount[0]['tax_amount'] = $current->getShippingTaxAmount(); + $taxClassAmount[0]['base_tax_amount'] = $current->getBaseShippingTaxAmount(); + if ($current->getShippingHiddenTaxAmount() > 0) { + $taxClassAmount[0]['hidden_tax_amount'] = $current->getShippingHiddenTaxAmount(); } + $taxClassAmount[0]['title'] = $this->__('Shipping & Handling Tax'); + $taxClassAmount[0]['percent'] = null; } return $taxClassAmount; diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php index 15835ffb07e..2224e9b86ad 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php @@ -1203,11 +1203,9 @@ protected function _aggregateTaxPerRate( $this->_deltaRound($baseRowTaxBeforeDiscount, $rateKey, $inclTax, 'tax_before_discount_base'), ); - if (!$item->getNoDiscount()) { - if ($item->getWeeeTaxApplied()) { - $item->setDiscountTaxCompensation($item->getDiscountTaxCompensation() + - $taxBeforeDiscountRounded - max(0, $rowTax)); - } + if (!$item->getNoDiscount() && $item->getWeeeTaxApplied()) { + $item->setDiscountTaxCompensation($item->getDiscountTaxCompensation() + + $taxBeforeDiscountRounded - max(0, $rowTax)); } if ($inclTax && $discount > 0) { @@ -1572,10 +1570,8 @@ public function fetch(Mage_Sales_Model_Quote_Address $address) /* * when weee discount is not included in extraTaxAmount, we need to add it to the total tax */ - if ($this->_weeeHelper->isEnabled()) { - if (!$this->_weeeHelper->includeInSubtotal()) { - $taxAmount += $address->getWeeeDiscount(); - } + if ($this->_weeeHelper->isEnabled() && !$this->_weeeHelper->includeInSubtotal()) { + $taxAmount += $address->getWeeeDiscount(); } $area = null; diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php index 3b44ba2a5d4..61eee257b03 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php @@ -563,37 +563,34 @@ protected function _createShipmentXml($shipment, $shipKey) $apValue = 0; $apCode = self::ADDITIONAL_PROTECTION_NOT_REQUIRED; - if ($apEnabled) { - if ($apMinValue <= $subtotal) { - switch ($apUseSubtotal) { - case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL: - $apValue = $subtotal; + if ($apEnabled && $apMinValue <= $subtotal) { + switch ($apUseSubtotal) { + case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL: + $apValue = $subtotal; + break; + case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL_WITH_DISCOUNT: + $apValue = $subtotalWithDiscount; + break; + default: + case self::ADDITIONAL_PROTECTION_VALUE_CONFIG: + $apValue = $apConfigValue; + break; + } + if ($apValue) { + $apCode = self::ADDITIONAL_PROTECTION_ASSET; + + switch ($apValueRounding) { + case self::ADDITIONAL_PROTECTION_ROUNDING_CEIL: + $apValue = ceil($apValue); break; - case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL_WITH_DISCOUNT: - $apValue = $subtotalWithDiscount; + case self::ADDITIONAL_PROTECTION_ROUNDING_ROUND: + $apValue = round((float) $apValue); break; default: - case self::ADDITIONAL_PROTECTION_VALUE_CONFIG: - $apValue = $apConfigValue; + case self::ADDITIONAL_PROTECTION_ROUNDING_FLOOR: + $apValue = floor($apValue); break; } - - if ($apValue) { - $apCode = self::ADDITIONAL_PROTECTION_ASSET; - - switch ($apValueRounding) { - case self::ADDITIONAL_PROTECTION_ROUNDING_CEIL: - $apValue = ceil($apValue); - break; - case self::ADDITIONAL_PROTECTION_ROUNDING_ROUND: - $apValue = round((float) $apValue); - break; - default: - case self::ADDITIONAL_PROTECTION_ROUNDING_FLOOR: - $apValue = floor($apValue); - break; - } - } } } @@ -1180,15 +1177,13 @@ protected function _parseXmlTrackingResponse($trackings, $response) public function getResponse() { $statuses = ''; - if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result) { - if ($trackings = $this->_result->getAllTrackings()) { - foreach ($trackings as $tracking) { - if ($data = $tracking->getAllData()) { - if (isset($data['status'])) { - $statuses .= Mage::helper('usa')->__($data['status']) . "\n
"; - } else { - $statuses .= Mage::helper('usa')->__($data['error_message']) . "\n
"; - } + if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result && $trackings = $this->_result->getAllTrackings()) { + foreach ($trackings as $tracking) { + if ($data = $tracking->getAllData()) { + if (isset($data['status'])) { + $statuses .= Mage::helper('usa')->__($data['status']) . "\n
"; + } else { + $statuses .= Mage::helper('usa')->__($data['error_message']) . "\n
"; } } } diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php index 12401b020db..57773f9bfb7 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php @@ -1222,15 +1222,13 @@ protected function _parseXmlTrackingResponse($trackingvalue, $response) public function getResponse() { $statuses = ''; - if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result) { - if ($trackings = $this->_result->getAllTrackings()) { - foreach ($trackings as $tracking) { - if ($data = $tracking->getAllData()) { - if (!empty($data['status'])) { - $statuses .= Mage::helper('usa')->__($data['status']) . "\n
"; - } else { - $statuses .= Mage::helper('usa')->__('Empty response') . "\n
"; - } + if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result && $trackings = $this->_result->getAllTrackings()) { + foreach ($trackings as $tracking) { + if ($data = $tracking->getAllData()) { + if (!empty($data['status'])) { + $statuses .= Mage::helper('usa')->__($data['status']) . "\n
"; + } else { + $statuses .= Mage::helper('usa')->__('Empty response') . "\n
"; } } } diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php index 7cab4330ad4..31ce9518297 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php @@ -431,85 +431,80 @@ protected function _parseXmlResponse($response) $r = $this->_rawRequest; $costArr = []; $priceArr = []; - if (strlen(trim($response)) > 0) { - if (str_starts_with(trim($response), '')) { - $response = str_replace( - '', - '', - $response, - ); - } - $xml = simplexml_load_string($response); - - if (is_object($xml)) { - $allowedMethods = explode(',', $this->getConfigData('allowed_methods')); - $serviceCodeToActualNameMap = []; - /** - * US Rates - */ - if ($this->_isUSCountry($r->getDestCountryId())) { - if (is_object($xml->Package) && is_object($xml->Package->Postage)) { - foreach ($xml->Package->Postage as $postage) { - $serviceName = $this->_filterServiceName((string) $postage->MailService); - $serviceCodeMethod = $this->getCode('method_to_code', $serviceName); - $serviceCode = $serviceCodeMethod ?: (string) $postage->attributes()->CLASSID; - $serviceCodeToActualNameMap[$serviceCode] = $serviceName; - if (in_array($serviceCode, $allowedMethods)) { - $costArr[$serviceCode] = (string) $postage->Rate; - $priceArr[$serviceCode] = $this->getMethodPrice( - (float) $postage->Rate, - $serviceCode, - ); - } + if (strlen(trim($response)) > 0 && str_starts_with(trim($response), '')) { + $response = str_replace( + '', + '', + $response, + ); + } + $xml = simplexml_load_string($response); + if (is_object($xml)) { + $allowedMethods = explode(',', $this->getConfigData('allowed_methods')); + $serviceCodeToActualNameMap = []; + /** + * US Rates + */ + if ($this->_isUSCountry($r->getDestCountryId())) { + if (is_object($xml->Package) && is_object($xml->Package->Postage)) { + foreach ($xml->Package->Postage as $postage) { + $serviceName = $this->_filterServiceName((string) $postage->MailService); + $serviceCodeMethod = $this->getCode('method_to_code', $serviceName); + $serviceCode = $serviceCodeMethod ?: (string) $postage->attributes()->CLASSID; + $serviceCodeToActualNameMap[$serviceCode] = $serviceName; + if (in_array($serviceCode, $allowedMethods)) { + $costArr[$serviceCode] = (string) $postage->Rate; + $priceArr[$serviceCode] = $this->getMethodPrice( + (float) $postage->Rate, + $serviceCode, + ); } - asort($priceArr); } - } else { // International Rates - if (is_object($xml->Package) && is_object($xml->Package->Service)) { - foreach ($xml->Package->Service as $service) { - // phpcs:ignore Ecg.Performance.Loop.ArraySize - if ($service->ServiceErrors->count()) { - continue; - } - $serviceName = $this->_filterServiceName((string) $service->SvcDescription); - $serviceCode = 'INT_' . (string) $service->attributes()->ID; - $serviceCodeToActualNameMap[$serviceCode] = $serviceName; - if (in_array($serviceCode, $allowedMethods)) { - $costArr[$serviceCode] = (string) $service->Postage; - $priceArr[$serviceCode] = $this->getMethodPrice( - (float) $service->Postage, - $serviceCode, - ); - } + asort($priceArr); + } + } else { // International Rates + if (is_object($xml->Package) && is_object($xml->Package->Service)) { + foreach ($xml->Package->Service as $service) { + // phpcs:ignore Ecg.Performance.Loop.ArraySize + if ($service->ServiceErrors->count()) { + continue; + } + $serviceName = $this->_filterServiceName((string) $service->SvcDescription); + $serviceCode = 'INT_' . (string) $service->attributes()->ID; + $serviceCodeToActualNameMap[$serviceCode] = $serviceName; + if (in_array($serviceCode, $allowedMethods)) { + $costArr[$serviceCode] = (string) $service->Postage; + $priceArr[$serviceCode] = $this->getMethodPrice( + (float) $service->Postage, + $serviceCode, + ); } - asort($priceArr); } + asort($priceArr); } } - - $result = Mage::getModel('shipping/rate_result'); - if (empty($priceArr)) { - $error = Mage::getModel('shipping/rate_result_error'); - $error->setCarrier('usps'); - $error->setCarrierTitle($this->getConfigData('title')); - $error->setErrorMessage($this->getConfigData('specificerrmsg')); - $result->append($error); - } else { - foreach ($priceArr as $method => $price) { - $rate = Mage::getModel('shipping/rate_result_method'); - $rate->setCarrier('usps'); - $rate->setCarrierTitle($this->getConfigData('title')); - $rate->setMethod($method); - $rate->setMethodTitle($serviceCodeToActualNameMap[$method] ?? $this->getCode('method', $method)); - $rate->setCost($costArr[$method]); - $rate->setPrice($price); - $result->append($rate); - } + } + $result = Mage::getModel('shipping/rate_result'); + if (empty($priceArr)) { + $error = Mage::getModel('shipping/rate_result_error'); + $error->setCarrier('usps'); + $error->setCarrierTitle($this->getConfigData('title')); + $error->setErrorMessage($this->getConfigData('specificerrmsg')); + $result->append($error); + } else { + foreach ($priceArr as $method => $price) { + $rate = Mage::getModel('shipping/rate_result_method'); + $rate->setCarrier('usps'); + $rate->setCarrierTitle($this->getConfigData('title')); + $rate->setMethod($method); + $rate->setMethodTitle($serviceCodeToActualNameMap[$method] ?? $this->getCode('method', $method)); + $rate->setCost($costArr[$method]); + $rate->setPrice($price); + $result->append($rate); } - - return $result; } + return $result; } } @@ -967,25 +962,23 @@ protected function _parseXmlTrackingResponse($trackingValue, $response) { $errorTitle = Mage::helper('usa')->__('Unable to retrieve tracking'); $resultArr = []; - if (strlen(trim($response)) > 0) { - if (str_starts_with(trim($response), 'Number) && isset($xml->Description) && (string) $xml->Description != '') { - $errorTitle = (string) $xml->Description; - } elseif (isset($xml->TrackInfo) - && isset($xml->TrackInfo->Error) - && isset($xml->TrackInfo->Error->Description) - && (string) $xml->TrackInfo->Error->Description != '' - ) { - $errorTitle = (string) $xml->TrackInfo->Error->Description; - } else { - $errorTitle = Mage::helper('usa')->__('Unknown error'); - } + if (strlen(trim($response)) > 0 && str_starts_with(trim($response), 'Number) && isset($xml->Description) && (string) $xml->Description != '') { + $errorTitle = (string) $xml->Description; + } elseif (isset($xml->TrackInfo) + && isset($xml->TrackInfo->Error) + && isset($xml->TrackInfo->Error->Description) + && (string) $xml->TrackInfo->Error->Description != '' + ) { + $errorTitle = (string) $xml->TrackInfo->Error->Description; + } else { + $errorTitle = Mage::helper('usa')->__('Unknown error'); + } - if (isset($xml->TrackInfo) && isset($xml->TrackInfo->TrackSummary)) { - $resultArr['tracksummary'] = (string) $xml->TrackInfo->TrackSummary; - } + if (isset($xml->TrackInfo) && isset($xml->TrackInfo->TrackSummary)) { + $resultArr['tracksummary'] = (string) $xml->TrackInfo->TrackSummary; } } } @@ -1019,15 +1012,13 @@ protected function _parseXmlTrackingResponse($trackingValue, $response) public function getResponse() { $statuses = ''; - if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result) { - if ($trackingData = $this->_result->getAllTrackings()) { - foreach ($trackingData as $tracking) { - if ($data = $tracking->getAllData()) { - if (!empty($data['track_summary'])) { - $statuses .= Mage::helper('usa')->__($data['track_summary']); - } else { - $statuses .= Mage::helper('usa')->__('Empty response'); - } + if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result && $trackingData = $this->_result->getAllTrackings()) { + foreach ($trackingData as $tracking) { + if ($data = $tracking->getAllData()) { + if (!empty($data['track_summary'])) { + $statuses .= Mage::helper('usa')->__($data['track_summary']); + } else { + $statuses .= Mage::helper('usa')->__('Empty response'); } } } diff --git a/app/code/core/Mage/Weee/Helper/Data.php b/app/code/core/Mage/Weee/Helper/Data.php index 2e6b54de441..9ce02ba08f8 100644 --- a/app/code/core/Mage/Weee/Helper/Data.php +++ b/app/code/core/Mage/Weee/Helper/Data.php @@ -236,17 +236,15 @@ public function getProductWeeeAttributes( */ public function getApplied($item) { - if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract) { - if ($item->getHasChildren() && $item->isChildrenCalculated()) { - $result = []; - foreach ($item->getChildren() as $child) { - $childData = $this->getApplied($child); - if (is_array($childData)) { - $result = array_merge($result, $childData); - } + if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract && ($item->getHasChildren() && $item->isChildrenCalculated())) { + $result = []; + foreach ($item->getChildren() as $child) { + $childData = $this->getApplied($child); + if (is_array($childData)) { + $result = array_merge($result, $childData); } - return $result; } + return $result; } /** diff --git a/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php b/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php index abf9b4d8496..7ed62cbcf51 100644 --- a/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php +++ b/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php @@ -288,15 +288,12 @@ protected function _processTaxSettings($item, $value, $baseValue, $rowValue, $ba ->unsPriceInclTax() ->unsBasePriceInclTax(); } - if ($this->_helper->isTaxable($this->_store) - && !$this->_helper->isTaxIncluded($this->_store) && $rowValue + if ($this->_helper->isTaxable($this->_store) && !$this->_helper->isTaxIncluded($this->_store) && $rowValue && !$this->_helper->includeInSubtotal($this->_store) ) { - if (!$this->_helper->includeInSubtotal($this->_store)) { - $item->setExtraTaxableAmount($value) - ->setBaseExtraTaxableAmount($baseValue) - ->setExtraRowTaxableAmount($rowValue) - ->setBaseExtraRowTaxableAmount($baseRowValue); - } + $item->setExtraTaxableAmount($value) + ->setBaseExtraTaxableAmount($baseValue) + ->setExtraRowTaxableAmount($rowValue) + ->setBaseExtraRowTaxableAmount($baseRowValue); } return $this; } diff --git a/app/code/core/Mage/Wishlist/Model/Item.php b/app/code/core/Mage/Wishlist/Model/Item.php index 60b2bdc21eb..2abce3b2e20 100644 --- a/app/code/core/Mage/Wishlist/Model/Item.php +++ b/app/code/core/Mage/Wishlist/Model/Item.php @@ -348,10 +348,8 @@ public function addToCart(Mage_Checkout_Model_Cart $cart, $delete = false) return false; } - if (!$product->isVisibleInSiteVisibility()) { - if ($product->getStoreId() == $storeId) { - return false; - } + if (!$product->isVisibleInSiteVisibility() && $product->getStoreId() == $storeId) { + return false; } if (!$product->isSalable()) { diff --git a/app/code/core/Mage/Wishlist/Model/Observer.php b/app/code/core/Mage/Wishlist/Model/Observer.php index d220f36a2be..54aaf12cdc5 100644 --- a/app/code/core/Mage/Wishlist/Model/Observer.php +++ b/app/code/core/Mage/Wishlist/Model/Observer.php @@ -49,19 +49,15 @@ public function processCartUpdateBefore($observer) * Collect product ids marked for move to wishlist */ foreach ($data as $itemId => $itemInfo) { - if (!empty($itemInfo['wishlist'])) { - if ($item = $cart->getQuote()->getItemById($itemId)) { - $productId = $item->getProductId(); - $buyRequest = $item->getBuyRequest(); - - if (isset($itemInfo['qty']) && is_numeric($itemInfo['qty'])) { - $buyRequest->setQty($itemInfo['qty']); - } - $wishlist->addNewItem($productId, $buyRequest); - - $productIds[] = $productId; - $cart->getQuote()->removeItem($itemId); + if (!empty($itemInfo['wishlist']) && $item = $cart->getQuote()->getItemById($itemId)) { + $productId = $item->getProductId(); + $buyRequest = $item->getBuyRequest(); + if (isset($itemInfo['qty']) && is_numeric($itemInfo['qty'])) { + $buyRequest->setQty($itemInfo['qty']); } + $wishlist->addNewItem($productId, $buyRequest); + $productIds[] = $productId; + $cart->getQuote()->removeItem($itemId); } } diff --git a/install.php b/install.php index 9a20e827407..cf852afca71 100644 --- a/install.php +++ b/install.php @@ -124,12 +124,10 @@ } // print all errors if there were any -if ($installer instanceof Mage_Install_Model_Installer_Console) { - if ($installer->getErrors()) { - echo "\nFAILED\n"; - foreach ($installer->getErrors() as $error) { - echo $error . "\n"; - } +if ($installer instanceof Mage_Install_Model_Installer_Console && $installer->getErrors()) { + echo "\nFAILED\n"; + foreach ($installer->getErrors() as $error) { + echo $error . "\n"; } } exit(1); // don't delete this as this should notify about failed installation diff --git a/lib/Mage/Cache/Backend/File.php b/lib/Mage/Cache/Backend/File.php index 3b5fbb3a957..bafc4d21668 100644 --- a/lib/Mage/Cache/Backend/File.php +++ b/lib/Mage/Cache/Backend/File.php @@ -94,10 +94,8 @@ public function __construct(array $options = []) } // Validate prefix - if (isset($this->_options['file_name_prefix'])) { - if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) { - Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]'); - } + if (isset($this->_options['file_name_prefix']) && !preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) { + Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]'); } // See #ZF-4422 @@ -165,13 +163,11 @@ public function save($data, $id, $tags = [], $specificLifetime = false) { $file = $this->_file($id); $path = $this->_path($id); - if ($this->_options['hashed_directory_level'] > 0) { + if ($this->_options['hashed_directory_level'] > 0 && !is_writable($path)) { + // maybe, we just have to build the directory structure + $this->_recursiveMkdirAndChmod($id); if (!is_writable($path)) { - // maybe, we just have to build the directory structure - $this->_recursiveMkdirAndChmod($id); - if (!is_writable($path)) { - return false; - } + return false; } } if ($this->_options['read_control']) { @@ -640,10 +636,9 @@ protected function _tagPath() $path = $this->_options['cache_dir'] . DIRECTORY_SEPARATOR . $this->_options['file_name_prefix'] . '-tags' . DIRECTORY_SEPARATOR; if (!$this->_isTagDirChecked) { - if (!is_dir($path)) { - if (@mkdir($path, $this->_options['use_chmod'] ? $this->_options['directory_mode'] : 0777) && $this->_options['use_chmod']) { - @chmod($path, $this->_options['directory_mode']); // see #ZF-320 (this line is required in some configurations) - } + if (!is_dir($path) && (@mkdir($path, $this->_options['use_chmod'] ? $this->_options['directory_mode'] : 0777) && $this->_options['use_chmod'])) { + @chmod($path, $this->_options['directory_mode']); + // see #ZF-320 (this line is required in some configurations) } $this->_isTagDirChecked = true; } diff --git a/lib/Mage/System/Ftp.php b/lib/Mage/System/Ftp.php index e64072b2f53..1b13faec41f 100644 --- a/lib/Mage/System/Ftp.php +++ b/lib/Mage/System/Ftp.php @@ -145,10 +145,8 @@ public function connect($string, $timeout = 900) } else { $this->login(); } - if (isset($params['path'])) { - if (!$this->chdir($params['path'])) { - throw new Exception("Cannot chdir after login to: {$params['path']}"); - } + if (isset($params['path']) && !$this->chdir($params['path'])) { + throw new Exception("Cannot chdir after login to: {$params['path']}"); } } diff --git a/lib/Unserialize/Reader/Arr.php b/lib/Unserialize/Reader/Arr.php index 3a099135478..5803bda115b 100644 --- a/lib/Unserialize/Reader/Arr.php +++ b/lib/Unserialize/Reader/Arr.php @@ -99,10 +99,8 @@ public function read($char, $prevChar) } } - if ($this->_status == self::FINISHED_ARR) { - if ($char == '}') { - return $this->_result; - } + if ($this->_status == self::FINISHED_ARR && $char == '}') { + return $this->_result; } } } diff --git a/lib/Unserialize/Reader/Str.php b/lib/Unserialize/Reader/Str.php index 07f23dd7893..7963d3c07a9 100644 --- a/lib/Unserialize/Reader/Str.php +++ b/lib/Unserialize/Reader/Str.php @@ -51,11 +51,9 @@ public function read($char, $prevChar) } } - if ($this->_status == self::FINISHED_LENGTH) { - if ($char == Unserialize_Parser::SYMBOL_QUOTE) { - $this->_status = self::READING_VALUE; - return null; - } + if ($this->_status == self::FINISHED_LENGTH && $char == Unserialize_Parser::SYMBOL_QUOTE) { + $this->_status = self::READING_VALUE; + return null; } if ($this->_status == self::READING_VALUE) { @@ -68,10 +66,8 @@ public function read($char, $prevChar) return null; } - if (strlen($this->_value) == $this->_length) { - if ($char == Unserialize_Parser::SYMBOL_SEMICOLON && $prevChar == Unserialize_Parser::SYMBOL_QUOTE) { - return (string) $this->_value; - } + if (strlen($this->_value) == $this->_length && ($char == Unserialize_Parser::SYMBOL_SEMICOLON && $prevChar == Unserialize_Parser::SYMBOL_QUOTE)) { + return (string) $this->_value; } } return null; diff --git a/lib/Varien/Cache/Backend/Database.php b/lib/Varien/Cache/Backend/Database.php index 864305fe311..ab42bd49415 100644 --- a/lib/Varien/Cache/Backend/Database.php +++ b/lib/Varien/Cache/Backend/Database.php @@ -58,10 +58,8 @@ class Varien_Cache_Backend_Database extends Zend_Cache_Backend implements Zend_C public function __construct($options = []) { parent::__construct($options); - if (empty($this->_options['adapter_callback'])) { - if (!($this->_options['adapter'] instanceof Zend_Db_Adapter_Abstract)) { - Zend_Cache::throwException('Option "adapter" should be declared and extend Zend_Db_Adapter_Abstract!'); - } + if (empty($this->_options['adapter_callback']) && !($this->_options['adapter'] instanceof Zend_Db_Adapter_Abstract)) { + Zend_Cache::throwException('Option "adapter" should be declared and extend Zend_Db_Adapter_Abstract!'); } if (empty($this->_options['data_table']) || empty($this->_options['tags_table'])) { Zend_Cache::throwException('Options "data_table" and "tags_table" should be declared!'); diff --git a/lib/Varien/Data/Form/Element/Date.php b/lib/Varien/Data/Form/Element/Date.php index 9e15728cdbe..56afe28b0e8 100644 --- a/lib/Varien/Data/Form/Element/Date.php +++ b/lib/Varien/Data/Form/Element/Date.php @@ -90,10 +90,8 @@ public function setValue($value, $format = null, $locale = null) } } // last check, if locale was set - if (null === $locale) { - if (!$locale = $this->getLocale()) { - $locale = null; - } + if (null === $locale && !$locale = $this->getLocale()) { + $locale = null; } try { $this->_value = new Zend_Date($value, $format, $locale); diff --git a/lib/Varien/Data/Tree/Dbp.php b/lib/Varien/Data/Tree/Dbp.php index c8947770e26..86a140aca6d 100644 --- a/lib/Varien/Data/Tree/Dbp.php +++ b/lib/Varien/Data/Tree/Dbp.php @@ -252,10 +252,8 @@ public function getChildren($node, $recursive = true, $result = []) } foreach ($node->getChildren() as $child) { - if ($recursive) { - if ($child->getChildren()) { - $result = $this->getChildren($child, $recursive, $result); - } + if ($recursive && $child->getChildren()) { + $result = $this->getChildren($child, $recursive, $result); } $result[] = $child->getId(); } diff --git a/lib/Varien/Db/Select.php b/lib/Varien/Db/Select.php index ba4b6d48b17..32a7f991667 100644 --- a/lib/Varien/Db/Select.php +++ b/lib/Varien/Db/Select.php @@ -142,13 +142,9 @@ public function resetJoinLeft() if ($tableCorrelationName == $tableId) { continue; } - if (!empty($table['joinCondition'])) { - if ($this->_findTableInCond($tableId, $table['joinCondition']) - || $this->_findTableInCond($tableProp['tableName'], $table['joinCondition']) - ) { - $useJoin = true; - $joinInTables[] = $tableCorrelationName; - } + if (!empty($table['joinCondition']) && ($this->_findTableInCond($tableId, $table['joinCondition']) || $this->_findTableInCond($tableProp['tableName'], $table['joinCondition']))) { + $useJoin = true; + $joinInTables[] = $tableCorrelationName; } } diff --git a/lib/Varien/Image/Adapter/Gd2.php b/lib/Varien/Image/Adapter/Gd2.php index 493016e4d03..e422d7964c1 100644 --- a/lib/Varien/Image/Adapter/Gd2.php +++ b/lib/Varien/Image/Adapter/Gd2.php @@ -350,11 +350,9 @@ public function resize($frameWidth = null, $frameHeight = null) $dstHeight = $frameHeight; if ($this->_keepAspectRatio) { // do not make picture bigger, than it is, if required - if ($this->_constrainOnly) { - if (($frameWidth >= $this->_imageSrcWidth) && ($frameHeight >= $this->_imageSrcHeight)) { - $dstWidth = $this->_imageSrcWidth; - $dstHeight = $this->_imageSrcHeight; - } + if ($this->_constrainOnly && ($frameWidth >= $this->_imageSrcWidth && $frameHeight >= $this->_imageSrcHeight)) { + $dstWidth = $this->_imageSrcWidth; + $dstHeight = $this->_imageSrcHeight; } // keep aspect ratio if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) { diff --git a/lib/Varien/Io/Ftp.php b/lib/Varien/Io/Ftp.php index 80e89d54d24..55e41367329 100644 --- a/lib/Varien/Io/Ftp.php +++ b/lib/Varien/Io/Ftp.php @@ -108,20 +108,16 @@ public function open(array $args = []) throw new Varien_Io_Exception('Invalid user name or password'); } - if (!empty($this->_config['path'])) { - if (!@ftp_chdir($this->_conn, $this->_config['path'])) { - $this->_error = self::ERROR_INVALID_PATH; - $this->close(); - throw new Varien_Io_Exception('Invalid path'); - } + if (!empty($this->_config['path']) && !@ftp_chdir($this->_conn, $this->_config['path'])) { + $this->_error = self::ERROR_INVALID_PATH; + $this->close(); + throw new Varien_Io_Exception('Invalid path'); } - if (!empty($this->_config['passive'])) { - if (!@ftp_pasv($this->_conn, true)) { - $this->_error = self::ERROR_INVALID_MODE; - $this->close(); - throw new Varien_Io_Exception('Invalid file transfer mode'); - } + if (!empty($this->_config['passive']) && !@ftp_pasv($this->_conn, true)) { + $this->_error = self::ERROR_INVALID_MODE; + $this->close(); + throw new Varien_Io_Exception('Invalid file transfer mode'); } return true; From 42ae3ba89e31274b94125139f312bca53a874de4 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 8 Jul 2025 03:40:20 +0200 Subject: [PATCH 2/3] baseline - shifting errors --- .phpstan.dist.baseline.neon | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.phpstan.dist.baseline.neon b/.phpstan.dist.baseline.neon index 096e0aa022c..946b2132c71 100644 --- a/.phpstan.dist.baseline.neon +++ b/.phpstan.dist.baseline.neon @@ -432,6 +432,12 @@ parameters: count: 2 path: app/code/core/Mage/Adminhtml/Block/Widget/Form.php + - + message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php + - message: '#^Parameter \#1 \$emptyLabel of method Mage_Directory_Model_Resource_Country_Collection\:\:toOptionArray\(\) expects string, false given\.$#' identifier: argument.type @@ -4935,7 +4941,7 @@ parameters: - message: '#^If condition is always false\.$#' identifier: if.alwaysFalse - count: 3 + count: 2 path: app/code/core/Mage/Tax/Helper/Data.php - @@ -4959,7 +4965,7 @@ parameters: - message: '#^Right side of && is always false\.$#' identifier: booleanAnd.rightAlwaysFalse - count: 1 + count: 2 path: app/code/core/Mage/Tax/Helper/Data.php - From 403737aaddaf535f4b453108b59c1ffbf3adaafb Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 8 Jul 2025 03:47:22 +0200 Subject: [PATCH 3/3] cs --- app/code/core/Mage/Core/Model/Layout/Update.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Model/Layout/Update.php b/app/code/core/Mage/Core/Model/Layout/Update.php index bc1afba3130..d3fcf2368b5 100644 --- a/app/code/core/Mage/Core/Model/Layout/Update.php +++ b/app/code/core/Mage/Core/Model/Layout/Update.php @@ -207,7 +207,8 @@ public function loadCache() // The cache key is just a hash of the real content to de-duplicate the often large XML strings // sha1 - if (strlen($result) === 40 && !$result = Mage::app()->loadCache(self::XML_KEY_PREFIX . $result)) { return false; + if (strlen($result) === 40 && !$result = Mage::app()->loadCache(self::XML_KEY_PREFIX . $result)) { + return false; } $this->addUpdate($result);