通过数据库更改 Magento 捆绑产品价格类型

Change Magento bundle product price type via database

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

我希望您的意思不是使用原始 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 您可以找到您可以为捆绑产品以编程方式更改的所有属性。


    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();

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

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

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

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