public function testDelete()
 {
     $productSku = 'sku1';
     $productOptions = [$this->productOption1];
     $productOption1Sku = 'productOption1Sku';
     $this->productData->expects($this->once())->method('getTypeId')->will($this->returnValue(ProductType::TYPE_BUNDLE));
     $this->productData->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $this->productData->expects($this->once())->method('getCustomAttribute')->with('bundle_product_options')->will($this->returnValue($this->attributeValue));
     $this->attributeValue->expects($this->any())->method('getValue')->will($this->returnValue($productOptions));
     $this->optionWriteService->expects($this->once())->method('remove')->with($productSku, $productOption1Sku)->will($this->returnValue(1));
     $this->saveProcessor->delete($this->productData);
 }
Esempio n. 2
0
 /**
  * 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;
 }
 /**
  * Delete bundle-related attributes of product.
  *
  * @param Product $product
  * @return void
  */
 public function delete(Product $product)
 {
     if ($product->getTypeId() != ProductType::TYPE_BUNDLE) {
         return;
     }
     /**
      * @var string $productSku
      */
     $productSku = $product->getSku();
     /**
      * @var Option[] $bundleProductOptions
      */
     /**
      * @var AttributeValue $bundleProductOptionsAttrValue
      */
     $bundleProductOptionsAttrValue = $product->getCustomAttribute('bundle_product_options');
     if (is_null($bundleProductOptionsAttrValue) || !is_array($bundleProductOptionsAttrValue->getValue())) {
         $bundleProductOptions = array();
     } else {
         $bundleProductOptions = $bundleProductOptionsAttrValue->getValue();
     }
     foreach ($bundleProductOptions as $option) {
         $this->optionWriteService->remove($productSku, $option->getId());
     }
 }