/** * Create bundle product data for use in creating a new product * * @return Product */ private function createBundleProductData($skuSuffix) { /** @var Link $firstLink */ $firstLink = $this->linkBuilder->setSku('simple')->create(); /** @var Link[] $links */ $links = array($firstLink); /** @var Option $firstOption */ $firstOption = $this->optionBuilder->setProductLinks($links)->create(); /** @var Product bundleProduct */ $bundleProduct = $this->productBuilder->setSku('sku-z' . $skuSuffix)->setName('Fancy Bundle')->setTypeId(Type::TYPE_BUNDLE)->setPrice(50.0)->setCustomAttribute('bundle_product_options', array($firstOption))->setCustomAttribute('price_view', 'test')->create(); return $bundleProduct; }
/** * Populate product with variation of attributes * * @param Product $product * @param array $variations * @param array $attributes * @return array */ private function populateProductVariation(Product $product, $variations, $attributes) { $products = []; foreach ($variations as $attributeId => $variation) { $price = $product->getPrice(); $this->productBuilder->populate($product); $suffix = ''; foreach ($variation as $attributeId => $valueInfo) { $suffix .= '-' . $valueInfo['value']; $this->productBuilder->setCustomAttribute($attributes[$attributeId]['attribute_code'], $valueInfo['value']); $priceInfo = $valueInfo['price']; $price += (!empty($priceInfo['is_percent']) ? $product->getPrice() / 100.0 : 1.0) * $priceInfo['price']; } $this->productBuilder->setPrice($price); $this->productBuilder->setName($product->getName() . $suffix); $this->productBuilder->setSku($product->getSku() . $suffix); $this->productBuilder->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE); $products[] = $this->productBuilder->create(); } return $products; }