Skip to content

Magento 2 Shipping carrier Shipping Cost Vs Shipping Price

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 MagentoQuoteModelQuoteAddressRateResultMethod
 */
private function createShippingMethod($shippingPrice, $cost)
{
    /** @var  MagentoQuoteModelQuoteAddressRateResultMethod $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 ZendLogWriterStream(BP . '/var/log/custom.log');
    $logger = new ZendLogLogger();
    $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!