Php 通过magento中的某些ID范围获取产品集合
我想根据当前价格的特定百分比更新所有产品价格Php 通过magento中的某些ID范围获取产品集合,php,magento,Php,Magento,我想根据当前价格的特定百分比更新所有产品价格 $products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('price'); foreach ($products as $product) { $product->setPrice($product->getPrice() * 1.03); $product->save(); echo $pro
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('price');
foreach ($products as $product) {
$product->setPrice($product->getPrice() * 1.03);
$product->save();
echo $product->getId()."updated Sucess";
}
它工作得很好。但是完成上述过程需要花费大量的时间,因为我们店里有很多产品。有时它也会返回超时错误。因此,我想通过拆分这些产品集合来执行上述操作,如果我们有1000个产品,请按照下面的方式执行此操作
Collect 1st 100 products from product collections
Update price of those products
Then collect next 100 products
Update price of those products
有没有人有办法通过一系列ID获取产品集合 有时使用magento(或任何其他框架),最好直接查询数据库,而不是使用现有的系统
使用此选项:
SELECT * FROM `eav_attribute` WHERE `attribute_code` = ‘price’
SELECT * FROM `catalog_product_entity_decimal`
WHERE `attribute_id` = [above id] and `store_id` = [id of your store]
您将获得您的price
属性id
然后使用这个:
SELECT * FROM `eav_attribute` WHERE `attribute_code` = ‘price’
SELECT * FROM `catalog_product_entity_decimal`
WHERE `attribute_id` = [above id] and `store_id` = [id of your store]
您将获得给定商店的所有价格(您可以使用一个简单的MySQL
update
查询来更新它。谢谢您的即时回复。而且我只想为特定的商店设置价格。我可以通过这种方式选择商店吗?如果我记得很清楚,在目录产品实体实体实体实体实体实体实体实体实体实体实体
中有一个store\u id
列,所以答案是肯定的。谢谢您的回复。i我也运行了你的代码。它在我的本地服务器上也运行得很好。但我害怕直接编辑Db。@AmitBera回答在我的框架中也运行得很好。谢谢你!谢谢你的即时回复。它运行得很好,非常感谢。它在产品集合上有一些小错误。按产品id筛选产品,而不是按价格筛选产品!只是将价格更改为实体\u id
$_productCOllection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array(
'from' => $startPrOID,
'to' => $EndPrOID
))
->load();