0

What I'm trying to achieve

During the checkout, if the customer has a Bike item in their basket, we want the shipping cost to be added as a product option to the cart item as opposed to being added to the cart. This is because for Bike items the client wants the customer to ONLY pay £99 as a deposit, without having to pay the, e.g. £120 dispatch fee; they want the dispatch fee to be added to the Bike's options.

What we've done

I've created a plugin for Magento\Checkout\Model\ShippingInformationManagement::saveAddressInformation (RichardPK\DeliveryCharge\Plugin\Checkout\Model\ShippingInformationManagement::afterSaveAddressInformation) where I'm listening for the shipping method "tablerate_bestway" and, if the basket has a Bike item in it, am setting the shipping information to "0.00" then, for each item, finding each Bike item in the basket, adding the Additional Option "Delivery Fee" and the shipping amount. These values are being saved to the database and I can see the values being updated. I'm also able to see the values being updated in the JSON being returned to the /rest/abtesting/V1/guest-carts/<cart-id>/shipping-information request BUT the sidebar summary block details are not being updated, i.e. the shipping amount still shows £120 and the cart item's options do not include the shipping fee.

What do I need to change in order to achieve what I'm trying to do?

1 Answer 1

0

You need to create mixin in any applicable place and reload summary block

You can add mixin to Magento_Checkout/js/model/shipping-save-processor

You can update summary with following logic

define([
    'Magento_Checkout/js/action/get-totals'
    // ...
], function(
    summary
    // ...
) {
    // any place where you want to reload order summary
    summary([]);
});

You can find mixin example in How to hook into shipping step address save Magento 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.