/** * @param string $entityType * @param object $entity * @param array $arguments * @return \Magento\Catalog\Api\Data\ProductInterface|object * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entityType, $entity, $arguments = []) { $options = []; /** @var $entity \Magento\Catalog\Api\Data\ProductInterface */ foreach ($this->optionRepository->getProductOptions($entity) as $option) { $option->setProduct($entity); $options[] = $option; } $entity->setOptions($options); return $entity; }
/** * @param object $entity * @param array $arguments * @return \Magento\Catalog\Api\Data\ProductInterface|object * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ foreach ($this->optionRepository->getProductOptions($entity) as $option) { $this->optionRepository->delete($option); } if ($entity->getOptions()) { foreach ($entity->getOptions() as $option) { $this->optionRepository->save($option); } } return $entity; }
public function testGetMinimalPriceFixedBundleWithOption() { $optionMaxPrice = 2; $this->baseAmount = 5; $result = 7; $this->prepareMock(); $customOptions = [$this->getMockBuilder(\Magento\Catalog\Api\Data\ProductCustomOptionInterface::class)->setMethods(['setProduct'])->getMockForAbstractClass()]; $this->productOptionRepositoryMock->expects(static::once())->method('getProductOptions')->with($this->saleableInterfaceMock)->willReturn($customOptions); $this->saleableInterfaceMock->expects($this->once())->method('getPriceType')->willReturn(Price::PRICE_TYPE_FIXED); $this->customOptionPriceMock->expects($this->once())->method('getCustomOptionRange')->with(true)->willReturn($optionMaxPrice); $this->bundleCalculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($this->baseAmount + $optionMaxPrice), $this->equalTo($this->saleableInterfaceMock))->will($this->returnValue($result)); $this->assertSame($result, $this->finalPrice->getMinimalPrice()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getMinimalPrice()); }