Jump to content

How to show weight of product in your shopping cart.


hdp2101

Recommended Posts

Hello all my lovely friends
 
   If anybody is interested about how to show product weight in his shopping cart then this is a useful code for him. Please note that before changing code to this files I advise to him to take backup of all files mentioned below. Also I am not responsible for any changes or any mashup happened in site but any way this works for me so I put in our community.
 
   To make our theme batter may be user will modified the code in mentioned files. So due to changes in all this files may be you will find the code in some other lines. So don't worry for that (This is a normal course to work).
 
   Also i am attaching the modified files. But if you done any previous changes in that files then don't copy straight away or else your previous changes will be disappear.Then also if you are copy willing to copy all this files then remove the last word from file-name. (Ex blockcart.php.modified is file name then remove modified word)
 
   For safer side i am attaching all the images of below file as result how it will look in file after pasting or replacing. Also the final result of site how the design was before and after. And last but very important i am attaching the original files also in-case if you forget to take backup of that files. Just change the last word from file-name (Ex blockcart.php.original is file name then remove original word) and copy back to his place again.
 
   Once again I am not responsible for any changes or any mashup happened in site but any way this works for me so I put in our community.

Original file name

   shopping-cart.tpl              in ../themes/your theme name/
   blockcart-json.tpl             in ../themes/your theme name/modules/blockcart/
   blockcart.php                  in ../modules/blockcart/
   ajax-cart.js                   in ../themes/your theme name/js/modules/blockcart/
   shopping-cart-product-line.tpl in ../themes/your theme name/
   order-payment-classic.tpl      in ../themes/your theme name/

   Please go through following steps carefully.

   All the best
shopping-cart.tpl in ../themes/your theme name/

Paste this following code :

<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight'}</span></td>
<td colspan="3" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>
</tr>

Above this line

</tfoot>
blockcart-json.tpl in ../themes/your theme name/modules/blockcart

Paste this following code :

"totalWeight": {$total_weight|json_encode},

Below this line :

"shippingCost": {$shipping_cost|json_encode},
blockcart.php in ../modules/blockcart

Paste this following code :

$totalWeight = $params['cart']->getTotalWeight().' '.Configuration::get('PS_WEIGHT_UNIT');

Below this line :

$totalToPay = $params['cart']->getOrderTotal($useTax);
******************************************************************************************
Again

Paste this following code :

'total_weight' => $totalWeight

Below this line :

'free_shipping' => $total_free_shipping

please add , at the end of line 'free_shipping' => $total_free_shipping
Result will be as follow.

'free_shipping' => $total_free_shipping,
ajax-cart.js in ../themes/your theme name/js/modules/blockcart/

Paste this following code :

$('.ajax_block_cart_weight').text(jsonData.totalWeight);

Below this line :

$('.ajax_total_price_wt').text(jsonData.total_price_wt);
shopping-cart.tpl in ../themes/your theme name/

Paste this following code :

<th class="cart_weight item">{l s='Weight'}</th>

Below this line :

<th class="cart_description item">{l s='Description'}</th>
**********************************************************
Again

Find this line :

<td class="cart_discount_name" colspan="{if $PS_STOCK_MANAGEMENT}3{else}2{/if}">{$discount.name}</td>

and replace with this line : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td class="cart_discount_name" colspan="{if $PS_STOCK_MANAGEMENT}4{else}3{/if}">{$discount.name}</td>

Please note about above changes in line number is depand on your theme (this change is for default theme of PS 1.6.1.0 default-bootstrap theme)
so please change all line one by one (update value in each line then save and the check in your browserand according to design change the value)
shopping-cart-product-line.tpl in ../themes/your theme name/

Paste this following code :

<td class="cart_weight">{if $product.weight}{$product.weight|number_format:3|escape:'htmlall':'UTF-8'} {Configuration::get('PS_WEIGHT_UNIT')}{/if}</td>

Below this line :

{if isset($product.attributes) && $product.attributes}<small><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html':'UTF-8'}">{$product.attributes|@replace: $smarty.capture.sep:$smarty.capture.default|escape:'html':'UTF-8'}</a></small>{/if}
order-payment-classic.tpl in ../themes/your theme name/

Paste this following code :

<th class="cart_weight item">{l s='Weight'}</th>

Below this line :

<th class="cart_description item">{l s='Description'}</th>
**********************************************************
Again

Due to modification in design one need to change following line in order-payment-classic.tpl in ../themes/your theme name/

Please change in this all line number (49,54,60,75,90,97,102,108,124,141,146,151,158,191,198) following code
You just need to change following number only (rest everything will intact)

In above each line you can find following code :

<td colspan="2"

Just replace following code with the above one

<td colspan="3"
***************************************************************************************************************************
Again

Please change in this all line number (48,53,59,64,89,96,101,107,113,140,145,150,197) following code
You just need to change following number only (rest everything will intact)

In above each line you can find following code :

<td colspan="4"

Just replace following code with the above one

<td colspan="6"

             48,53,59,64,   89,96,101,107,113,    140,145,150,        197
