我知道这是一个特定于框架的问题,而不是一般的编程问题,但是我已经在Magento StackExchange论坛上提出了这个问题,但没有得到任何回应。
我想用我所有简单产品的特惠价格代替正常价格(特惠价格将不再存在)。我对Magento还是很陌生,我不知道什么是最好的方法。
我当时在考虑替换值的SQL查询,然后找到一种方法来禁用不再优惠的产品上的特价。
我还以为我可以使用导入/导出工具导出所有打折的简单产品的列表,在Excel中更改其属性,然后使用Magmi导入新的csv,但是默认的Magento导入/导出工具不起作用。对我来说很好(同一SKU多行)。
有什么办法可以安全地执行此操作吗?Magmi是否可以禁用我产品中的所有特惠价格?
我的Magento版本是Magento 1.9
谢谢!
我个人的喜好是使用Magento Shell脚本。您可以在shell
dir下找到一些示例。
创建一个后,只需使用以下命令即可调用它:
php shell/<script-name>.php
这样,您就可以访问Magento的ORM,并且可以以更安全的方式完成此任务。
实施这样的cli脚本应该很容易,但是如果您需要帮助,请使用未经测试的版本::)
<?php
require_once 'abstract.php';
class Mage_Shell_SpecialPrice extends Mage_Shell_Abstract
{
public function run()
{
if ($this->getArg('help')) {
echo $this->usageHelp();
return;
}
$collection = $this->_getProductCollection();
/** @var Mage_Catalog_Model_Product $product */
foreach ($collection as $product) {
$product->setPrice($product->getSpecialPrice())
->setSpecialPrice(null);
$product->getResource()->saveAttribute($product, 'price');
$product->getResource()->saveAttribute($product, 'special_price');
}
}
/**
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
protected function _getProductCollection()
{
return Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('special_price', array('notnull' => true))
->setOrder($this->getArg('limit') ?: 'created_at', $this->getArg('dir') ?: 'desc')
->setPageSize($this->getArg('limit') ?: 20);
}
/**
* @return string
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f special-price.php
php -f special-price.php --limit 20 --sort created_at --dir desc
USAGE;
}
}
$shell = new Mage_Shell_SpecialPrice();
$shell->run();
我抛弃了一些命令行参数示例以取得良好的效果,但这通常就是这样。
干杯。:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句