cancel
Showing results for 
Search instead for 
Did you mean: 

Shipping error product screen

Highlighted
New Member

Shipping error product screen

On the product screen I have the freight calculation and I have created free shipping rules, how to adptar the current function for that same check of the rule and I get free shipping freight when it is free shipping?

 

private function getShippingEstimate ( $_product, $postcode, $productQty, $countryId = "BR" ) {

    $quote = Mage::getModel('sales/quote')->setStoreId(1);

    $_product->getStockItem()->setUseConfigManageStock(false);
    $_product->getStockItem()->setManageStock(false);

    $quote->addProduct($_product, $productQty);
    $quote->getShippingAddress()->setCountryId($countryId)->setPostcode($postcode); 
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->getShippingAddress()->collectShippingRates();

    $quote->setCustomerGroupId(0);
    $quote->setCouponCode('');

    $_rates = $quote->getShippingAddress()->getAllShippingRates();

    $shippingRates = array();

    foreach ($_rates as $_rate):
      if ($_rate->getMethodTitle() != "") {
        $quote->getShippingAddress()->setShippingMethod($_rate->getCode())->setCollectShippingRates(false);
        $quote->collectTotals();
        $discount = $quote->getShippingAddress()->getDiscountAmount() * -1;
        $shippingRates[] =  array("title" => $_rate->getMethodTitle(), "price" => ($_rate->getPrice()-$discount));
      }
    endforeach;

    // set postcode in cart quote.
    $this->_setCartPostCode($postcode);

    return $shippingRates;
  }