lyounsiweb Posted November 26, 2023 Share Posted November 26, 2023 Help plesae Hi i am using prestashop 8.1 , i get a message this msg error Warning: Attempt to read property "id" on null in classes/Tools.php on line 1299 , so i check my code and after research i think the problem in my context declaration , this my two code : Context::getContext()->smarty->assign([ 'module_ajax_url' => $this->module_ajax_url, 'id_product' => $this->params['id_product'], 'id_shop' => $this->id_shop, ]); Thank's Link to comment Share on other sites More sharing options...
lyounsiweb Posted November 26, 2023 Author Share Posted November 26, 2023 10 minutes ago, lyounsiweb said: Help plesae Hi i am using prestashop 8.1 , i get a message this msg error Warning: Attempt to read property "id" on null in classes/Tools.php on line 1299 , so i check my code and after research i think the problem in my context declaration , this my two code : class PBSAdminProductTabGeneralController extends PBSControllerCore { protected $id_shop = 1; protected $base_url; protected $sibling; public function __construct($sibling, $params = []) { parent::__construct($sibling, $params); $this->sibling = $sibling; $this->base_url = Tools::getShopProtocol() . Tools::getShopDomain() . __PS_BASE_URI__; $product = new Product(Tools::getValue('id_product')); $this->context; if (!empty($product->id_shop_default)) { $this->id_shop = $product->id_shop_default; } else { $this->id_shop = Context::getContext()->shop->id; } } public function setMedia() { } public function render() { $id_product = Tools::getValue('id_product'); $pbs_product = new PBSProduct(); $pbs_product->getByProduct($id_product); $units = PBSUnit::getUnits(); foreach ($units as $unit) { $product_conversion_unit = PBSProductUnitConversionHelper::get($unit['id_pbs_unit'], $id_product); if (!empty($product_conversion_unit['id_pbs_product_unit_conversion'])) { $unit['checked'] = 1; } else { $unit['checked'] = 0; } } Context::getContext()->smarty->assign([ 'module_ajax_url' => $this->module_ajax_url, 'id_product' => $this->params['id_product'], 'pbs_product' => $pbs_product, 'units' => $units, ]); return $this->sibling->display($this->sibling->module_file, 'views/templates/admin/producttab/general.tpl'); } public function processForm() { $unit_conversions = Tools::getValue('unit_conversions'); $id_product = (int) Tools::getValue('id_product'); $pbs_product = new PBSProduct(); $pbs_product->getByProduct($id_product); $pbs_product->id_product = (int) $id_product; $pbs_product->id_pbs_unit_default = (int) Tools::getValue('id_pbs_unit_default'); $pbs_product->enabled = (int) Tools::getValue('enabled'); $pbs_product->min_price = (float) Tools::getValue('min_price'); $pbs_product->min_total_area = (float) Tools::getValue('min_total_area'); $pbs_product->setup_fee = (float) Tools::getValue('setup_fee'); $pbs_product->attribute_price_as_area_price = (int) Tools::getValue('attribute_price_as_area_price'); $pbs_product->front_conversion_enabled = (int) Tools::getValue('front_conversion_enabled'); $pbs_product->front_conversion_operator = pSQL(Tools::getValue('front_conversion_operator')); $pbs_product->front_conversion_value = (float) Tools::getValue('front_conversion_value'); if (!empty($unit_conversions)) { $pbs_product->front_conversion_enabled = 0; } $pbs_product->save(); // Save unit conversion options PBSProductUnitConversionHelper::deleteByProduct($id_product); if (!empty($unit_conversions)) { foreach ($unit_conversions as $id_pbs_unit) { $pbs_product_unit_conversion_model = new PBSProductUnitConversion(); $pbs_product_unit_conversion_model->id_product = (int) $id_product; $pbs_product_unit_conversion_model->id_pbs_unit = (int) $id_pbs_unit; $pbs_product_unit_conversion_model->save(); } } } public function route() { $return = ''; switch (Tools::getValue('action')) { case 'processform': exit($this->processForm()); default: return $this->render(); } } } 10 minutes ago, lyounsiweb said: Help plesae Hi i am using prestashop 8.1 , i get a message this msg error Warning: Attempt to read property "id" on null in classes/Tools.php on line 1299 , so i check my code and after research i think the problem in my context declaration , this my two code : Context::getContext()->smarty->assign([ 'module_ajax_url' => $this->module_ajax_url, 'id_product' => $this->params['id_product'], 'id_shop' => $this->id_shop, ]); Thank's Thank's Link to comment Share on other sites More sharing options...
AddWeb Solution Posted January 9 Share Posted January 9 Hi, In your code, I see a potential issue with the way you're trying to access the id_product value in the context. In the render method, you're trying to access it using $this->params['id_product'], but you're not defining params anywhere in your class. In context declaration use below $id_product = (int) Tools::getValue('id_product'); ... ... Context::getContext()->smarty->assign([ 'module_ajax_url' => $this->module_ajax_url, 'id_product' => $id_product, // Use Tools::getValue to get id_product //... ]); Let me know if it helps! Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now