コード例 #1
0
ファイル: RepositoryTest.php プロジェクト: koliaGI/magento2
 /**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  */
 public function testDeleteByIdentifierWhenCannotRemoveOption()
 {
     $optionId = 1;
     $productSku = 'simple_product';
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku, true)->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getOptions')->willReturn([$optionId => $this->optionMock]);
     $this->productMock->expects($this->once())->method('getOptionById')->with($optionId)->willReturn($this->optionMock);
     $this->optionResourceMock->expects($this->once())->method('delete')->with($this->optionMock);
     $this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock)->willThrowException(new \Exception());
     $this->assertTrue($this->optionRepository->deleteByIdentifier($productSku, $optionId));
 }
コード例 #2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testUpdateNonExistingOption()
 {
     $convertedOption = ['title' => 'test_option_code_1', 'type' => 'field', 'sort_order' => 1, 'is_require' => 1, 'price' => 10, 'price_type' => 'fixed', 'sku' => 'sku1', 'max_characters' => 10, 'values' => []];
     $optionId = 10;
     $productSku = 'productSku';
     $this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku);
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku, true)->willReturn($this->productMock);
     $this->converterMock->expects($this->once())->method('toArray')->with($this->optionMock)->will($this->returnValue($convertedOption));
     $this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId);
     $this->productMock->expects($this->once())->method('getOptionById')->with($optionId);
     $this->optionRepository->save($this->optionMock);
 }
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     if (!$this->getCollection()->isLoaded()) {
         $currentProductId = (int) $this->request->getParam('current_product_id');
         if (0 !== $currentProductId) {
             $this->getCollection()->getSelect()->where('e.entity_id != ?', $currentProductId);
         }
         $this->getCollection()->getSelect()->distinct()->join(['opt' => $this->getCollection()->getTable('catalog_product_option')], 'opt.product_id = e.entity_id', null);
         $this->getCollection()->load();
         /** @var ProductInterface $product */
         foreach ($this->getCollection() as $product) {
             $options = [];
             /** @var ProductOption|DataObject $option */
             foreach ($this->productOptionRepository->getProductOptions($product) as $option) {
                 $option->setData('values', $this->productOptionValueModel->getValuesCollection($option)->toArray()['items']);
                 $options[] = $option->toArray();
             }
             $product->setOptions($options);
         }
     }
     $items = $this->getCollection()->toArray();
     return ['totalRecords' => $this->getCollection()->getSize(), 'items' => array_values($items)];
 }
コード例 #4
0
ファイル: Option.php プロジェクト: dragonsword007008/magento2
 /**
  * Get Product Option Collection
  *
  * @param Product $product
  * @return \Magento\Catalog\Model\ResourceModel\Product\Option\Collection
  */
 public function getProductOptions(Product $product)
 {
     return $this->optionRepository->getProductOptions($product, $this->getAddRequiredFilter());
 }