mysql - 通过数据库更改 Magento bundle 产品价格类型

标签 mysql database magento bundle

是否可以通过数据库将现有的 bundle 产品从动态价格更改为固定价格,而不必创建新产品?

最佳答案

我希望您指的不是使用原始 SQL 查询。无论如何,您可以使用 magento 模型来做到这一点。这些步骤应该可以为您完成工作(尽管我自己没有测试过!):

加载您的产品:

    $bundleProduct = new Mage_Catalog_Model_Product();      
    $bundleProduct->load(YOUR_PRODUCT_ID);

将价格类型设置为1:

    $bundleProduct->setPriceType(1); // Price types => 0: dynamic, 1: fixed

保存您的产品:

    $bundleProduct->save();

Here您可以找到可以通过编程方式为 bundle 产品更改的所有属性。


    require_once ("app/Mage.php"); //Pass the exact path to Mage.php file here (e.g. the indicated path works if your script is under main magento installation folder)

    Mage::setIsDeveloperMode(true);
    umask(0);
    Mage::app('admin');
    Mage::register('isSecureArea', 1);
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    error_reporting(E_ALL);

    $bundleProduct = new Mage_Catalog_Model_Product();      
    $bundleProduct->load(YOUR_PRODUCT_ID); //Pass your bundle product ID here; you can get the ID from Magento admin panel
    $bundleProduct->setPriceType(1); // Price types => 0: dynamic, 1: fixed
    $bundleProduct->save();

或者,如果您想为所有现有的 bundle 产品更改此设置,请使用:

$products = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToSelect('type')
                    ->addFieldToFilter('type_id', array('eq' => 'bundle'));

foreach ($products as $product) {
    $product->setPriceType(1);
    $product->save;
}

您可以从命令行或其他方法(浏览器、wget、..)使用 php 命令运行脚本

关于mysql - 通过数据库更改 Magento bundle 产品价格类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30071339/

相关文章:

mysql - INNER JOIN 导致查询执行时间很长

php - 如何在 CakePHP 中检索整数列的整数值?

java - @Transactional 如何影响 Hibernate 中的当前 session ?

Magento - 隐藏一些页脚链接

php - mysql查询计数和求和

python - 如何在 Flask 中处理长 SQL 查询?

database - F# - 依赖管理

database - 使用 New-AzSqlDatabaseExport 在 powershell 中导出 azure 数据库并不总是返回 OperationStatusLink,从而导致异常

mysql - Magento 高负载下抛出错误 : UNQ_SALES_FLAT_INVOICE_INCREMENT_ID

magento - 在 Magento 交易电子邮件中添加 replyTo