Laravelshoppingcart: Shipping/ Delivery Charge

Created on 18 May 2018  Â·  8Comments  Â·  Source: Crinsane/LaravelShoppingcart

I need to add Shipping/ Delivery charge with the cart. I checked the doc and issues listed here but did not find and solution to accommodate that. There are option field to add more information about the item but how can i add the Shipping/ Delivery charge with the total and show the amount to the user when needed?

All 8 comments

@nasirkhan maybe something like:

Cart::total() + $ShippingDeliveryCharge;

@abr4xas
I add shipping cost in Show Cart Page.
$ShippingDeliveryCharge = 50;
echo 'à§³'.$value = Cart::total()+ $ShippingDeliveryCharge;
It show error A non well formed numeric value encountered .

Then probably the $ShippingDeliveryCharge variable holds the price that ‘s not a numeric value. I suggest to convert it before counting by floatval() function. That should solve the problem. So $totalPrice = Cart::total() + floatval($ShippingDeliveryCharge);

Total, taxes and shipping will be isolated data.

@Nazmulhaqued
Hello,
For this, you have to remove comma (,) from cart total value

Our total will in this format 15,000 so we have to remove comma (,) from a value

Please try this
str_replace(",","",Cart::total()) + $ShippingDeliveryCharge;

Hope this will help you :)

@ankitabhatti05
The package and the total method already use number format, there is no need to use str_replace.
Notice: A non well formed numeric value encountered in is provoked by the thousand seperator as you have pointed out already. But there is no need to str_replace the total as Cart total is already using number_format internally.

https://github.com/Crinsane/LaravelShoppingcart/blob/7ff157b7e1ef10d27cd2759d5151aae2cc6b1b9a/src/Cart.php#L245

https://github.com/Crinsane/LaravelShoppingcart/blob/7ff157b7e1ef10d27cd2759d5151aae2cc6b1b9a/src/Cart.php#L534

http://php.net/manual/de/function.number-format.php

Cart::total( 2, '.', '' ); + $shippingDeliveryCharge

Should return '15000' in your example. But keep in mind that it will omit decimal values if it is a even number. you can wrap it in an additional number_format to force trailing zeros to display.

@AlterwebStudio && @ankitabhatti05 Both of Your Answer is not working, shows error. A non well formed numeric value encountered (View: F:\xampp\htdocs\ecommerce_office\resources\views\pages\show_cart.blade.php)

@ankitabhatti05 I can add delivery charge echo '$'.$value = str_replace(",","",Cart::total())+50.00; it work
but when i echo $cart::total(); it don't show the delivery charge.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hasanali05 picture hasanali05  Â·  6Comments

shakhawatfci picture shakhawatfci  Â·  10Comments

abdullahkaamil picture abdullahkaamil  Â·  3Comments

wasid picture wasid  Â·  8Comments

matbeard picture matbeard  Â·  7Comments