gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 20:38:40 25 4
gpt4 key购买 nike

是否可以通过数据库将现有的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com