(Line Number 49,54,60,   75,90,97,102,108,    124,141,146,151,158,191,198 The code will be approx 2 to 3 line up or down, Depends of your theme)
             
Please note about above changes in line number is depend on your theme (this change is for default theme of PS 1.6.1.0 default-bootstrap theme)
so please change all line one by one (update value in each line then save and the check in your browser and according to design change the value)
*************************************************************************************************************************************************
Again

Find this line :

<td class="cart_discount_name" colspan="{if $PS_STOCK_MANAGEMENT}3{else}2{/if}">{$discount.name}</td>

and replace with this line : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td class="cart_discount_name" colspan="{if $PS_STOCK_MANAGEMENT}4{else}3{/if}">{$discount.name}</td>

Please note about above changes in line number is depend on your theme (this change is for default theme of PS 1.6.1.0 default-bootstrap theme)
so please change all line one by one (update value in each line then save and the check in your browserand according to design change the value)
*******************************************************************************************************************************************************
Again

Paste this following code :

<tr class="cart_total_price">
<td colspan="6" class="text-right"><span>{l s='Total weight'}</span></td>
<td colspan="5" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>
</tr>

Above this line

</tfoot>
shopping-cart.tpl in ../themes/your theme name/

Find this line :

<td colspan="{$col_span_subtotal}" class="text-right">{if $display_tax_label}{l s='Total products (tax excl.)'}{else}{l s='Total products'}{/if}</td>

and replace with this line : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="{$col_span_subtotal}" class="text-right">{if $display_tax_label}{l s='Total products (tax excl.)'}{else}{l s='Net amount of total products (Before discount)'}{/if}</td>
*************************************************************************************************************************************************************************************
Again

Find this line :

<td colspan="{$col_span_subtotal}" class="text-right">{if $display_tax_label}{l s='Total products (tax incl.)'}{else}{l s='Total products'}{/if}</td>

and replace with this line : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="{$col_span_subtotal}" class="text-right">{if $display_tax_label}{l s='Total products (tax incl.)'}{else}{l s='Net amount of total products (Before discount)'}{/if}</td>
*************************************************************************************************************************************************************************************
Again

Find this code :

{if $use_taxes}
	{if $display_tax_label}{l s='Total gift wrapping (tax incl.)'}{else}{l s='Total gift-wrapping cost'}{/if}
{else}
	{l s='Total gift-wrapping cost'}
{/if}

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

{if $use_taxes}
	{if $display_tax_label}{l s='Total gift wrapping (tax incl.)'}{else}{l s='Gift-wrapping charges'}{/if}
{else}
	{l s='Gift-wrapping charges'}
{/if}
*******************************************************************************************************************************************************
Again

Find this code :

<td colspan="{$col_span_subtotal}" class="text-right">{l s='Total shipping'}</td>   Same line 1st

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="{$col_span_subtotal}" class="text-right">{l s='Shipping charges'}</td>

Find this code :

<td colspan="{$col_span_subtotal}" class="text-right">{l s='Total shipping'}</td>  same line 2nd

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="{$col_span_subtotal}" class="text-right">{l s='Shipping charges'}</td>
*******************************************************************************************************************************************************
Again

Find this code :

{l s='Total vouchers'}

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

{l s='Total amount of discount for applied vouchers'}
*******************************************************************************************************************************************************
Again

Find this code :

<span>{l s='Total'}</span>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<span>{l s='Final Total'}</span>
*******************************************************************************************************************************************************
Again

Find this code :

<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight'}</span></td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight of all products'}</span></td>
order-payment-classic.tpl in ../themes/your theme name/

Find this code :

<td colspan="4" class="text-right">{if $display_tax_label}{l s='Total products (tax excl.)'}{else}{l s='Total products'}{/if}</td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="text-right">{if $display_tax_label}{l s='Total products (tax excl.)'}{else}{l s='Net amount of total products (Before discount)'}{/if}</td>
******************************************************************************************************************************************************************
Again

Find this code :

<td colspan="4" class="text-right">{if $display_tax_label}{l s='Total products (tax incl.)'}{else}{l s='Total products'}{/if}</td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="text-right">{if $display_tax_label}{l s='Total products (tax incl.)'}{else}{l s='Net amount of total products (Before discount)'}{/if}</td>
******************************************************************************************************************************************************************
Again

Find this code :

{if $use_taxes}
    {if $priceDisplay}
        {if $display_tax_label}{l s='Total gift wrapping (tax excl.):'}{else}{l s='Total gift wrapping cost:'}{/if}
    {else}
        {if $display_tax_label}{l s='Total gift wrapping (tax incl.)'}{else}{l s='Total gift wrapping cost:'}{/if}
    {/if}
{else}
    {l s='Total gift wrapping cost:'}
{/if}

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

{if $use_taxes}
    {if $priceDisplay}
        {if $display_tax_label}{l s='Total gift wrapping (tax excl.):'}{else}{l s='Gift-wrapping charges'}{/if}
    {else}
        {if $display_tax_label}{l s='Total gift wrapping (tax incl.)'}{else}{l s='Gift-wrapping charges'}{/if}
    {/if}
{else}
    {l s='Gift-wrapping charges'}
{/if}
*******************************************************************************************************************************************************
Again

