/** * 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()); } }
/** * @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); }