Frage

Ich habe das Web gesucht. Konnte jedoch keine ordnungsgemäße Anleitung finden, um gruppiertes Produkt programmgesteuert zu erstellen.

Kann jemand dafür eine ordnungsgemäße Anleitung bereitstellen?

Links zu Web -Posts, Büchern, PDF und anderen Online -Anleitungen werden sehr geschätzt.

Danke im Voraus

War es hilfreich?

Lösung

Der folgende Code funktionierte perfekt für mich, um gruppiertes Produkt mit seinen assoziierten Produkten zu erstellen. Ich hoffe, dies hilft jemandem, gruppierte Produkte programmatisch zu erstellen.

public function createGroupedProduct()
    {
        $sku = 'AL108';
        $title = 'my test product';
        $description = 'this is a description about the product...';

        $product = new Mage_Catalog_Model_Product();

        $product->setSku($sku.'-grouped');
        $product->setAttributeSetId(63); // put your attribute set id here.
        $product->setTypeId('grouped');
        $product->setName($title);
        $product->setCategoryIds(array(35)); // put your category ids here
        $product->setWebsiteIDs(array(1,2,3));// put your website ids here
        $product->setDescription($description);
        $product->setShortDescription($description);
        $product->setPrice(1000);
        $product->setWeight(200);
        $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
        $product->setStatus(1);
        $product->setTaxClassId(0); 
        $product->setStockData(array(
                                    'is_in_stock'             => 1,
                                    'manage_stock'            => 0,
                                    'use_config_manage_stock' => 1
                                    ));

        try {
// Save the grouped product.
            $product->save();       
            $group_product_id = $product->getId();

// You need to create an array which contains the associate product ids.
            $simpleProductId[0] = 1483;
            $simpleProductId[1] = 1484;
            $simpleProductId[2] = 1485;
                $simpleProductId[3] = 1486;
            $simpleProductId[4] = 1487;

            $products_links = Mage::getModel('catalog/product_link_api');

// Get grouped product id.
            $group_product_id = $product->getId();

// Map each associate product with the grouped product.
            foreach($simpleProductId as $id){
                $products_links->assign ("grouped",$group_product_id,$id);
            }

        } catch (Exception $ex) {
            echo $ex->getMessage();
        }

    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top