Find this code :

<td colspan="4" class="text-right">{l s='Total shipping'}</td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="text-right">{l s='Shipping charges'}</td>
*******************************************************************************************************************************************************
Again

Find this code :

<td colspan="4" class="text-right">{l s='Total shipping'}</td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="text-right">{l s='Shipping charges'}</td>
*******************************************************************************************************************************************************
Again

Find this code :

{if $use_taxes}
    {if $priceDisplay}
        {if $display_tax_label}{l s='Total vouchers (tax excl.)'}{else}{l s='Total vouchers'}{/if}
    {else}
        {if $display_tax_label}{l s='Total vouchers (tax incl.)'}{else}{l s='Total vouchers'}{/if}
    {/if}
{else}
    {l s='Total vouchers'}
{/if}

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

{if $use_taxes}
    {if $priceDisplay}
        {if $display_tax_label}{l s='Total amount of discount for applied vouchers (tax excl.)'}{else}{l s='Total amount of discount for applied vouchers'}{/if}
    {else}
        {if $display_tax_label}{l s='Total amount of discount for applied vouchers (tax incl.)'}{else}{l s='Total amount of discount for applied vouchers'}{/if}
    {/if}
{else}
    {l s='Total amount of discount for applied vouchers'}
{/if}
****************************************************************************************************************************************************************
Again

Find this code :

<td colspan="4" class="total_price_container text-right"><span>{l s='Total'}</span></td>

and replace with this code :  (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="total_price_container text-right"><span>{l s='Final Total'}</span></td>
********************************************************************************************************************************************************
Again

Find this code :

<td colspan="4" class="text-right"><span>{l s='Total weight'}</span></td>

and replace with this code : (due to title change may be you can't find the complete code then try to find the title words which is at and of the code)

<td colspan="6" class="text-right"><span>{l s='Total weight of all products'}</span></td>
Now please see the images
 
post-480835-0-46738400-1436866052_thumb.png post-480835-0-22604300-1436866316_thumb.png
 
post-480835-0-05929100-1436866353_thumb.png post-480835-0-96259700-1436866396_thumb.png
 
post-480835-0-76692700-1436866441_thumb.png post-480835-0-86426000-1436866480_thumb.png
 
post-480835-0-33528000-1436866519_thumb.png post-480835-0-70334500-1436866557_thumb.png
 
post-480835-0-25565300-1436866604_thumb.png post-480835-0-45633000-1436866645_thumb.png
 
post-480835-0-58124800-1436866683_thumb.png post-480835-0-15015900-1436866920_thumb.png
 
post-480835-0-48683000-1436866965_thumb.png post-480835-0-15201700-1436867006_thumb.png
 
post-480835-0-73812500-1436867045_thumb.png post-480835-0-42105700-1436867084_thumb.png
 
post-480835-0-56838100-1436867128_thumb.png post-480835-0-04641600-1436867167_thumb.png
 
post-480835-0-03776600-1436867219_thumb.png post-480835-0-21747000-1436867259_thumb.png
 
post-480835-0-87290600-1436867299_thumb.png post-480835-0-81926500-1436867421_thumb.png
 
post-480835-0-62530900-1436867459_thumb.png post-480835-0-96120800-1436867500_thumb.png
 
post-480835-0-93367000-1436867527_thumb.png
 
Finally the end comes. I hope you guys had done great job.
 
Thank you
Hemal Parikh
 
 
 
 
 
 
 
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Did you deleted the browser cache and smarty cache ? Are you using advancedeucompliance module ?

 

For me seems the instruction is something complicated. On my own page I have not more than one file changed and is less code and it is working as well. Please let me know if caches are deleted and you are using the module I wrote before. I will instruct you how to add the weight on cart.

Link to comment
Share on other sites

Change of code PS 1.5. and PS 1.6. WITHOUT advancedeucompliance module:

 

Change with editor (notepad++) your file /themes/YOUR THEME/shopping-cart.tpl, if you are using native theme it is - /themes/default-bootstrap/shopping-cart.tpl
as follows:

 

Search for the block </foot>

Just a line BEFORE this block add the following code:

<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>
{l s='Total cart weight'}
</span></td>
<td colspan="2" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3}
{Configuration::get('PS_WEIGHT_UNIT')}
</span></td>
</tr>

Change of code for Prestashop 1.5. and 1.6 using advancedeucompliance module:

 

Change with editor (notepad++) your file /themes/YOUR THEME/shoppping-cart-advanced.tpl, if you are using native theme it is /themes/default-bootstrap/shoppping-cart-advanced.tplas follows:

 

Search for the block </foot>

Just a line BEFORE this block add the following code:

<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>
{l s='Total cart weight'}
</span></td>
<td colspan="2" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3}
{Configuration::get('PS_WEIGHT_UNIT')}
</span></td>
</tr>

After changes made, delete your browser cache, cookie sessions and also the smarty cache.

Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...