dongzong7467
2013-11-26 09:59
浏览 64
已采纳

Magento在Stock.php中获取产品属性文本

I've been trying to adjust the amount stock reduced by a sale, depending on a product's attribute, I've tried the following methods, but seem to be getting nowhere.

Magento Version: 1.8.0.0

File: /app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php

Around line 158 after: foreach ($productQtys as $productId => $qty)

I have added the following code:

$CheckLength = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('length');
if ( $CheckLength == 'Per Half Metre' )
{
    $qty = $qty / 2;
}

and also tried this:

$myproduct = Mage::getModel('catalog/product');

if ($myproduct->getAttributeText('length')=='per Half Metre')
{
    $qty = $qty / 2;
}

and this:

$storeId = Mage::app()->getStore()->getId(); // return current store id
$CheckLength = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'length', $storeId);

if ( $CheckLength == 'Per Half Metre' )
{
    $qty = $qty / 2;
}

None of the above seem to work. Without the check, the qty divides by 2 quite nicely as I need, but I only need it to do it if the Product Attribute is "Per Half Metre".

PS: This attribute is in a drop down with 2 other options.

Hope someone can help! Thanks in Advance.

图片转代码服务由CSDN问答提供 功能建议

我一直在努力调整销售减少的库存量,具体取决于产品的属性,我是 尝试了以下方法,但似乎无处可去。

Magento版本:1.8.0.0

文件:/ app / code / core / Mage /CatalogInventory/Model/Resource/Stock.php

nn

在第158行之后:foreach($ productQtys as $ productId => $ qty)

我添加了以下代码:

  $ CheckLength = Mage :: getModel('catalog / product') - > load($ _ item ['product_id']) - &gt  ; getData('length'); 
if($ CheckLength =='每半米')
 {
 $ qty = $ qty / 2; 
} 
   
 \  n 

并尝试了这个:

  $ myproduct = Mage :: getModel('catalog / product'); 
 
if($ myproduct-> getAttributeText(  'length')=='每半米')
 {
 $ qty = $ qty / 2; 
} 
   
 
 

并且:

  $ storeId = Mage :: app() - > getStore() - > getId();  //返回当前商店ID 
 $ CheckLength = Mage :: getResourceModel('catalog / product') - > getAttributeRawValue($ productId,'length',$ storeId); 
 
if($ CheckLength =='每半 Meter')
 {
 $ qty = $ qty / 2; 
} 
   
 
 

上述所有内容似乎都不起作用。 如果没有检查,qty会根据需要很好地除以2,但如果产品属性是“每半米”,我只需要它就可以做到。

PS:这个属性是 用另外两个选项下拉。

希望有人可以提供帮助! 在此先感谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题