我正在編寫一個自定義模塊,用戶可以輸入每件產品的運輸成本。Magento自定義變量問題
我已將一個自定義變量添加到所有名爲'initial_shipping_charge'的產品中。在我的運輸費率函數中,我試圖循環訪問我的購物籃中的產品並獲取變量(這些將被添加到總計中)。
var_dump($ shipping_price_initial);行返回NULL,而不是它包含的變量 - 任何想法,爲什麼這不起作用?
在此先感謝。
protected function _getStandardShippingRate()
{
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
/**
* getConfigData(config_key) returns the configuration value for the
* carriers/[carrier_code]/[config_key]
*/
$shipping_price_value = rand(10 , 50);
//Create a basket session object
$session = Mage::getSingleton('checkout/session');
foreach ($session->getQuote()->getAllItems() as $item) {
$item_id = $item->getId();
$_basketProduct = Mage::getModel('catalog/product')->load($item_id);
$shipping_price_initial = $_basketProduct->getAttribute('initial_shipping_charge');
var_dump($shipping_price_initial);
}
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('standand');
$rate->setMethodTitle('Standard');
$rate->setPrice($shipping_price_value);
$rate->setCost(0);
return $rate;
}
如果你' Mage :: log($ _ basketProduct-> getData())'加載產品後(並明顯啓用系統日誌),你能看到正確的值嗎? –