Question

J'ai effectivement réussi à créer le programme produit fourni, et il apparaît dans Admin correctement, mais ne montre pas la fin de l'avant jusqu'à ce que je sauverai à partir de l'administration. Je suis en train de créer un grand nombre de produits groupés, afin d'avoir à aller dans l'administration et les sauver n'est pas acceptable individuellement.

Voici mon code:

foreach($productRow as $product){

$data = array(

    'attribute_set_id' => 64, //MANUALLY SET

    'sku_type'                              => 0, //0 = dynamic, 1 = fixed
    'sku'                                   => $product['INVENTORY_PARTNUMBER']."B",
    'name'                                  => $product['INVENTORY_ITEMNAME'],
    'description'                           => $product['WEB_DESCRIPTION'],
    'short_description'                     => $product['WEB_DESCRIPTION'],
    'type_id'                               => 'bundle',
    'entity_type_id'                        => 4,
    'weight_type'                           => 0, //0 = dynamic, 1 = fixed
    'visibility'                            => 4,
    'price_type'                            => 0, //0 = dynamic, 1 = fixed
    'price_view'                            => 1, //0 = as low as, 1 = price range <---- DOES NOT SEEM TO HAVE ANY EFFECT
    'status'                                => 1,
    'created_at'                            => strtotime('now'),
    'category_ids'                          => $cats,
    'store_id'                              => $storeID,
    'website_ids'                           => $websiteIDs,
    'freightquote_height'                   => '36',
    'freightquote_width'                    => '36',
    'freightquote_length'                   => '36',

    'freightquote_nmfc'                     => 0,
    'freightquote_commodity'                => 'GeneralMerchandise',
    'freightquote_content'                  => 'NewCommercialGoods',
    'freightquote_hzmt'                     => 0,
    'freightquote_enable'                   => 0,
);

$productCheck = Mage::getModel('catalog/product');

    $productCheck->setData($data);
    Mage::register('product', $productCheck);
    Mage::register('current_product', $product);

    $productCheck->setStockData(array(
        'is_in_stock' => 1,
        'qty' => 1
    ));
    $productCheck->setPriceView(1);

    $optionRawData = array();
    $selectionRawData = array();

    $i = 0;

    /**
     * Turning the SKU into an "option" so that
     * it can be added to the bundle
     */
    $product['INVENTORY_PARTNUMBER'] = $product['INVENTORY_PARTNUMBER'].", the sku";

    foreach ($options as $option => $name){

        if(isset($product[$option])){
            $optionRawData[$i] = array(
                'required' => 0,
                'option_id' => '',
                'position' => $i,
                'type' => 'radio',
                'title' => $name,
                'default_title' => $name,
                'delete' => '',
            );

            $partsArray = explode ("|", $product[$option]);


            foreach ($partsArray as $pn){

                    $product_id = Mage::getModel("catalog/product")->getIdBySku($pn);

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

                    $i2++;
            }
            $i++;
        }

    }

    $productCheck->setCanSaveConfigurableAttributes(false);
    $productCheck->setCanSaveCustomOptions(false);

    // Set the Bundle Options & Selection Data
    $productCheck->setBundleOptionsData($optionRawData);
    $productCheck->setBundleSelectionsData($selectionRawData);
    $productCheck->setCanSaveBundleSelections(true);
    $productCheck->setAffectBundleProductSelections(true);

    try {
        $productCheck->save();
    }
    catch(exception $e) {
        echo "<pre>";
        print_r($e);
        echo "</pre>";
    }

Tout ce que je peux trouver des spectacles que je l'ai créé et enregistré correctement le produit livré, mais il ne sera pas affiché à l'avant jusqu'à ce que je sauverai de la fin arrière. L'indexation ne fait rien, et le cache est désactivé.

Était-ce utile?

La solution

The answer was pretty simple: Website ID was zero and need to be 1

EDIT: Wanted to add to my answer since finding information for automating bundled products is lacking, and its the one feature that has yet to fully find its way into Magmi.

If you're having trouble with $product->save(); try $product->getResource()->save($product);

To programmatically update a bundled product, check this post to load the bundled product data correctly. Then, you can check if a bundled product exists; from there you only need to match your option titles to the existing product, and get that options ID with $option->getOptionId() so that you don't create a duplicate option.

Updating any other attribute on your bundled product (except for the elusive "Ship Bundle Items" attribute) can be added to an associative array as you would an attribute for any other product, and use $product->addData($data) to update your product attributes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top