用Magento创建捆绑产品 [英] Creating a bundled product with Magento

查看:137
本文介绍了用Magento创建捆绑产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直遵循以下示例: Magento以编程方式创建捆绑产品

I've been following along with this example: Magento programmaticaly create bundle Product

,并且在创建新产品时代码可以正常工作,但是,当我加载捆绑或简单的产品时,我无法使其正常工作. 我可以通过下面的代码加载以编程方式创建的捆绑产品,然后将产品添加到捆绑中.我通过GUI创建的捆绑产品,我也无法添加产品.

and the code is working when I create a new product, however, I can't get it to work when I load a product either bundled or simple. I can load a bundled product that I created programmatically through the code below and add products to the bundle. A bundled product I created through the GUI I cannot add products too.

您知道如何加载产品然后将其与另一产品捆绑在一起吗?

Any idea how I can load a product up then bundle it with another a product?

这是我当前的代码:

    $items = array();
$items[] = array(
    'title'     => 'Bundle Option',
    'option_id' => '',
    'delete'    => '',
    'type'      => 'radio',
    'required'  => 1,
    'position'  => 0,
);

$selectionRawData = array();
$selectionRawData[0] = array();
$selectionRawData[0][] = array(
    'selection_id'             => '',
    'option_id'                => '',
    'product_id'               => 3,
    'delete'                   => '',
    'selection_price_value'    => 0,
    'selection_price_type'     => 0,
    'selection_qty'            => 1,
    'selection_can_change_qty' => 0,
    'position'                 => 0,
    'is_default'               => 1,
);

$selections = $selectionRawData;

$websiteIDs = array(1);
$cats = array(4);

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

// load product
// NOT WORKING
$product = Mage::getModel('catalog/product');
$product->load(127);


// new product
/******
 * THIS WORKS

$p = array(
            'sku_type' => 1,
            'sku' => '123321',
            'name' => "BarProduct",
            'description' => 'Foo',
            'short_description' => 'Bar',
            'type_id' => 'bundle',
            'attribute_set_id' => 4,
            'weight_type' => 0,
            'visibility' => 4,
            'price_type' => 1,
            'price_view' => 0,
            'price' => 1.99,
            'has_options' => 1,
            'required_options' => 1,
            'status' => 1,
            'created_at' => strtotime('now'),
            'category_ids' => $cats,
            'store_id' => 0,
            'website_ids' => $websiteIDs,
            'weight' => 0,
            'weight_type' => 1,
            'delivery_time' => '',
            'generate_meta' => 1,
            'tax_class_id' => 1, //19%
    );
    $product->setData($p);

*****/ 

Mage::register('product', $product);
Mage::register('current_product', $product);

$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);

$product->setBundleOptionsData($items);
$product->setBundleSelectionsData($selections);
$product->setCanSaveCustomOptions(true);
$product->setCanSaveBundleSelections(true);
$product->setAffectBundleProductSelections(true);

$product->save();

$result['product_name'] = $product->getId();
return $result;

推荐答案

我的产品索引上有一些时髦的内容.我删除了所有产品并修复了索引,尽管效果不佳,但现在可以正常工作.

I had some funky stuff going on with my product index. I deleted all my products and fixed my index and this now works, albeit not well.

这就是我从过程中收集到的信息:

So here is what I gleaned from the process:

如果要购买两个简单产品并将其捆绑在一起,则需要通过上面的$p = array代码创建一个新的捆绑产品,然后添加两个简单产品.

If you want to take two simple products and bundle them, you'll need to create a new bundled bundled product via the $p = array code above, then add both simple products.

否则,您将需要通过magento gui预先制造的捆绑产品.那么您将使用$ product-> load(product_id)命令启动该产品,然后向其中添加简单的产品.

Otherwise, you'll need a bundled product that is premade via the magento gui. then you'll have bring up that product using the $product->load(product_id) command, then add your simple products to that.

这篇关于用Magento创建捆绑产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