Jump to:

2076 Posts in 857 Topics by 449 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » [SOLVED] Delivery Price Modifier based on Cart Quantity

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 402 Views
  • SnowBoarder82
    Avatar
    Community Member
    52 Posts

    [SOLVED] Delivery Price Modifier based on Cart Quantity Link to this post

    Hey guys,

    I am looking to set up a delivery modifier that will adjust the pricing based on the following:

    Domestic Shipping (within NZ) will be $7.50 for up to 3 items, and the same for any additional items ordered,
    for example 1-3 items: $7.50, 4-6 items: $15.00, 7-9 items: $22.50 and so on.

    International Shipping will be $15.00 per item flat rate.

    Any thoughts on the best way to go about this?

    I have started by setting the default rate to $15.00 and then will be looking to adjust the SimpleShippingModifier. My thoughts are to create a formula in here based on the number of items in the cart but being a bit of a newb i'm not sure of the best way to get / reference this variable in the modifier?

    Any clues?

    Thank you,

  • SnowBoarder82
    Avatar
    Community Member
    52 Posts

    Re: [SOLVED] Delivery Price Modifier based on Cart Quantity Link to this post

    Solved. So managed to figure this out and have achieved the desired result by adjusting SimpleShippingModifier.php as below:

    [line 63]

    function LiveAmount() {
          
          //Get the Current Order
          $o = ShoppingCart::current_order();
          $total = $o->SubTotal();
          $orderItems = $o->Items();
           // Calculate the total quantity of the order
          if($orderItems){
             foreach($orderItems as $orderItem){
             $totalQuantity += $orderItem->Quantity;
             }
          }
             
          if ($this->LiveCountry() == "NZ"){
             
             $postage = $totalQuantity / 3;
             $postage = ceil($postage);
              $postage = 7.50 * $postage;
              return $postage;
          }
          
          else {
             $postage = $totalQuantity * 15;
             return $postage;
          }      

          //return $this->LiveIsDefaultCharge() ? self::$default_charge : self::$charges_by_country[$this->LiveCountry()];
          
       }

    Cheers,

    402 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.