From c9e79cb9a2bfabfa7add26fe462fbb38ed294d3b Mon Sep 17 00:00:00 2001 From: Vladimir Fishchenko Date: Tue, 4 Feb 2020 13:48:11 +0000 Subject: [PATCH 1/4] Update the product model custom option methods PHPdoc --- app/code/Magento/Catalog/Model/Product.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 7015fa0295cfb..dc181f84bfc54 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -10,6 +10,7 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductLinkRepositoryInterface; use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool; +use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; use Magento\Catalog\Model\FilterProductCustomAttribute; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\App\Filesystem\DirectoryList; @@ -108,7 +109,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements /** * Product object customization (not stored in DB) * - * @var array + * @var OptionInterface[] */ protected $_customOptions = []; @@ -2062,7 +2063,7 @@ public function addCustomOption($code, $value, $product = null) /** * Sets custom options for the product * - * @param array $options Array of options + * @param OptionInterface[] $options Array of options * @return void */ public function setCustomOptions(array $options) @@ -2073,7 +2074,7 @@ public function setCustomOptions(array $options) /** * Get all custom options of the product * - * @return array + * @return OptionInterface[] */ public function getCustomOptions() { @@ -2084,14 +2085,11 @@ public function getCustomOptions() * Get product custom option info * * @param string $code - * @return array + * @return OptionInterface|null */ public function getCustomOption($code) { - if (isset($this->_customOptions[$code])) { - return $this->_customOptions[$code]; - } - return null; + return $this->_customOptions[$code] ?? null; } /** @@ -2101,11 +2099,7 @@ public function getCustomOption($code) */ public function hasCustomOptions() { - if (count($this->_customOptions)) { - return true; - } else { - return false; - } + return (bool)count($this->_customOptions); } /** From 73ba904016249b8973e31e3a524f30fdb59ac513 Mon Sep 17 00:00:00 2001 From: Vladimir Fishchenko Date: Thu, 6 Feb 2020 19:33:15 +0000 Subject: [PATCH 2/4] Fix PHPStan code validation issues in Product Model --- app/code/Magento/Catalog/Model/Product.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index dc181f84bfc54..ffc0feb015842 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -2154,7 +2154,7 @@ public function reset() */ public function getCacheIdTags() { - $tags = parent::getCacheIdTags(); + $tags = (array)$this->getData('cache_id_tags'); $affectedCategoryIds = $this->getAffectedCategoryIds(); if (!$affectedCategoryIds) { $affectedCategoryIds = $this->getCategoryIds(); @@ -2334,7 +2334,8 @@ public function isDisabled() public function getImage() { $this->getTypeInstance()->setImageFromChildProduct($this); - return parent::getImage(); + + return (string)$this->getData('image'); } /** From 42b9e3269a8b06bc431f47f788bb5e255c1600b7 Mon Sep 17 00:00:00 2001 From: Vladimir Fishchenko Date: Thu, 6 Feb 2020 22:14:27 +0000 Subject: [PATCH 3/4] Add PHPCompatibility ignore to __toArray method in Product model --- app/code/Magento/Catalog/Model/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index ffc0feb015842..ae2c2974add20 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -2404,7 +2404,7 @@ public function reloadPriceInfo() * @return array * @todo refactor with converter for AbstractExtensibleModel */ - public function __toArray() + public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames { $data = $this->_data; $hasToArray = function ($model) { From 1a3b7d0c37fa9c9e1fd8a5016f1540e95662134a Mon Sep 17 00:00:00 2001 From: Vladimir Fishchenko Date: Sat, 8 Feb 2020 01:59:21 +0000 Subject: [PATCH 4/4] Update app/code/Magento/Catalog/Model/Product.php --- app/code/Magento/Catalog/Model/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index ae2c2974add20..5643be2dd0d3c 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -2335,7 +2335,7 @@ public function getImage() { $this->getTypeInstance()->setImageFromChildProduct($this); - return (string)$this->getData('image'); + return $this->getData('image'); } /**