/**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
  * @magentoAppIsolation enabled
  */
 public function testUpdateBundleProduct()
 {
     // get existing bundle product
     $savedProduct = $this->productService->get('bundle-product');
     /** @var Link $newLink */
     $newLink = $this->linkBuilder->setSku('simple2')->create();
     /** @var Link[] $links */
     $links = array($newLink);
     /** @var Option $newOption */
     $newOption = $this->optionBuilder->setProductLinks($links)->create();
     /** @var Product bundleProduct */
     $updatedBundleProduct = $this->productBuilder->populate($savedProduct)->setCustomAttribute('bundle_product_options', array($newOption))->setCustomAttribute('price_view', 'test')->setCustomAttribute('price', 10)->create();
     $this->assertEquals('bundle-product', $this->productService->update('bundle-product', $updatedBundleProduct));
     $this->productRepository->get('bundle-product')->unsetData('_cache_instance_options_collection');
     // load and confirm number of links and options
     $savedProduct = $this->productService->get('bundle-product');
     /** @var Option[] $updatedOptions */
     $savedOptions = $savedProduct->getCustomAttribute('bundle_product_options')->getValue();
     $this->assertTrue(is_array($savedOptions));
     $this->assertEquals(1, count($savedOptions));
     $option = $savedOptions[0];
     $linkedProducts = $option->getProductLinks();
     $this->assertTrue(is_array($linkedProducts));
     $this->assertEquals(1, count($linkedProducts));
     $link = $linkedProducts[0];
     $this->assertEquals('simple2', $link->getSku());
 }
Пример #2
0
 /**
  * @param OptionModel $option
  * @param Product $product
  * @return Option
  */
 public function createDataFromModel(OptionModel $option, Product $product)
 {
     $this->builder->populateWithArray($option->getData())->setId($option->getId())->setTitle(is_null($option->getTitle()) ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku());
     return $this->builder->create();
 }