From 949b4cbe814b409cc93fc180af23c120beecd85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hu=C4=8D=C3=ADk?= Date: Sat, 17 Dec 2022 08:42:26 +0100 Subject: [PATCH] Do not use $customization_required property Do not populate dynamic property $product->customization_required. Fixes PHP8.2 dynamic property warnings --- classes/Product.php | 23 ++++++++++++++++++++++- controllers/front/ProductController.php | 13 ++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index 18a91297da..1e21fe5ab8 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -6649,7 +6649,7 @@ protected function _deleteOldLabels() * @param int|bool $idLang * @param int|null $idShop * - * @return array|bool|PDOStatement + * @return array|bool * * @throws PrestaShopDatabaseException * @throws PrestaShopException @@ -8250,4 +8250,25 @@ public function getDefaultShopId() return $shopId; } + /** + * Returns true, if customization is required for a product + * + * @return bool + * + * @throws PrestaShopDatabaseException + * @throws PrestaShopException + */ + public function isCustomizationRequired() + { + if ($this->customizable) { + return (bool)Db::getInstance()->getValue((new DbQuery) + ->select('1') + ->from('customization_field', 'cf') + ->where('cf.id_product = '.(int)$this->id) + ->where('cf.`required`') + ); + } + return false; + } + } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 2968378563..8bcb7b65c0 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -267,15 +267,9 @@ public function initContent() ] ); - $this->product->customization_required = false; - $customizationFields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false; - if (is_array($customizationFields)) { - foreach ($customizationFields as $customizationField) { - if ($this->product->customization_required = $customizationField['required']) { - break; - } - } - } + $customizationFields = $this->product->customizable + ? $this->product->getCustomizationFields($this->context->language->id) + : false; // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); @@ -312,6 +306,7 @@ public function initContent() $this->context->smarty->assign( [ 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), + 'customizationRequired' => $this->product->isCustomizationRequired(), 'customizationFields' => $customizationFields, 'id_customization' => empty($customizationDatas) ? null : $customizationDatas[0]['id_customization'], 'accessories' => $accessories,