futurewebs Posted November 11, 2013 Share Posted November 11, 2013 Hi, I need to display the total number of product which are currently in the shopping cart. Currently my basket just displays the total price. Here is the code im working on: <span class="top-cart"> <span class="shop-total">{l s='Items:'} <span id="summary_products_quantity">{$productNumber} {if $productNumber == 1}{l s='product'}{else}{l s='products'}{/if}</span> {l s='Basket Total:' mod='wdshoppinginfo'} <span class="ajax_cart_total{if $cart_qties == 0} tophidden{/if} price"> {if $cart_qties > 0} {if $priceDisplay == 1} {assign var='blockuser_cart_flag' value='Cart::BOTH_WITHOUT_SHIPPING'|constant} {convertPrice price=$cart->getOrderTotal(false, $blockuser_cart_flag)} {else} {assign var='blockuser_cart_flag' value='Cart::BOTH_WITHOUT_SHIPPING'|constant} {convertPrice price=$cart->getOrderTotal(true, $blockuser_cart_flag)} {/if} {/if} </span> Any help would be much appreciated! Matt Link to comment Share on other sites More sharing options...
vekia Posted November 11, 2013 Share Posted November 11, 2013 in your blockcart module template file you can use this variable {$cart_qties} Link to comment Share on other sites More sharing options...
futurewebs Posted November 12, 2013 Author Share Posted November 12, 2013 That's great, the total number of products now appears in my cart dropdown. The only problem is the total only appears when you refresh the page. I have checked to make sure Ajax is enabled in the Cart Block module which it is. If you have any ideas that would be great. Many thanks for your help! Link to comment Share on other sites More sharing options...
vekia Posted November 12, 2013 Share Posted November 12, 2013 have you changed code in blockcart.tpl file? especially class names ? Link to comment Share on other sites More sharing options...
futurewebs Posted November 12, 2013 Author Share Posted November 12, 2013 Yes I have slighty, here is my blockcart.tpl code: {if $ajax_allowed} <script type="text/javascript"> var CUSTOMIZE_TEXTFIELD = {$CUSTOMIZE_TEXTFIELD}; var img_dir = '{$img_dir}'; </script> {/if} <script type="text/javascript"> var customizationIdMessage = '{l s='Customization #' mod='blockcart' js=1}'; var removingLinkText = '{l s='remove this product from my cart' mod='blockcart' js=1}'; var freeShippingTranslation = '{l s='Free shipping!' mod='blockcart' js=1}'; var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}'; var delete_txt = '{l s='Delete' mod='blockcart'}'; var added_txt = '{l s='Added to your basket' mod='blockcart' js=1}'; var checkout_txt = '{l s='Proceed to checkout' mod='blockcart' js=1}'; var continue_txt = '{l s='Continue shopping' mod='blockcart' js=1}'; </script> <!-- MODULE Block cart --> <div id="cart_block" class="block exclusive cartView"> <p class="block-subtitle">{l s='Recently added item(s)' mod='blockcart'}</p> <h4> <a href="{$link->getPageLink("$order_process", true)}">{l s='Cart' mod='blockcart'}</a> {if $ajax_allowed} <span id="block_cart_expand" {if isset($colapseExpandStatus) && $colapseExpandStatus eq 'expanded' || !isset($colapseExpandStatus)}class="hidden"{/if}> </span> <span id="block_cart_collapse" {if isset($colapseExpandStatus) && $colapseExpandStatus eq 'collapsed'}class="hidden"{/if}> </span> {/if} </h4> <div class="top-empty"> <!-- block summary --> <div id="cart_block_summary" class="{if isset($colapseExpandStatus) && $colapseExpandStatus eq 'expanded' || !$ajax_allowed || !isset($colapseExpandStatus)}collapsed{else}expanded{/if}"> <span class="ajax_cart_quantity" {if $cart_qties <= 0}style="display:none;"{/if}>{$cart_qties}</span> <span class="ajax_cart_product_txt_s" {if $cart_qties <= 1}style="display:none"{/if}>{l s='products' mod='blockcart'}</span> <span class="ajax_cart_product_txt" {if $cart_qties > 1}style="display:none"{/if}>{l s='product' mod='blockcart'}</span> <span class="ajax_cart_total" {if $cart_qties == 0}style="display:none"{/if}> {if $cart_qties > 0} {if $priceDisplay == 1} {convertPrice price=$cart->getOrderTotal(false)} {else} {convertPrice price=$cart->getOrderTotal(true)} {/if} {/if} </span> <span class="ajax_cart_no_product" {if $cart_qties != 0}style="display:none"{/if}>{l s='(empty)' mod='blockcart'}</span> </div> <!-- block list of products --> <div id="cart_block_list" class="{if isset($colapseExpandStatus) && $colapseExpandStatus eq 'expanded' || !$ajax_allowed || !isset($colapseExpandStatus)}expanded{else}collapsed{/if}"> {if $products} <dl class="products"> {foreach from=$products item='product' name='myLoop'} {assign var='productId' value=$product.id_product} {assign var='productAttributeId' value=$product.id_product_attribute} <img width="40" src="" alt="" align="left" title="{$product.name|escape:htmlall:'UTF-8'|truncate:20}" /> <dt id="cart_block_product_{$product.id_product}_{if $product.id_product_attribute}{$product.id_product_attribute}{else}0{/if}_{if $product.id_address_delivery}{$product.id_address_delivery}{else}0{/if}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}"> <a class="product-image" title="{$product.name|escape:html:'UTF-8'}" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)}"><img width="50" height="50" alt="Star dreams capri nightsuit" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'small_default')}"></a> <span class="quantity-formated"><span class="quantity">{$product.cart_quantity}</span>x</span> <a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)}" title="{$product.name|escape:html:'UTF-8'}"> {$product.name|truncate:20:'...'|escape:html:'UTF-8'}</a> <span class="remove_link">{if !isset($customizedDatas.$productId.$productAttributeId) && ($product.total > 0)}<a rel="nofollow" class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart', true, NULL, "delete&id_product={$product.id_product}&ipa={$product.id_product_attribute}&id_address_delivery={$product.id_address_delivery}&token={$static_token}", true)}" title="{l s='remove this product from my cart' mod='blockcart'}"> </a>{/if}</span> <span class="price"> {if $product.total > 0} {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total`"}{else}{displayWtPrice p="`$product.total_wt`"}{/if} {else} <b>{l s='Free!' mod='blockcart'}</b> {/if} </span> </dt> {if isset($product.attributes_small)} <dd id="cart_block_combination_of_{$product.id_product}{if $product.id_product_attribute}_{$product.id_product_attribute}{/if}_{$product.id_address_delivery|intval}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}"> <a href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)}" title="{l s='Product detail' mod='blockcart'}">{$product.attributes_small}</a> {/if} <!-- Customizable datas --> {if isset($customizedDatas.$productId.$productAttributeId[$product.id_address_delivery])} {if !isset($product.attributes_small)}<dd id="cart_block_combination_of_{$product.id_product}_{if $product.id_product_attribute}{$product.id_product_attribute}{else}0{/if}_{if $product.id_address_delivery}{$product.id_address_delivery}{else}0{/if}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">{/if} <ul class="cart_block_customizations" id="customization_{$productId}_{$productAttributeId}"> {foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization' name='customizations'} <li name="customization"> <div class="deleteCustomizableProduct" id="deleteCustomizableProduct_{$id_customization|intval}_{$product.id_product|intval}_{$product.id_product_attribute|intval}_{$product.id_address_delivery|intval}"><a class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart', true, NULL, "delete&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_customization={$id_customization}&token={$static_token}", true)}"> </a></div> <span class="quantity-formated"><span class="quantity">{$customization.quantity}</span>x</span>{if isset($customization.datas.$CUSTOMIZE_TEXTFIELD.0)} {$customization.datas.$CUSTOMIZE_TEXTFIELD.0.value|escape:html:'UTF-8'|replace:"<br />":" "|truncate:28} {else} {l s='Customization #%d:' sprintf=$id_customization|intval mod='blockcart'} {/if} </li> {/foreach} </ul> {if !isset($product.attributes_small)}</dd>{/if} {/if} {if isset($product.attributes_small)}</dd>{/if} {/foreach} </dl> {/if} <p {if $products}class="hidden"{/if} id="cart_block_no_products">{l s='No products' mod='blockcart'}</p> {if $discounts|@count > 0} <table id="vouchers"> <tbody> {foreach from=$discounts item=discount} {if $discount.value_real > 0} <tr class="bloc_cart_voucher" id="bloc_cart_voucher_{$discount.id_discount}"> <td class="quantity">1x</td> <td class="name" title="{$discount.description}">{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}</td> <td class="price">-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}</td> <td class="delete"> {if strlen($discount.code)} <a class="delete_voucher" href="{$link->getPageLink('$order_process', true)}?deleteDiscount={$discount.id_discount}" title="{l s='Delete' mod='blockcart'}"><img src="{$img_dir}icon/delete.gif" alt="{l s='Delete' mod='blockcart'}" class="icon" /></a> {/if} </td> </tr> {/if} {/foreach} </tbody> </table> {/if} <p id="cart-prices"> <span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span> <span>{l s='Shipping' mod='blockcart'}</span> <br/> {if $show_wrapping} {assign var='cart_flag' value='Cart::ONLY_WRAPPING'|constant} <span id="cart_block_wrapping_cost" class="price cart_block_wrapping_cost">{if $priceDisplay == 1}{convertPrice price=$cart->getOrderTotal(false, $cart_flag)}{else}{convertPrice price=$cart->getOrderTotal(true, $cart_flag)}{/if}</span> <span>{l s='Wrapping' mod='blockcart'}</span> <br/> {/if} {if $show_tax && isset($tax_cost)} <span id="cart_block_tax_cost" class="price ajax_cart_tax_cost">{$tax_cost}</span> <span>{l s='Tax' mod='blockcart'}</span> <br/> {/if} <span id="cart_block_total" class="price ajax_block_cart_total">{$total}</span> <span>{l s='Total' mod='blockcart'}</span> </p> {if $use_taxes && $display_tax_label == 1 && $show_tax} {if $priceDisplay == 0} <p id="cart-price-precisions"> {l s='Prices are tax included' mod='blockcart'} </p> {/if} {if $priceDisplay == 1} <p id="cart-price-precisions"> {l s='Prices are tax excluded' mod='blockcart'} </p> {/if} {/if} <p id="cart-buttons"> <div class="actions"> <p class="view-cart"> <a href="{$link->getPageLink("$order_process.php", true)}" title="{l s='Cart' mod='blockcart'}"><span class="overstyle1">{l s='View Cart' mod='blockcart'}</span></a> </p> <button onclick="setLocation('{$link->getPageLink("$order_process.php", true)}{if $order_process == "order"}?step=1{/if}')" class="exclusive{if $order_process == 'order-opc'}_large{/if} button buttonpostion" title="{l s='Check out' mod='blockcart'}"><span><span>{l s='Check out' mod='blockcart'}</span></span></button> </div> </div> </div> </div> <!-- /MODULE Block cart --> </div> <div class="top_info"><span class="phone"> <img src="{$img_dir}/{if $sccop.trendy_theme !=''}{$sccop.trendy_theme}{else}default{/if}_phone.png" alt="" /> </span><span class="support"><span class="number">{l s='Support' mod='blockcart'} {$sccop.trendy_support_info}</span></span> </div> </div> I am using a custom module which is where the cart total appears, here is the .tpl code: <div class="row"> <!-- Block user information module HEADER --> <div class="span7"> <div class="shoppingCart"> <ul id="header_nav"> {if !$PS_CATALOG_MODE} <li id="shopping_cart"> <a href="{$link->getPageLink($order_process, true)}" title="{l s='Your Shopping Cart' mod='wdshoppinginfo'}"> <span class="cart-ico"><img src="{$img_dir}/{if $sccop.trendy_theme !=''}{$sccop.trendy_theme}{else}default{/if}_cart.png" /></span> <span class="top-cart"> <span class="shop-total"><span id="summary_products_quantity">Total Items: {$cart_qties}</span> {l s='Basket Total:' mod='wdshoppinginfo'} <span class="ajax_cart_total{if $cart_qties == 0} tophidden{/if} price"> {if $cart_qties > 0} {if $priceDisplay == 1} {assign var='blockuser_cart_flag' value='Cart::BOTH_WITHOUT_SHIPPING'|constant} {convertPrice price=$cart->getOrderTotal(false, $blockuser_cart_flag)} {else} {assign var='blockuser_cart_flag' value='Cart::BOTH_WITHOUT_SHIPPING'|constant} {convertPrice price=$cart->getOrderTotal(true, $blockuser_cart_flag)} {/if} {/if} </span> <span class="ajax_cart_no_product{if $cart_qties > 0} tophidden{/if} price"> {assign var='blockuser_cart_flag' value='Cart::BOTH_WITHOUT_SHIPPING'|constant} {convertPrice price=$cart->getOrderTotal(false, $blockuser_cart_flag)}</span> </span> </span> </a> </li> {/if} </ul> <!-- /Block user information module HEADER --> Thanks so much for your help! Link to comment Share on other sites More sharing options...
futurewebs Posted November 13, 2013 Author Share Posted November 13, 2013 Just thought I would let you know I have noticed that the product total refreshes correctly when in the checkout/basket pages but not on any of the others, im not sure whether this helps? Link to comment Share on other sites More sharing options...
neoweiter Posted March 3, 2015 Share Posted March 3, 2015 Vekia, {$cart_qties} works fine, but is there a way to exclude Packs from the count ? Link to comment Share on other sites More sharing options...
Nikhil Kumar Posted July 12, 2016 Share Posted July 12, 2016 in your blockcart module template file you can use this variable {$cart_qties} HI vekia how to get total number of PRODUCTS in cart without QUANTITIES Link to comment Share on other sites More sharing options...
vekia Posted July 12, 2016 Share Posted July 12, 2016 HI vekia how to get total number of PRODUCTS in cart without QUANTITIES you mean 1x blouse 2x dress 1x shoes 1x hat instead of 5 you want to dispaly 4 (because 4 types of product are in cart) ? Link to comment Share on other sites More sharing options...
mariloj Posted July 29, 2016 Share Posted July 29, 2016 Hello Ambassador, I need if what you say . Count the total of different products in the cart. Link to comment Share on other sites More sharing options...
mpbAAA Posted September 6, 2016 Share Posted September 6, 2016 (edited) Hello, I have the same problem. There is any way to show this data ({$products|count}) without the need to refresh the page? Thanks in advance, Marc Edited September 6, 2016 by mpbAAA (see edit history) Link to comment Share on other sites More sharing options...
Websmith Posted February 27, 2020 Share Posted February 27, 2020 (edited) @vekia This is exactly what I'm trying to do, display the number of different items in the cart instead of the total number of items. Is there a way to do this? I'm not familiar with PHP or the Prestashop core but it should be a matter of grouping tems by ID in the SQL statement or maybe looping and increasing a counter each time the ID changes. The problem is I have no idea where to put this... Edited February 27, 2020 by Websmith (see edit history) Link to comment Share on other sites More sharing options...
Ezequielb Posted May 31, 2020 Share Posted May 31, 2020 On 2/27/2020 at 8:13 AM, Websmith said: @vekia This is exactly what I'm trying to do, display the number of different items in the cart instead of the total number of items. Is there a way to do this? I'm not familiar with PHP or the Prestashop core but it should be a matter of grouping tems by ID in the SQL statement or maybe looping and increasing a counter each time the ID changes. The problem is I have no idea where to put this... the same for PS_1.7.6.5.. Any updates? Link to comment Share on other sites More sharing options...
Ezequielb Posted March 11, 2021 Share Posted March 11, 2021 On 5/30/2020 at 10:36 PM, Ezequielb said: the same for PS_1.7.6.5.. Any updates? I found the solution for PS 1.7.7. Maybe not the best solution but it works perfectly. Instead of {$cart.product_count} you need to create a counter like : {if $cart.products_count == 0} 0 {else}{foreach from=$cart.products item=product}{if $product@last}{$product@total}{/if}{/foreach}{/if} you need to add this code to ..../modules/ps_shoppingcart/ps_shoppingcart.tpl 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