Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magento2
Browse files Browse the repository at this point in the history
 into 2.4-develop
  • Loading branch information
mage-os-ci committed Jun 17, 2024
2 parents fe6755b + 3a7c4d1 commit 91f1cec
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1912,9 +1912,7 @@ protected function _saveTitles(array $titles)
if (!isset($existingOptionIds[$optionId]) && count($storeInfo) > 0) {
$storeInfo = [Store::DEFAULT_STORE_ID => reset($storeInfo)] + $storeInfo;
}
//for use default
$uniqStoreInfo = array_unique($storeInfo);
foreach ($uniqStoreInfo as $storeId => $title) {
foreach ($storeInfo as $storeId => $title) {
$titleRows[] = ['option_id' => $optionId, 'store_id' => $storeId, 'title' => $title];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function aroundAddFieldToFilter(
}
}

$fieldName = $subject->getConnection()->quoteIdentifier($field);
$fieldName = $subject->getConnection()->quoteIdentifier('main_table.' . $field);
$condition = $subject->getConnection()->prepareSqlCondition($fieldName, $condition);
$subject->getSelect()->where($condition, null, Select::TYPE_CONDITION);

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</arguments>
<plugin name="orderGridExportFilterColumnPlugin" type="Magento\Sales\Plugin\Model\Export\OrderGridExportFilterColumn"/>
</type>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<type name="Magento\Sales\Model\ResourceModel\Order\Grid\Collection">
<plugin name="orderGridCollectionFilterPlugin" type="Magento\Sales\Plugin\Model\ResourceModel\Order\OrderGridCollectionFilter"/>
</type>
<type name="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider\ProductCollection">
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Wishlist/CustomerData/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Customer\CustomerData\SectionSourceInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\StoreManagerInterface;

/**
* Wishlist section
Expand All @@ -17,7 +18,7 @@ class Wishlist implements SectionSourceInterface
/**
* @var string
*/
const SIDEBAR_ITEMS_NUMBER = 3;
public const SIDEBAR_ITEMS_NUMBER = 3;

/**
* @var \Magento\Wishlist\Helper\Data
Expand All @@ -44,19 +45,26 @@ class Wishlist implements SectionSourceInterface
*/
private $itemResolver;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
* @param \Magento\Wishlist\Block\Customer\Sidebar $block
* @param \Magento\Catalog\Helper\ImageFactory $imageHelperFactory
* @param \Magento\Framework\App\ViewInterface $view
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface|null $itemResolver
* @param StoreManagerInterface|null $storeManager
*/
public function __construct(
\Magento\Wishlist\Helper\Data $wishlistHelper,
\Magento\Wishlist\Block\Customer\Sidebar $block,
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
\Magento\Framework\App\ViewInterface $view,
\Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface $itemResolver = null
\Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface $itemResolver = null,
StoreManagerInterface $storeManager = null
) {
$this->wishlistHelper = $wishlistHelper;
$this->imageHelperFactory = $imageHelperFactory;
Expand All @@ -65,6 +73,7 @@ public function __construct(
$this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(
\Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface::class
);
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand All @@ -76,6 +85,7 @@ public function getSectionData()
return [
'counter' => $counter,
'items' => $counter ? $this->getItems() : [],
'websiteId' => $this->storeManager->getWebsite()->getId()
];
}

Expand Down
56 changes: 52 additions & 4 deletions app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\App\ViewInterface;
use Magento\Framework\Pricing\Render;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Wishlist\Block\Customer\Sidebar;
use Magento\Wishlist\CustomerData\Wishlist;
use Magento\Wishlist\CustomerData\Wishlist as WishlistModel;
Expand All @@ -23,6 +24,7 @@
use Magento\Wishlist\Model\ResourceModel\Item\Collection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Store\Api\Data\WebsiteInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -47,6 +49,15 @@ class WishlistTest extends TestCase
/** @var ImageBuilder|MockObject */
private $itemResolver;

/** @var StoreManagerInterface|MockObject */
private $storeManagerMock;

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

/** @var ImageFactory|MockObject */
private $imageHelperFactory;

protected function setUp(): void
{
$this->wishlistHelperMock = $this->getMockBuilder(Data::class)
Expand All @@ -61,24 +72,34 @@ protected function setUp(): void
$this->catalogImageHelperMock = $this->getMockBuilder(Image::class)
->disableOriginalConstructor()
->getMock();
$imageHelperFactory = $this->getMockBuilder(ImageFactory::class)
$this->imageHelperFactory = $this->getMockBuilder(ImageFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();
$imageHelperFactory->expects($this->any())
$this->imageHelperFactory->expects($this->any())
->method('create')
->willReturn($this->catalogImageHelperMock);

$this->itemResolver = $this->createMock(
ItemResolverInterface::class
);

$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->websiteMock = $this->getMockBuilder(WebsiteInterface::class)
->onlyMethods(['getId',])
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->model = new Wishlist(
$this->wishlistHelperMock,
$this->sidebarMock,
$imageHelperFactory,
$this->imageHelperFactory,
$this->viewMock,
$this->itemResolver
$this->itemResolver,
$this->storeManagerMock
);
}

Expand All @@ -102,6 +123,14 @@ public function testGetSectionData()
$itemAddParams = ['add_params'];
$itemRemoveParams = ['remove_params'];

$this->storeManagerMock->expects($this->once())
->method('getWebsite')
->willReturn($this->websiteMock);

$this->websiteMock->expects($this->once())
->method('getId')
->willReturn(1);

$result = [
'counter' => __('1 item'),
'items' => [
Expand All @@ -124,6 +153,7 @@ public function testGetSectionData()
'delete_item_params' => $itemRemoveParams,
],
],
'websiteId' => 1
];

/** @var Item|MockObject $itemMock */
Expand Down Expand Up @@ -288,6 +318,14 @@ public function testGetSectionDataWithTwoItems()
->getMock();
$items = [$itemMock, $itemMock];

$this->storeManagerMock->expects($this->once())
->method('getWebsite')
->willReturn($this->websiteMock);

$this->websiteMock->expects($this->once())
->method('getId')
->willReturn(1);

$result = [
'counter' => __('%1 items', count($items)),
'items' => [
Expand Down Expand Up @@ -328,6 +366,7 @@ public function testGetSectionDataWithTwoItems()
'delete_item_params' => $itemRemoveParams,
],
],
'websiteId' => 1
];

$this->wishlistHelperMock->expects($this->once())
Expand Down Expand Up @@ -465,9 +504,18 @@ public function testGetSectionDataWithoutItems()
{
$items = [];

$this->storeManagerMock->expects($this->once())
->method('getWebsite')
->willReturn($this->websiteMock);

$this->websiteMock->expects($this->once())
->method('getId')
->willReturn(null);

$result = [
'counter' => null,
'items' => [],
'websiteId' =>null
];

$this->wishlistHelperMock->expects($this->once())
Expand Down
22 changes: 19 additions & 3 deletions app/code/Magento/Wishlist/view/frontend/web/js/view/wishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@

define([
'uiComponent',
'Magento_Customer/js/customer-data'
], function (Component, customerData) {
'Magento_Customer/js/customer-data',
'underscore'
], function (Component, customerData, _) {
'use strict';

var wishlistReloaded = false;

return Component.extend({
/** @inheritdoc */
initialize: function () {
this._super();

this.wishlist = customerData.get('wishlist');
if (!wishlistReloaded
&& !_.isEmpty(this.wishlist())
// Expired section names are reloaded on page load.
&& _.indexOf(customerData.getExpiredSectionNames(), 'wishlist') === -1
&& window.checkout
&& window.checkout.websiteId
&& window.checkout.websiteId !== this.wishlist().websiteId
) {
//set count to 0 to prevent "wishlist" blocks and count to show with wrong count and items
this.wishlist().counter = 0;
customerData.invalidate(['wishlist']);
customerData.reload(['wishlist'], false);
wishlistReloaded = true;
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
use Magento\Catalog\Helper\Data as CatalogConfig;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\CatalogImportExport\Model\Import\ProductTestBase;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Magento\ImportExport\Helper\Data as ImportExportConfig;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Test\Fixture\Store as StoreFixture;
use Magento\TestFramework\Fixture\AppIsolation;
use Magento\TestFramework\Fixture\Config;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
Expand Down Expand Up @@ -90,7 +94,7 @@ public function testSaveCustomOptions(string $importFile, string $sku, int $expe
$importModel->importData();

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
$productRepository = Bootstrap::getObjectManager()->create(
\Magento\Catalog\Api\ProductRepositoryInterface::class
);
$product = $productRepository->get($sku);
Expand Down Expand Up @@ -187,17 +191,17 @@ public function testSaveCustomOptionsWithMultipleStoreViews(
array $expected
) {
$expected = $this->getFullExpectedOptions($expected);
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager = Bootstrap::getObjectManager();
/** @var StoreManagerInterface $storeManager */
$storeManager = $objectManager->get(StoreManagerInterface::class);
$pathToFile = __DIR__ . '/../_files/' . $importFile;
$importModel = $this->createImportModel($pathToFile);
$errors = $importModel->validateData();
$this->assertTrue($errors->getErrorsCount() == 0, 'Import File Validation Failed');
$importModel->importData();
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->get(
\Magento\Catalog\Api\ProductRepositoryInterface::class
ProductRepositoryInterface::class
);
$actual = [];
foreach ($expected as $sku => $storesData) {
Expand Down Expand Up @@ -982,9 +986,9 @@ public function testImportCustomOptions(string $importFile, string $sku1, string
$this->assertTrue($errors->getErrorsCount() == 0);
$importModel->importData();

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Api\ProductRepositoryInterface::class
/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()->create(
ProductRepositoryInterface::class
);
$product1 = $productRepository->get($sku1);

Expand Down Expand Up @@ -1025,4 +1029,64 @@ public function getCustomOptionDataProvider(): array
],
];
}

/**
* Tests import product custom options with multiple uploads.
*
* @dataProvider getProductCustomOptionDataProvider
* @param string $importFile
* @param string $sku
* @param int $uploadCount
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws StateException
*/
public function testImportProductCustomOptionsOnMultipleUploads(
string $importFile,
string $sku,
int $uploadCount
): void {
$pathToFile = __DIR__ . '/../_files/' . $importFile;

for ($count = 0; $count < $uploadCount; $count++) {
$productImportModel = $this->createImportModel($pathToFile);
$errors = $productImportModel->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$productImportModel->importData();
}

/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()->create(
ProductRepositoryInterface::class
);
$product = $productRepository->get($sku);

$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product);
$options = $product->getOptionInstance()->getProductOptions($product);

$expectedData = $this->getExpectedOptionsData($pathToFile, 'default');
$expectedOptions = $expectedData['options'];

$this->assertCount(count($expectedOptions), $options);

// Cleanup imported products
try {
$this->productRepository->delete($product);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
}
}

/**
* @return array
*/
public function getProductCustomOptionDataProvider(): array
{
return [
[
'importFile' => 'product_with_custom_options_and_multiple_uploads.csv',
'sku' => 'p1',
'uploadCount' => 2,
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sku,store_view_code,attribute_set_code,product_type,custom_options
p1,default,Default,simple,"name=Option One,type=multiple,required=0,price=2.000000,sku=1,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=One|name=Option One,type=multiple,required=0,price=2.000000,sku=2,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Two|name=Option Two,type=multiple,required=0,price=3.000000,sku=3,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Three|name=Option Two,type=multiple,required=0,price=4.000000,sku=4,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Four"
Loading

0 comments on commit 91f1cec

Please sign in to comment.