我的产品具有影响重量的可变尺寸,我需要将重量逻辑放入购物车以更准确地计算运费。我已将app/code/core/Mage/Sales/Model/Quote/Item.php的副本移至本地代码池。我已经能够获取相关产品的基本重量,但是,在更新购物车之前,我无法获得自定义选项(文本字段)的值来进行数学计算。我在公共职能setProduct
中这样做。这是我到目前为止有:Magento购物车在型号/报价/ Item.php中获取自定义选项(文本字段)值
public function setProduct($product)
{
if ($this->getQuote()) {
$product->setStoreId($this->getQuote()->getStoreId());
$product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
}
//Get the Weight per UOM
$sku = $product->getSku();
$item = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$wpuom = $item->getResource()->getAttribute('weight_per_uom')->getFrontend()->getValue($item);
//Get the Length
$params = Mage::app()->getRequest()->getParams();
/** @var Mage_Catalog_Model_Product $product */
$info = new Varien_Object($params);
// Don't throw an exception if required options are missing
$processMode = Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_LITE;
$options = array();
foreach ($product->getOptions() as $option) {
/* @var $option Mage_Catalog_Model_Product_Option */
$group = $option->groupFactory($option->getType())
->setOption($option)
->setProduct($product)
->setRequest($info)
->setProcessMode($processMode)
->validateUserValue($info->getOptions());
$optionValue = $info->getData('options/' . $option->getId());
$options[] = array(
'label' => $option->getTitle(),
'value' => $group->getFormattedOptionValue($optionValue),
'value2' => $option->getValues(),
'option_id' => $option->getId(),
'option_type' => $option->getType()
);
//<<<This is Where I Cannot Get the Value for the Custom Option>>>
if($options[0]['label'] == 'Length') {
//print_r($options[0]['value']);
}
}
//Update Weight
$baseWeight = $item->getWeight();
$uom = $item->getResource()->getAttribute('uom')->getFrontend()->getValue($item);
if((($uom == 'Meters') && ($length >= 76)) || (($uom == 'Feet') && ($length >= 250))) { $spoolWeight = 3; }
else { $spoolWeight = 0; }
$finalWeight = ($baseWeight + ($length * $wpuom) + $spoolWeight);
$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;
}
,当我尝试添加print_r($options[0]);
,我得到的一切,除了值,它甚至不是一个数组。我为了获得价值而错过了什么?
一些附注:产品是可配置的,版本是Magento 1.9.1 CE – NotJay