sanctusmob Posted May 16, 2019 Share Posted May 16, 2019 I have create a new variable ($show_discount) overriding product class. Product.php class override <?php Class Product extends ProductCore { public $show_discount = 1; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { self::$definition['fields']['show_discount'] = array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'size' => 1); parent::__construct($id_product, $full, $id_lang, $id_shop, $context); } } ?> and i am changing the value from the controller (override). The variable exists in product page (var dump), but does not exists in product listing (category, new product, search etc.) Can anyone help? Link to comment Share on other sites More sharing options...
MigrationPro Posted May 16, 2019 Share Posted May 16, 2019 Hi, You need to access the variable on tpl for display it in the product page. you can modify tpl files in root\themes\your_theme\templates\catalog directory for modifying display products Link to comment Share on other sites More sharing options...
sanctusmob Posted May 16, 2019 Author Share Posted May 16, 2019 33 minutes ago, Migration Pro said: Hi, You need to access the variable on tpl for display it in the product page. you can modify tpl files in root\themes\your_theme\templates\catalog directory for modifying display products In product page the variable $show_discount exists and working properly. I have edit the tpl and i have access to the variable from the product page. But not from product listing pages (category, search, new products etc.). When i var dump $product in listing pages the variable $show_discount does not exists. Link to comment Share on other sites More sharing options...
MigrationPro Posted May 16, 2019 Share Posted May 16, 2019 did you check to modify root\themes\your_theme\templates\catalog\_partials\miniatures\product.tpl ? Link to comment Share on other sites More sharing options...
sanctusmob Posted May 16, 2019 Author Share Posted May 16, 2019 4 minutes ago, Migration Pro said: did you check to modify root\themes\your_theme\templates\catalog\_partials\miniatures\product.tpl ? Yes. Link to comment Share on other sites More sharing options...
MigrationPro Posted May 16, 2019 Share Posted May 16, 2019 in this case, you need to contact the theme developer and ask them about the issue, you have faced. Link to comment Share on other sites More sharing options...
sanctusmob Posted May 17, 2019 Author Share Posted May 17, 2019 There is nothing to do with the theme. Has as say when I var dump $product in listing products the $product.show_discount does not exists. In product page the $product.show_discount exists and working as normal. I think my problem is in some controller. Maybe is stripping unnecessary variables for the listing products. Link to comment Share on other sites More sharing options...
JSilva Posted November 11, 2019 Share Posted November 11, 2019 sanctusmob did you solve it? Link to comment Share on other sites More sharing options...
sanctusmob Posted November 11, 2019 Author Share Posted November 11, 2019 14 minutes ago, JSilva said: sanctusmob did you solve it? Nop. Link to comment Share on other sites More sharing options...
djnick Posted May 8, 2020 Share Posted May 8, 2020 Did you find solution for this issue? I have same problem... Link to comment Share on other sites More sharing options...
sooly Posted June 2, 2020 Share Posted June 2, 2020 bump. having same problem. Link to comment Share on other sites More sharing options...
sanctusmob Posted June 2, 2020 Author Share Posted June 2, 2020 My guess is that in product listing does not assign all the variables from product class to smarty. The project i was using that is obsolete for me... Check also here. Link to comment Share on other sites More sharing options...
shaunwhl1991 Posted August 25, 2021 Share Posted August 25, 2021 I know this is an old thread. But in case if anyone's looking for answer for the 'smarty not carrying the assigned variables' problem, here are my fixes. Override /controllers/front/listing/CategoryController.php Then you can attach your variables in the 'initContent()' function. <?php class CategoryController extends CategoryControllerCore { public function initContent() { parent::initContent(); if ($this->category->checkAccess($this->context->customer->id)) { $this->doProductSearch( 'catalog/listing/category', [ 'entity' => 'category', 'id' => $this->category->id, ] ); } $this->context->smarty->assign([ 'custom_variable' => 'some custom values...', ]); } } 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