1

I try to recieve additional data to my custom shipping method.

I get some info from checkout page and put it in my custom object quote.pickPoint.

Then, I add it to shipping-save-processor:

payload = {
    addressInformation: {
        shipping_address: quote.shippingAddress(),
        billing_address: quote.billingAddress(),
        shipping_method_code: quote.shippingMethod().method_code,
        shipping_carrier_code: quote.shippingMethod().carrier_code
    },
    pickPoint: quote.pickPoint()
};

In my custom shipping method I try to get additional info:

$rawReq = json_decode(file_get_contents('php://input'), true);

And then $rawReq contains correct array with my data

Array
(
    [addressInformation] => Array
        (
            [shipping_address] => Array
                (
                    [countryId] => RU
                    [region] => Russian Federation
                    [street] => Array
                        (
                        )

                    [telephone] => +79161234567
                    [postcode] => 
                    [city] => Moscow
                    [firstname] => Pavel
                    [lastname] => Shi
                )

            [billing_address] => Array
                (
                    [countryId] => RU
                    [region] => Russian Federation
                    [street] => Array
                        (
                        )

                    [telephone] => +79161234567
                    [postcode] => 
                    [city] => Moscow
                    [firstname] => Pavel
                    [lastname] => Shi
                    [saveInAddressBook] => 
                )

            [shipping_method_code] => svyaznoy
            [shipping_carrier_code] => svyaznoy
        )

    [pickPoint] => Array
        (
            [city] => Москва
            [region] => Москва г
            [address] => 105120 Золоторожский Вал ул 42
            [deliveryCost1] => 149
            [deliveryCost2] => 158
            [deliveryCost3] => 167
            [deliveryCost4] => 176
            [deliveryCost5] => 176
            [deliveryCost6] => 176
            [deliveryCost7] => 176
            [deliveryCost8] => 176
            [hash] => 691C7765E7B8EB872246B667E3617141
            [hash8] => 12A8F948EFCEEE375836B37705674CC2
            [hash16] => 1C307A3D17989B48487DF19563111DE1
            [name] => Площадь Ильича
            [returnCost1] => 238.4
            [returnCost2] => 238.4
            [returnCost3] => 238.4
            [returnCost4] => 238.4
            [returnCost5] => 238.4
            [returnCost6] => 238.4
            [returnCost7] => 238.4
            [returnCost8] => 238.4
            [shopId] => MD34
            [deliveryOperatorId] => 1
            [deliveryOperator] => Евросеть
        )

)

BUT!

When I try to set price and cost, its not working.

This code working:

$amount = 0;
$amount = 1;

$method->setPrice($amount);
$method->setCost($amount);

But this code not working:

$amount = 0;
if (isset $rawReq['pickPoint']) {
    $amount = 123;
}
$method->setPrice($amount);
$method->setCost($amount);

Shipping method always return 0 price.

Why?

Thanks beforehand!

1 Answer 1

1

Okay, I found the answer. Its because I was add my data to payload in saveShippingInformation function. But for shipping rates we need to use getRates instead.

getRates returns data BEFORE saveShippingInformation starts, so we have empty data when getRates works. But saveShippingInformation get rate for selected delivery method, so we have right shipping rate in totals and 0 in shipping method.

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.