Moncef Grey Posted October 23, 2021 Share Posted October 23, 2021 (edited) I have a task to create some styling in the shopping cart part based on the value of $product.condition.label The problem is, this variable doesn't work when i added it to themes\new\templates\checkout\_partials\cart-detailed-product-line.tpl But it work in other files such as: themes\new\templates\catalog\product.tpl How can i pass that variable $product.condition.label to cart-detailed-product-line.tpl file ? Edited October 23, 2021 by Moncef Grey Typo (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 product.tpl handles Product.php and cart-detailed-product-line.tpl handles Cart.php with the getProducts function. 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 (edited) ./classes/Cart.php Add p.`condition` to sql query. Edited October 23, 2021 by WebSoft (see edit history) 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 (edited) I added p.`condition` at the end to sql query in getProducts method like this: $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, cp.`id_customization`, pl.`name`, p.`is_virtual`, pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, m.`name` AS manufacturer_name, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`, product_shop.`available_for_order`, product_shop.`show_price`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`, p.`available_date`, p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0), IFNULL(cp.`id_customization`, 0)) AS unique_id, cp.id_address_delivery, product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, p.`condition`'); Yet when i run this code in cart-detailed-product-line.tpl file, nothing shows in the console, even i added the condition ( New ) to all the products in the cart from the BO! <script> console.log('{$product.condition.label}'); </script> Edited October 23, 2021 by Moncef Grey (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 {$product.condition} 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 1 minute ago, WebSoft said: {$product.condition} Also not displaying anything ! Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 Prestashop version ? 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 2 minutes ago, WebSoft said: Prestashop version ? 1.7.5.1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 Ok, theme is classic ? 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 Can you make a picture of where you want the condition? 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 Just now, WebSoft said: Ok, theme is classic ? No, the theme in which my files are is called new Example: themes\new\templates\checkout\_partials\cart-detailed-product-line.tpl Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 2 minutes ago, WebSoft said: Can you make a picture of where you want the condition? I want to create a flag (as shown in red color) that shows the condition label and style it with css. Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 Oh, that's different again. If you want to display it as text, it's easy. If you want to display it as a flag, you would have to create a function in Cart.php 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 I wanted to use $product.condition.label as a condition in if else statement to display a div that contains text and style it using css. Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 2 minutes ago, WebSoft said: If you want to display it as a flag, you would have to create a function in Cart.php How can i do that? i have no experience in PHP and just few in prestashop Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 8 minutes ago, Moncef Grey said: I wanted to use $product.condition.label as a condition in if else statement to display a div that contains text and style it using css. I repeat again that everything in the cart shows the Cart.php class. Product.php displays on the main page, product categories and product details page. They are two different classes. What you think the $product variable is valid everywhere is a mistake. $product is array !!! You cannot use fields from Product.php and use them in Cart.php. 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 9 minutes ago, Moncef Grey said: How can i do that? i have no experience in PHP and just few in prestashop If you want to display it as a flag, you would have to create a function in Cart.php 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 23, 2021 Author Share Posted October 23, 2021 I understand now, thank you. I appreciate you help Link to comment Share on other sites More sharing options...
ps8modules Posted October 23, 2021 Share Posted October 23, 2021 There are features for the products ./src/Adapter/Presenter/Product/ProductLazyArray.php and function getFlags(). 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 24, 2021 Share Posted October 24, 2021 UPDATE !!! Add new function to: ./classes/Cart.php public function getConditions($id_product) { $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), Context::getContext()->shop->id); $show_condition = $product->show_condition; $condition = $product->condition; if ($product->show_condition == '0') { return; } switch ($product->condition) { case 'new': return '<li class="product-flag new" style="top: 0px;margin-top: -1rem;margin-left: -1rem;">'.Context::getContext()->getTranslator()->trans('New', array(), 'Shop.Theme.Catalog').'</li>'; case 'used': return '<li class="product-flag used" style="top: 0px;margin-top: -1rem;margin-left: -1rem;">'.Context::getContext()->getTranslator()->trans('Used', array(), 'Shop.Theme.Catalog').'</li>'; break; case 'refurbished': return '<li class="product-flag refurbished" style="top: 0px;margin-top: -1rem;margin-left: -1rem;">'.Context::getContext()->getTranslator()->trans('Refurbished', array(), 'Shop.Theme.Catalog').'</li>'; break; default: return; } } Add to ./themes/classic/templates/checkout/_partials/cart-detailed-product-line.tpl (show standard conditions New, Used, Refurbished) after: <div class="product-line-grid-left col-md-3 col-xs-4"> add: <!-- block conditions --> <ul class="product-flags"> {Cart::getConditions($product.id) nofilter} </ul> <!-- end block conditions --> result: 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 24, 2021 Author Share Posted October 24, 2021 Thank you so much for you time and sorry for late answering, I was busy with some stuff. I'll try this and hopefully it will work. I appreciate it Link to comment Share on other sites More sharing options...
ps8modules Posted October 24, 2021 Share Posted October 24, 2021 4 minutes ago, Moncef Grey said: Thank you so much for you time and sorry for late answering, I was busy with some stuff. I'll try this and hopefully it will work. I appreciate it It works. I tested on Prestashop 1.7.5.1 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 24, 2021 Share Posted October 24, 2021 Add condition label to ./themes/classic/templates/checkout/_partials/cart-summary-product-line.tpl after: <a href="{$product.url}" title="{$product.name}"> <img class="media-object" src="{$product.cover.small.url}" alt="{$product.name}"> </a> add: <!-- block conditions --> <div style="display:block;position: relative;bottom: 0px;margin-left: 1.15rem;margin-top: 1rem;"> <ul class="product-flags"> {Cart::getConditions($product.id) nofilter} </ul> </div> <!-- end block conditions --> result: 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 24, 2021 Author Share Posted October 24, 2021 Woah !! It worked !!!! Thank you so so much, you won't believe how happy i am especially tomorrow is the deadline to deliver this. I really appreciate your time Link to comment Share on other sites More sharing options...
ps8modules Posted October 24, 2021 Share Posted October 24, 2021 Conditions label show only if product show_condition = 1 and condition is not null !! 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 24, 2021 Share Posted October 24, 2021 (edited) You can like my posts by clicking on the gray heart below the posts 😉 Edited October 24, 2021 by WebSoft (see edit history) 1 Link to comment Share on other sites More sharing options...
Moncef Grey Posted October 24, 2021 Author Share Posted October 24, 2021 Sure, You deserve that 1 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