1

What is the purpose of the shipping cost, I can observe the shipping Price is always visible on the frontend calculation.

I've tried to edit the below file to verify the shipping cost. But it is not visible anywhere or not added to the shipping price it seems.

vendor/magento/module-offline-shipping/Model/Carrier/Tablerate.php

/**
 * Get the method object based on the shipping price and cost
 *
 * @param float $shippingPrice
 * @param float $cost
 * @return \Magento\Quote\Model\Quote\Address\RateResult\Method
 */
private function createShippingMethod($shippingPrice, $cost)
{
    /** @var  \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
    $method = $this->_resultMethodFactory->create();

    $method->setCarrier($this->getCarrierCode());
    $method->setCarrierTitle($this->getConfigData('title'));

    $method->setMethod('bestway');
    $method->setMethodTitle($this->getConfigData('name'));

    $shippingPrice = 50.00;
    $cost = 20.00;

    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('shippingPrice - '.$shippingPrice); 
    $logger->info('cost - '.$cost); 
    $logger->info('File '.__FILE__.':'.__LINE__);

    $method->setPrice($shippingPrice);
    $method->setCost($cost);
    return $method;
}

Frontend enter image description here

Can someone help to understand the use of shipping cost and shipping price?

Thanks in advance!

1 Answer 1

4

The cost is what the merchant pays.

The price is what the customer pays.

Magento: Magento setPrice() and setCost() methods

1
  • Thank you, please share any other ref if you find.
    – Knight017
    Nov 1, 2022 at 10:10

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.