/**
  * 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());
     }
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \Magento\Webapi\Exception
  * @expectedExceptionCode 403
  */
 public function testRemoveWebApiException()
 {
     $productSku = 'oneSku';
     $optionId = 3;
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE));
     $this->product->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $this->model->remove($productSku, $optionId);
 }
 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);
 }