Skip to content

Commit

Permalink
Do not use $customization_required property
Browse files Browse the repository at this point in the history
Do not populate dynamic property $product->customization_required.

Fixes PHP8.2 dynamic property warnings
getdatakick committed Dec 17, 2022
1 parent a996d21 commit 949b4cb
Showing 2 changed files with 26 additions and 10 deletions.
23 changes: 22 additions & 1 deletion classes/Product.php
Original file line number Diff line number Diff line change
@@ -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;
}

}
13 changes: 4 additions & 9 deletions controllers/front/ProductController.php
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit 949b4cb

Please sign in to comment.