【发布时间】:2014-09-09 15:02:19
【问题描述】:
我需要从拥有它的magento商店中的所有产品中读取一个属性(有些可能由于属性集不同而没有它),用它做一些事情(正则表达式/替换等),然后保存新的同一产品的不同属性中的计算值。
例如,加载产品A,识别出它确实有属性X。加载X的前端值“9000”,将其乘以2,将18000保存在产品A的属性Y中。
在这里完成了一些帖子之后,我想出了这段代码。它允许我列出我们商店中几个产品的属性 ID(这里是制造商)。
问题:这只是制造商的 ID,而不是他们的实际名称(我需要实际名称)。我怎么得到那些。我在另一篇文章中发现了这个 sn-p:
$product = Mage::getModel('catalog/product')->load($_product->getEntityId());
$product->setData('add_ten_pence', 1)->getResource()->saveAttribute($product, 'add_ten_pence');
基本上我需要它的“getData-version”。由于某种原因,以下行不起作用。
$value = $product->getAttributeText($attribute_code);
非常感谢您对此事的任何意见。我正在寻找的属性值是前端类型的“下拉”,如果有任何改变的话。
到目前为止我的代码:
umask(0);
Mage::app('default');
Mage::app ()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$productCollection = Mage::getModel('catalog/product')->getCollection();
$i = 0;
$storeId = 1;
foreach($productCollection as $_product)
{
echo "Updating SKU:".$_product->getSku()."\tID:".$_product->getEntityId()." ";
$manufacturer = Mage::getResourceModel('catalog/product')->getAttributeRawValue($_product->getEntityId(), 'manufacturer', $storeId);
echo "\tManufacturer: ".$manufacturer."<br>";
$i++; //(DEBUG break loop early to reduce loading time)
if($i>10) break;
}
?>
【问题讨论】:
-
关于
$product->getAttributeText(...)的部分应该可以工作,它通常可以非常可靠地工作。请记住,当前商店设置为“管理员”,因此将使用这些选项标签,而不是任何前台商店。仔细检查$attribute_code是否正确。 -
谢谢。我再次查看了 getAttributeText 并让它工作。我目前正在取得进展,并将在此处发布我的代码。我应该在问题解决后编辑我的问题还是应该将其发布为答案?
-
如果解决了,那就是答案。
标签: php magento attributes product magento-1.9.1