【问题标题】:Get Custom Product Information Value获取自定义产品信息值
【发布时间】:2013-10-11 12:43:53
【问题描述】:

我的 magento 商店中有亚马逊导入脚本。并且每个产品在产品信息中都有“亚马逊进口产品”(Near General、Prices、Meta Information、Images...)。

我试图使用 PHP 获得的内容位于“亚马逊进口产品”和“亚马逊产品 URL”的值

这是我按 SKU 选择产品的代码:

$sku = $id;
$_product=Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); 
$amazonlink = 

有人可以帮忙吗?我在网上唯一能找到的是如何获取产品名称或图像等,而不是如何获取自定义属性?对速度也很敏感,所以我想通过名称来获取它,而不是遍历所有属性

【问题讨论】:

    标签: magento


    【解决方案1】:

    试试

    $sku = $id;
    $_product=Mage::getModel('catalog/product')->load($sku, 'sku'); 
    $amazonlink = $_product->getData('custom_attributes_code_here');
    // or 
    $amazonlink = $_product->getCustomAttributesCodeHere();
    

    【讨论】:

    • 我试过$amazonlink = $_product->getData('Amazon_Product_URL');$_product->getAmazonProductUrl();都没有工作
    • 试试 print_r($_product->getData());,你看到 amazon 产品 url 是不是数组键 'amazon_product_url'?
    • 只有这个Array
    • 如果您得到一个空数组,则该产品不存在。试试 print_r($id);和 print_r($_product->getId());结果是有效的 sku 和产品 ID 吗?
    • 存在但没有库存代码错误,因为$short = $_product->getShortDescription(); 工作正常
    【解决方案2】:

    以下是获取自定义属性值的最安全方法。

    $attribute = $_product->getResource()->getAttribute('custom_attribute_code');
    if ($attribute)
    {
        echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
    }
    

    上面的代码在我的博文中有解释

    Getting custom attribute value in Magento

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-09
      • 2011-09-02
      • 2016-11-23
      • 2012-10-28
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多