如何在发送到 fedex magento 之前更改重量?
How to change the weight before sending to fedex magento?
在 magento 结帐页面中,在提供账单信息和运输信息后,我了解到这些详细信息正在发送给联邦快递,然后运费会在结帐页面中填充,在将这些详细信息发送给联邦快递之前,我想更改重量的产品,我想为每个产品添加额外的重量,
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.
不确定您到底想要什么,但我会试一试。
我认为您可以在本地池和本地方法中覆盖 Mage_Checkout_OnepageController::savePaymentAction 方法,调度您自己的新事件 'save_payment_action_before' 并将您的对象作为参数传递。
在您的 fedex 模块中,创建一个观察者,获取您的对象并在将其发送到 fedex 之前更改订单重量。
要创建自定义事件,请选中 this post
最后我发现它发生在 sales/quote/item.php 文件中,有一个名为 setProduct 的函数,这里我们需要在设置数据时添加额外的信息。
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;
}
在 magento 结帐页面中,在提供账单信息和运输信息后,我了解到这些详细信息正在发送给联邦快递,然后运费会在结帐页面中填充,在将这些详细信息发送给联邦快递之前,我想更改重量的产品,我想为每个产品添加额外的重量,
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.
不确定您到底想要什么,但我会试一试。
我认为您可以在本地池和本地方法中覆盖 Mage_Checkout_OnepageController::savePaymentAction 方法,调度您自己的新事件 'save_payment_action_before' 并将您的对象作为参数传递。
在您的 fedex 模块中,创建一个观察者,获取您的对象并在将其发送到 fedex 之前更改订单重量。
要创建自定义事件,请选中 this post
最后我发现它发生在 sales/quote/item.php 文件中,有一个名为 setProduct 的函数,这里我们需要在设置数据时添加额外的信息。
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;
}