简体   繁体   English

无法在Magento中创建可配置的产品

[英]Unable to create configurable product in Magento

I am struggling to create Configurable product using simple PHP script, I would appreciate if you can help me out, 我正在努力使用简单的PHP脚本创建可配置产品,如果您能帮助我,我将不胜感激,

$sku_array = array(substr(sha1(mt_rand()), 0, 5),
                   substr(sha1(mt_rand()), 0, 5),
                   substr(sha1(mt_rand()), 0, 5),
                   substr(sha1(mt_rand()), 0, 5),
                   substr(sha1(mt_rand()), 0, 5),
                   substr(sha1(mt_rand()), 0, 5));
$color_array = array('Black','Blue','Green','Maroon','Navy','Red','White');
$size_array = array('S','M','L','XL','2XL');
$style_array = array('Men','Unisex','Women');
$price_array = array('8.90','9.00','12.30','14.25','15.99','11.30','4.45');
$associated_skus = array();

for($i=0; $i < 4; $i++) {
$productData = array(
    'categories'=> array(3),
    'name' => 'Name of product #' . ($i+1),
    'description' => 'Description of product #' . ($i+1),
    'short_description' => 'Short description of product #' . ($i+1),
    'websites' => array(1), // Id or code of website
    'status' => 1, // 1 = Enabled, 2 = Disabled
    'visibility' => 1, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search
    'tax_class_id' => 0, // 0 None; 2: Taxable Good; 4: Shipping
    'weight' => 0,
    'stock_data' => array(
        'use_config_manage_stock' => 0,
        'manage_stock' => 0, // We do not manage stock, for example
        'qty' => '100',
        'is_in_stock' => 1
    ),
    'price' => array_rand(array_flip($price_array),1), // Same price than configurable product, no price change
    'additional_attributes' => array(
        'single_data' => array(
            array(
                'key'   => 'style',
                'value' => array_rand(array_flip($style_array),1), // Id or label of style, attribute that will be used to configure product    (Men,Unisex,Women)      
            ),
            array(
                'key'   => 'color',
                'value' => array_rand(array_flip($color_array),1), // Id or label of color, attribute that will be used to configure product
            ),
            array(
                'key'   => 'size',
                'value' => array_rand(array_flip($size_array),1), // Id or label of size, attribute that will be used to configure product
            ),
        ),
    ),
);

// Creation of simple products
$proxy->catalogProductCreate($sessionId, 'simple', '9', 'SKU-' . $sku_array[$i], $productData);
$associated_skus[] =  'SKU-' . $sku_array[$i];

}

echo "<pre>";
echo "Ass Products";
print_r($associated_skus);
echo "<br />";


/**
 * Configurable product
 */
$productData = array(
    'categories'=> array(3),
    'name' => 'Configurable product',
    'description' => 'Description of configurable product',
    'short_description' => 'Short description of configurable product',
    'websites' => array(1), // Id or code of website
    'status' => 1, // 1 = Enabled, 2 = Disabled
    'visibility' => 4, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search
    'tax_class_id' => 2, // Default VAT
    'weight' => 0,
    'stock_data' => array(
        'use_config_manage_stock' => 0,
        'manage_stock' => 0, // We do not manage stock, for example
    ),
    'price' => 9.90,
    'associated_skus' => array($associated_skus), // Simple products to associate
    'price_changes' => array(),
);

$result = $proxy->catalogProductCreate($sessionId, 'configurable', '9', 'SKU-' . $sku_array[5], $productData);
echo "<pre>";
print_r($result);

Basically; 基本上; simple products including configurable product is visible in admin backend but on the front side it does not display the product, and when tried to edit Configurable product skus of associated product also missing. 包括可配置产品在内的简单产品在管理后端中可见,但在正面却不显示该产品,并且在尝试编辑关联产品的可配置产品时也会丢失。

Default Magento API does not allow to associate products to configurable products. 默认的Magento API不允许将产品与可配置产品相​​关联。 You can customize the API to achieve this. 您可以自定义API来实现此目的。 Follow this blog - http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/ 跟随此博客-http: //www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/

If you do not wish to download the plugin, then simply refer the code from below files and update your API accordingly. 如果您不想下载插件,则只需参考以下文件中的代码并相应地更新您的API。

associateProducts() - https://github.com/jreinke/magento-improve-api/blob/master/app/code/community/Bubble/Api/Helper/Catalog/Product.php associateProducts() -https://github.com/jreinke/magento-improve-api/blob/master/app/code/community/Bubble/Api/Helper/Catalog/Product.php

_prepareDataForSave() - https:// github.com/jreinke/magento-improve-api/blob/master/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php _prepareDataForSave()-https://github.com/jreinke/magento-improve-api/blob/master/app/code/community/Bubble/Api/Model/Catalog/Product/Api.php

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM