Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 加载Magento属性';实际价值_Php_Magento_Attributes_Product_Magento 1.9.1 - Fatal编程技术网

Php 加载Magento属性';实际价值

Php 加载Magento属性';实际价值,php,magento,attributes,product,magento-1.9.1,Php,Magento,Attributes,Product,Magento 1.9.1,我需要从magento商店中拥有属性的所有产品中读取属性(有些可能由于属性集不同而没有),对其进行处理(regex/replace等),然后将新计算的值保存在同一产品的不同属性中。 $value = $product->getAttributeText($attribute_code); 例如,加载产品A,识别它确实具有属性X。加载X的前端值“9000”,将其乘以2,并将18000保存在产品A的属性Y中 在我通过这里的一些帖子之后,我想出了这段代码。它允许我列出我们商店中一些产品的属性I

我需要从magento商店中拥有属性的所有产品中读取属性(有些可能由于属性集不同而没有),对其进行处理(regex/replace等),然后将新计算的值保存在同一产品的不同属性中。

$value = $product->getAttributeText($attribute_code);
例如,加载产品A,识别它确实具有属性X。加载X的前端值“9000”,将其乘以2,并将18000保存在产品A的属性Y中

在我通过这里的一些帖子之后,我想出了这段代码。它允许我列出我们商店中一些产品的属性ID(这里是制造商)

问题:这只是制造商的ID,而不是他们的实际名称(我需要实际名称)。我怎样才能得到这些。我在另一篇帖子中找到了这个片段:

$product = Mage::getModel('catalog/product')->load($_product->getEntityId());
$product->setData('add_ten_pence', 1)->getResource()->saveAttribute($product, 'add_ten_pence');
基本上我需要它的“getData版本”。由于某些原因,下面的行不起作用。

$value = $product->getAttributeText($attribute_code);
非常感谢您对此事的任何意见。我要查找的属性值是前端类型“dropdown”(如果有任何更改)。

$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;
}
?>
umask(0);
Mage::app('default');
Mage::app()->setCurrentStore(Mage\u Core\u Model\u app::ADMIN\u STORE\u ID);
$productCollection=Mage::getModel('catalog/product')->getCollection();
$i=0;
$storeId=1;
foreach($productCollection作为$\u产品)
{
回显“更新SKU:”.$\u产品->getSku()。“\tID:”.$\u产品->getEntityId()。”;
$manufacturer=Mage::getResourceModel('catalog/product')->getAttributeRawValue($\u product->getEntityId(),'manufacturer',$storeId);
echo“\t制造商:.$制造商。”
”; $i++;//(尽早调试中断循环以减少加载时间) 如果($i>10)中断; } ?>
试试看,因为集合没有选择特定属性,请在管理员中检查集合中是否有属性筛选器

$product=Mage::getModel('catalog/product')->load($id);

$product->getData($attribute_code);

关于
$product->getAttributeText(…)
的部分应该可以工作,它通常可以非常可靠地工作。请记住,当前存储设置为“admin”,因此将使用这些选项标签,而不是任何前端存储。再次检查
$attribute\u code
是否正确。谢谢。我再次查看了getAttributeText并使其正常工作。我目前正在取得进展,将在这里发布我的代码。我应该在问题解决后编辑它,还是将其作为答案发布?如果问题解决了,那么它就是答案。