0

I have a problem, I am creating a custom module of rma, the module must allow to calculate the price of the shipment. Additionally I have a custom shipping module that works correctly in the purchase process but I have to calculate shipping prices in the rma module(for return product), I am trying to do this by calling a function of the shipping module but it does not execute.

The Shipping module:

app/code/xxxx/xxxx/model/carrier/shipping.php

class Shipping extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements \Magento\Shipping\Model\Carrier\CarrierInterface
{
    #...rest of class methods
    
    #function to calculate rates
     public function getShippingPrice($origenRegion,$origenCiudad, $destinoRegion, $destinoCiudad, $peso)
     {
        # ...rest of function
        $shippingPrice = $this->getFinalPriceWithHandlingFee($tasa);
                
        return $shippingPrice;
     }
    
     public function collectRates(RateRequest $request)
     {
        #...
     }
    
}

The shipping rates works fine, but when I try to use the getShippingPrice function in another section (an observer) it does not get executed.

class RmaSuccess implements ObserverInterface
{
     protected $_ShippingModel;
     public function __construct(\xxxx\xxxx\Model\Carrier\Shipping $ShippingModel){

     $this->_ShippingModel = $ShippingModel;
     }

      public function execute(\Magento\Framework\Event\Observer $observer ) { 
         #....
         CostOfRefound = $this->_ShippingModel->getShippingPrice($shippingAdressOrigin->getRegion(),
                    $shippingAdressOrigin->getCity(), $SellerRegion, $SellerCiudad,($PesoTotalSeller[$key])/1000);
         #....the function does not run

      }
}

thanks for any help.

1 Answer 1

0

Need to change this section as below

From:

CostOfRefound = $this->_ShippingHelper->getShippingPrice($shippingAdressOrigin->getRegion(),
                    $shippingAdressOrigin->getCity(), $SellerRegion, $SellerCiudad,($PesoTotalSeller[$key])/1000);

To:

CostOfRefound = $this->_ShippingModel->getShippingPrice($shippingAdressOrigin->getRegion(),
                    $shippingAdressOrigin->getCity(), $SellerRegion, $SellerCiudad,($PesoTotalSeller[$key])/1000);
1
  • Hello thanks for your answer, but that is not the case, I modified that part to place the question but in the original code they match, I already edited the question Oct 6, 2020 at 14:28

Your Answer

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

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