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

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.

  • 写回答

2条回答 默认 最新

  • dongluo1853 2013-11-28 21:31
    关注

    Finally figured it out, the following works - I must have tried 15 different variations before this worked.

    $myproduct = Mage::getModel('catalog/product')->load($productId);
    $mylength = $myproduct->getAttributeText('length');
    

    Thanks to BuzzJoe for pointing me in the right direction, I eventually used:

    Mage::Log('$productId: '.$productId, null, 'mylogfile.log');
    Mage::Log('$mylength: '.$mylength, null, 'mylogfile.log');
    

    to keep a check on things. Couldn't get var_dump to work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示