From bd2e04d37c50bd74a7be78429547f104ccc77c75 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 4 May 2022 09:39:56 -0400 Subject: [PATCH 1/2] Fix multiple issues with object _hasDataChanges flag being set to true when there are no material changes to data. Fixes #1306 --- app/code/core/Mage/Catalog/Model/Product.php | 34 +++++++++++++++++-- app/code/core/Mage/Customer/Model/Address.php | 4 ++- .../Sales/Model/Order/Creditmemo/Item.php | 4 ++- .../Mage/Sales/Model/Order/Invoice/Item.php | 4 ++- app/code/core/Mage/Sales/Model/Order/Item.php | 4 ++- .../Mage/Sales/Model/Order/Shipment/Item.php | 4 ++- app/code/core/Mage/Sales/Model/Quote.php | 4 ++- .../core/Mage/Sales/Model/Quote/Address.php | 4 ++- app/code/core/Mage/Sales/Model/Quote/Item.php | 4 ++- .../Mage/Sales/Model/Quote/Item/Option.php | 8 +++-- .../core/Mage/Sales/Model/Quote/Payment.php | 4 ++- .../core/Mage/Wishlist/Model/Item/Option.php | 9 +++-- 12 files changed, 71 insertions(+), 16 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Product.php b/app/code/core/Mage/Catalog/Model/Product.php index 5dd0a324793..176f82028e9 100644 --- a/app/code/core/Mage/Catalog/Model/Product.php +++ b/app/code/core/Mage/Catalog/Model/Product.php @@ -223,9 +223,6 @@ * @method $this setStoreId(int $store) * @method bool hasStoreIds() * @method $this setStoreIds(array $storeIds) - * @method Mage_CatalogInventory_Model_Stock_Item getStockItem() - * @method bool hasStockItem() - * @method $this setStockItem(Mage_CatalogInventory_Model_Stock_Item $value) * @method array getSwatchPrices() * * @method int getTaxClassId() @@ -344,6 +341,11 @@ class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract */ protected $_calculatePrice = true; + /** + * @var Mage_CatalogInventory_Model_Stock_Item + */ + protected $_stockItem; + /** * Initialize resources */ @@ -694,6 +696,32 @@ public function getAttributes($groupId = null, $skipSuper = false) return $attributes; } + /** + * @return Mage_CatalogInventory_Model_Stock_Item + */ + public function getStockItem() + { + return $this->_stockItem; + } + + /** + * @return bool + */ + public function hasStockItem() + { + return !!$this->_stockItem; + } + + /** + * @param Mage_CatalogInventory_Model_Stock_Item $stockItem + * @return $this + */ + public function setStockItem(Mage_CatalogInventory_Model_Stock_Item $stockItem) + { + $this->_stockItem = $stockItem; + return $this; + } + /** * Check product options and type options and save them, too * diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index 27bd1931f59..caa5116d480 100644 --- a/app/code/core/Mage/Customer/Model/Address.php +++ b/app/code/core/Mage/Customer/Model/Address.php @@ -97,7 +97,9 @@ public function getCustomer() public function setCustomer(Mage_Customer_Model_Customer $customer) { $this->_customer = $customer; - $this->setCustomerId($customer->getId()); + if ($this->getCustomerId() != $customer->getId()) { + $this->setCustomerId($customer->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php index bbc742f5927..7cae8b9405c 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php @@ -176,7 +176,9 @@ public function getCreditmemo() public function setOrderItem(Mage_Sales_Model_Order_Item $item) { $this->_orderItem = $item; - $this->setOrderItemId($item->getId()); + if ($this->getOrderItemId() != $item->getId()) { + $this->setOrderItemId($item->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php index aea4acc56fa..f931beaa9a4 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php @@ -159,7 +159,9 @@ public function getInvoice() public function setOrderItem(Mage_Sales_Model_Order_Item $item) { $this->_orderItem = $item; - $this->setOrderItemId($item->getId()); + if ($this->getOrderItemId() != $item->getId()) { + $this->setOrderItemId($item->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Item.php b/app/code/core/Mage/Sales/Model/Order/Item.php index 94f58b74a43..33627c6aa90 100644 --- a/app/code/core/Mage/Sales/Model/Order/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Item.php @@ -440,7 +440,9 @@ public function getQtyToCancelBundleItem() public function setOrder(Mage_Sales_Model_Order $order) { $this->_order = $order; - $this->setOrderId($order->getId()); + if ($this->getOrderId() != $order->getId()) { + $this->setOrderId($order->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php index 3a1e8a6440d..7c6fc5c3c81 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php @@ -104,7 +104,9 @@ public function getShipment() public function setOrderItem(Mage_Sales_Model_Order_Item $item) { $this->_orderItem = $item; - $this->setOrderItemId($item->getId()); + if ($this->getOrderItemId() != $item->getId()) { + $this->setOrderItemId($item->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote.php b/app/code/core/Mage/Sales/Model/Quote.php index b399ae13319..55ce1a5acb1 100644 --- a/app/code/core/Mage/Sales/Model/Quote.php +++ b/app/code/core/Mage/Sales/Model/Quote.php @@ -297,7 +297,9 @@ public function getStore() */ public function setStore(Mage_Core_Model_Store $store) { - $this->setStoreId($store->getId()); + if ($this->getStoreId() != $store->getId()) { + $this->setStoreId($store->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote/Address.php b/app/code/core/Mage/Sales/Model/Quote/Address.php index afe743c0557..d8e7bf741c2 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address.php @@ -427,7 +427,9 @@ protected function _afterSave() public function setQuote(Mage_Sales_Model_Quote $quote) { $this->_quote = $quote; - $this->setQuoteId($quote->getId()); + if ($this->getQuoteId() != $quote->getId()) { + $this->setQuoteId($quote->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote/Item.php b/app/code/core/Mage/Sales/Model/Quote/Item.php index 939812da7f2..72b19e1bbb3 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item.php @@ -275,7 +275,9 @@ protected function _beforeSave() public function setQuote(Mage_Sales_Model_Quote $quote) { $this->_quote = $quote; - $this->setQuoteId($quote->getId()); + if ($this->getQuoteId() != $quote->getId()) { + $this->setQuoteId($quote->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote/Item/Option.php b/app/code/core/Mage/Sales/Model/Quote/Item/Option.php index b88a5070602..dc22cd48b5a 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item/Option.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item/Option.php @@ -83,8 +83,10 @@ protected function _hasModelChanged() */ public function setItem($item) { - $this->setItemId($item->getId()); $this->_item = $item; + if ($this->getItemId() != $item->getId()) { + $this->setItemId($item->getId()); + } return $this; } @@ -106,8 +108,10 @@ public function getItem() */ public function setProduct($product) { - $this->setProductId($product->getId()); $this->_product = $product; + if ($this->getProductId() != $product->getId()) { + $this->setProductId($product->getId()); + } return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote/Payment.php b/app/code/core/Mage/Sales/Model/Quote/Payment.php index 2e730a1af22..f68b907d6e1 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Payment.php +++ b/app/code/core/Mage/Sales/Model/Quote/Payment.php @@ -119,7 +119,9 @@ protected function _construct() public function setQuote(Mage_Sales_Model_Quote $quote) { $this->_quote = $quote; - $this->setQuoteId($quote->getId()); + if ($this->getQuoteId() != $quote->getId()) { + $this->setQuoteId($quote->getId()); + } return $this; } diff --git a/app/code/core/Mage/Wishlist/Model/Item/Option.php b/app/code/core/Mage/Wishlist/Model/Item/Option.php index 71ff069e0d8..36327058b8c 100644 --- a/app/code/core/Mage/Wishlist/Model/Item/Option.php +++ b/app/code/core/Mage/Wishlist/Model/Item/Option.php @@ -36,6 +36,7 @@ * @method int getProductId() * @method $this setProductId(int $value) * @method $this setWishlistItemId(int $value) + * @method int getWishlistItemId() * @method $this setValue(string $sBuyRequest) */ class Mage_Wishlist_Model_Item_Option extends Mage_Core_Model_Abstract implements Mage_Catalog_Model_Product_Configuration_Item_Option_Interface @@ -73,8 +74,10 @@ protected function _hasModelChanged() */ public function setItem($item) { - $this->setWishlistItemId($item->getId()); $this->_item = $item; + if ($this->getWishlistItemId() != $item->getId()) { + $this->setWishlistItemId($item->getId()); + } return $this; } @@ -96,8 +99,10 @@ public function getItem() */ public function setProduct($product) { - $this->setProductId($product->getId()); $this->_product = $product; + if ($this->getProductId() != $product->getId()) { + $this->setProductId($product->getId()); + } return $this; } From f1d78072d6c5c61488c82921df67c30500e138a8 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 8 Jun 2022 23:22:59 -0400 Subject: [PATCH 2/2] Add note to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 64289e5e601..3930bf0cd22 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Do not use 20.x.x if you need IE support. - fixed incorrect datetime in customer block (`$useTimezone` parameter) #1525 - add redis as a valid option for `global/session_save` #1513 - possibility to disable global search in backend #1532 +- reduce needless saves by avoiding setting `_hasDataChanges` flag #2066 For full list of changes, you can [compare tags](https://github.com/OpenMage/magento-lts/compare/1.9.4.x...20.0).