Hello. I'm having a problem with the Bleez Post Freight module. The version of Magento is 2.2.1. Whenever I try to simulate freight, it returns the following error:
[2018-02-27 12:40:05] main.CRITICAL: Report ID: webapi-5a9551a56b937; Message: Notice: Undefined index: product in /var/www/vhosts/xxxxx/httpdocs/app/code/Bleez/Correios/Model/Consulta.php on line 153 {"exception": "[object] (Exception (code: 0) : Report ID: webapi-5a9551a56b937; Message: Notice: Undefined index: product in /var/www/vhosts/xxxxx/httpdocs/app/code/Bleez/Correios/Model/Consulta.php on line 153 at / var / www / vhosts / xxxxx / httpdocs / vendor / magento / framework / Webapi / ErrorProcessor.php: 205, Exception (code: 0): Notice: Undefined index: product in / var / www / vhosts / xxxxx / httpdocs / app / code / Bleez /Creators/Model/Consulta.php on line 153 at /var/www/vhosts/xxxxx/httpdocs/vendor/magento/framework/App/ErrorHandler.php:61) "} []
The code snippet that causes this error is the following function:
/**
* Estima Frete de um produto
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function estimarFrete(){
$request = $this->_request->getParams();
$params = new \Magento\Framework\DataObject();
$params->setData($request);
$this->_product->load($request['product']); /*Essa seria a linha 153 que contém o erro no código*/
$this->_quote->addProduct($this->_product, $params);
$this->_quote->collectTotals();
$shipping = $this->_quote->getShippingAddress();
$shipping->setCountryId('BR');
$shipping->setPostcode($request['cep']);
$shipping->setCollectShippingRates(true);
$this->_totalsCollector->collectAddressTotals($this->_quote, $shipping);
$rates = $shipping->collectShippingRates()->getAllShippingRates();
$data = array();
if(count($rates)){
foreach ($rates as $k => $rate) {
$data[$k]['title'] = $rate->getMethodTitle();
$data[$k]['price'] = $this->_priceHelper->currency($rate->getPrice(), true, false);
}
return json_encode($data);
}else{
throw new \Exception('Não foi possivel calcular frete.');
}
}
How can I resolve this problem?