Skip to content

Commit

Permalink
magento#12584: Bundle Item price cannot differ per website.
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Foxtrot committed Nov 19, 2020
1 parent ed0f987 commit a7adbdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 1 addition & 3 deletions app/code/Magento/Bundle/Model/LinkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ protected function mapProductLinkToSelectionModel(
if ($productLink->getIsDefault() !== null) {
$selectionModel->setIsDefault($productLink->getIsDefault());
}
if ($productLink->getWebsiteId() !== null) {
$selectionModel->setWebsiteId($productLink->getWebsiteId());
}
$selectionModel->setWebsiteId((int)$this->storeManager->getWebsite()->getId());

return $selectionModel;
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/Model/Option/SaveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Api\ProductLinkManagementInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public function save(ProductInterface $bundleProduct, OptionInterface $option)
}
} else {
if (!$existingOption->getOptionId()) {
throw new \Magento\Framework\Exception\NoSuchEntityException(
throw new NoSuchEntityException(
__("The option that was requested doesn't exist. Verify the entity and try again.")
);
}
Expand Down Expand Up @@ -147,7 +148,6 @@ private function updateOptionSelection(ProductInterface $product, OptionInterfac
if (is_array($option->getProductLinks())) {
$productLinks = $option->getProductLinks();
foreach ($productLinks as $productLink) {
$productLink->setWebsiteId($this->storeManager->getStore($product->getStoreId())->getWebsiteId());
if (!$productLink->getId() && !$productLink->getSelectionId()) {
$linksToAdd[] = $productLink;
} else {
Expand Down
21 changes: 17 additions & 4 deletions app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -139,6 +140,11 @@ class LinkManagementTest extends TestCase
*/
private $linkField = 'product_id';

/**
* @var WebsiteInterface|MockObject
*/
private $websiteMock;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -203,6 +209,9 @@ protected function setUp(): void
$this->dataObjectHelperMock = $this->getMockBuilder(DataObjectHelper::class)
->disableOriginalConstructor()
->getMock();

$this->websiteMock = $this->getMockForAbstractClass( WebsiteInterface::class);

$this->model = $helper->getObject(
LinkManagement::class,
[
Expand Down Expand Up @@ -539,7 +548,8 @@ public function testAddChildCouldNotSave()
$productLink->method('getSku')->willReturn('linked_product_sku');
$productLink->method('getOptionId')->willReturn(1);
$productLink->method('getSelectionId')->willReturn(1);
$productLink->method('getWebSiteId')->willReturn(100);
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
$this->websiteMock->expects($this->once())->method('getId')->willReturn(100);

$this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField);
$productMock = $this->createMock(Product::class);
Expand Down Expand Up @@ -617,7 +627,8 @@ public function testAddChild()
$productLink->method('getSku')->willReturn('linked_product_sku');
$productLink->method('getOptionId')->willReturn(1);
$productLink->method('getSelectionId')->willReturn(1);
$productLink->method('getWebSiteId')->willReturn(100);
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
$this->websiteMock->expects($this->once())->method('getId')->willReturn(100);

$this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField);
$productMock = $this->createMock(Product::class);
Expand Down Expand Up @@ -705,7 +716,8 @@ public function testSaveChild()
->willReturn($canChangeQuantity);
$productLink->method('getIsDefault')->willReturn($isDefault);
$productLink->method('getSelectionId')->willReturn($optionId);
$productLink->method('getWebSiteId')->willReturn($websiteId);
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
$this->websiteMock->expects($this->once())->method('getId')->willReturn($websiteId);

$this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField);
$productMock = $this->createMock(Product::class);
Expand Down Expand Up @@ -785,7 +797,8 @@ public function testSaveChildFailedToSave()
$productLink->method('getSku')->willReturn('linked_product_sku');
$productLink->method('getId')->willReturn($id);
$productLink->method('getSelectionId')->willReturn(1);
$productLink->method('getWebsiteId')->willReturn($websiteId);
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
$this->websiteMock->expects($this->once())->method('getId')->willReturn($websiteId);

$bundleProductSku = 'bundleProductSku';

Expand Down

0 comments on commit a7adbdc

Please sign in to comment.