UltraCart / rest_api_v2_sdk_php

UltraCart REST API PHP Client
Apache License 2.0
3 stars 4 forks source link

Set Second Shipping method as default one #10

Closed chadhakavita closed 6 years ago

chadhakavita commented 6 years ago

Hi,

How I can set second shipping method as a default one or how I can change the shipping method in my code.

Code:

if ($cart->getSettings() != null && $cart->getSettings()->getShipping() != null) {
    $shippingSettings = $cart->getSettings()->getShipping();
    $estimates = $shippingSettings->getEstimates();
    if ($estimates != null && count($estimates) > 0) {
        $cart->getShipping()->setShippingMethod($estimates[0]->getName());
    }
}
perrytew commented 6 years ago

The code example above is setting the shipping method to the first shipping estimate.
To set the shipping method to the second one, just use

$estimates[1]->getName()

I feel like I'm missing what you're trying to accomplish. Can you elaborate more on what you're trying to do? You also mention in a support case this:

How I can set second shipping method as a default one or how I can change the shipping method in my code. Right now, it's picking the least cost shipping method but I want to make the shipping method dynamic whatever the customers choose the shipping method from the drop-down.

If you're needing a drop down, then just loop through the $estimates array and populate a drop down. When the user chooses a value or submits a value, assign that value to $cart->getShipping()->setShippingMethod($chosenValue)

chadhakavita commented 6 years ago

Hi Perry,

I have one dropdown from where the customer will select the shipping method. Right now, I'm using only 2 shipping method i.e FedEx: Standard Overnight and FedEx: 2-Day. And given the fixed shipping fixed for the specific product. For more clarification please have a look at the screenshot: https://prnt.sc/j7p8c8

And I've given the discount coupons as well with different shipping method. And I've taken the shipping method from the drop-down using: $cart->getShipping()->setShippingMethod($dropdown-select-shipping-method);

But when I select FedEx: Standard Overnight Shipping method the item is inserted in Ultracart with shipping method as FedEx: Standard Overnight which is perfect but it's not calculating shipping/Handing.

Shipping method: FedEx: 2-Day (Working Fine):

https://prnt.sc/j7pbsf

Shipping Method: FedEx: Standard Overnight (Incorrect with shipping/Handing - should be $2.00 after applying the coupon on shipping method)

https://prnt.sc/j7pcl4

perrytew commented 6 years ago

chadhakavita,

When you set the shipping method, you should also set the shipping cost. We leave that to you to make things fast. Calculating shipping costs is the most time intensive part of the checkout. So we only do it to provide estimates as needed. But if we calculated the costs every time the cart was updated, it would take a long, long time.

So you should put in the cost. The only reason it's there is so the customer knows how much it is. When the cart is finalized, we calculate the shipping cost again and use that value. That prevents any customer with programming knowledge from playing with the shipping cost.

By doing so, we yield a very fast and very accurate checkout.

chadhakavita commented 6 years ago

Thanks Perry.