Search code examples
magentoeventsmagento-1.9observersfedex

How to change the weight before sending to fedex magento?


In magento checkout page, after giving billing information and shipping information, i understand that these details are sending to fedex then the shipping rates are populating in chekout page, before sending theses details to fedex, i want to change the weight of the product, i Want to add additional weights for each products,

suppose user adding a product with weight of 2 pounds, i want to send these weight to 2*5 = 10pounds, how can i do that in magento? please help.


Solution

  • Finally i find out that it is happening in the sales/quote/item.php file, there is a function called setProduct, here we need to add addititonal info while setting data.

    public function setProduct($product)
        {
    
            $batchQty = Mage::getModel('catalog/product')->load($product->getId())->getBatchQty();
            $roleId     = Mage::getSingleton('customer/session')->getCustomerGroupId();
            $userrole   = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
            $userrole   = strtolower($userrole);
            if ($this->getQuote()) {
                $product->setStoreId($this->getQuote()->getStoreId());
                $product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
            }
            if($userrole=="retailer" && $batchQty>0 ){
                $this->setData('product', $product)
                ->setProductId($product->getId())
                ->setProductType($product->getTypeId())
                ->setSku($this->getProduct()->getSku())
                ->setName($product->getName())
                ->setWeight($this->getProduct()->getWeight()*$batchQty)
                ->setTaxClassId($product->getTaxClassId())
                ->setBaseCost($product->getCost())
                ->setIsRecurring($product->getIsRecurring());
            } else {
                $this->setData('product', $product)
                ->setProductId($product->getId())
                ->setProductType($product->getTypeId())
                ->setSku($this->getProduct()->getSku())
                ->setName($product->getName())
                ->setWeight($this->getProduct()->getWeight())
                ->setTaxClassId($product->getTaxClassId())
                ->setBaseCost($product->getCost())
                ->setIsRecurring($product->getIsRecurring());
            }
    
            if ($product->getStockItem()) {
                $this->setIsQtyDecimal($product->getStockItem()->getIsQtyDecimal());
            }
    
            Mage::dispatchEvent('sales_quote_item_set_product', array(
                'product' => $product,
                'quote_item' => $this
            ));
            return $this;
        }