Skip to content

Commit

Permalink
Merge branch '2.4-develop' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Hotel authored Sep 13, 2024
2 parents 481edc4 + 66dea0d commit 31aa73c
Show file tree
Hide file tree
Showing 197 changed files with 5,379 additions and 1,733 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,15 @@ public function testSaveAndReplaceAdvancedPricesAddRowErrorCall(): void
'bunch'
]
];
$count = 0;
$this->dataSourceModel
->method('getNextUniqueBunch')
->willReturnOnConsecutiveCalls($testBunch);
->willReturnCallback(function () use (&$count, $testBunch) {
if ($count == 0) {
$count++;
return $testBunch;
}
});
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(false);
$this->advancedPricing->method('saveProductPrices')->willReturnSelf();

Expand Down Expand Up @@ -405,9 +411,15 @@ public function testSaveAndReplaceAdvancedPricesAppendBehaviourDataAndCalls(
$advancedPricing
->method('getBehavior')
->willReturn(Import::BEHAVIOR_APPEND);
$count = 0;
$this->dataSourceModel
->method('getNextUniqueBunch')
->willReturnOnConsecutiveCalls($data);
->willReturnCallback(function () use (&$count, $data) {
if ($count == 0) {
$count++;
return $data;
}
});
$advancedPricing->method('validateRow')->willReturn(true);

$advancedPricing->method('getCustomerGroupId')->willReturnMap(
Expand Down Expand Up @@ -529,9 +541,16 @@ public function testSaveAndReplaceAdvancedPricesReplaceBehaviourInternalCalls():
$this->advancedPricing->method('getBehavior')->willReturn(
Import::BEHAVIOR_REPLACE
);

$count = 0;
$this->dataSourceModel
->method('getNextUniqueBunch')
->willReturnOnConsecutiveCalls($data);
->willReturnCallback(function () use (&$count, $data) {
if ($count == 0) {
$count++;
return $data;
}
});
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(true);

$this->advancedPricing
Expand Down Expand Up @@ -582,9 +601,15 @@ public function testDeleteAdvancedPricingFormListSkuToDelete(): void
]
];

$count = 0;
$this->dataSourceModel
->method('getNextUniqueBunch')
->willReturnOnConsecutiveCalls($data);
->willReturnCallback(function () use (&$count, $data) {
if ($count == 0) {
$count++;
return $data;
}
});
$this->advancedPricing->method('validateRow')->willReturn(true);
$expectedSkuList = ['sku value'];
$this->advancedPricing
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Backend/view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<body>
<attribute name="id" value="html-body"/>
<block name="require.js" class="Magento\Backend\Block\Page\RequireJs" template="Magento_Backend::page/js/require_js.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="head.critical" as="head.critical" template="Magento_Backend::page/container.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="head.additional" template="Magento_Backend::page/container.phtml"/>
<referenceContainer name="global.notices">
<block class="Magento\Backend\Block\Page\Notices" name="global_notices" as="global_notices" template="Magento_Backend::page/notices.phtml"/>
Expand Down
23 changes: 15 additions & 8 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,11 @@ function ($key) use ($optionCollection, $selectionCollection) {

$this->arrayUtility->expects($this->once())->method('flatten')->willReturn($bundleOptions);

$selectionCollection
->method('getItems')
->willReturnOnConsecutiveCalls([$selection], []);
$callCount = 0;
$selectionCollection->method('getItems')
->willReturnCallback(function () use (&$callCount, $selection) {
return $callCount++ === 0 ? [$selection] : [];
});
$selectionCollection
->method('getSize')
->willReturnOnConsecutiveCalls(1, 0);
Expand Down Expand Up @@ -1362,6 +1364,7 @@ public function testPrepareForCartAdvancedParentClassReturnString(): void

/**
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPrepareForCartAdvancedAllRequiredOption(): void
{
Expand Down Expand Up @@ -1452,12 +1455,14 @@ function ($key) use ($optionCollection) {
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5]);
$callCount = 0;
$option->method('getId')
->willReturnOnConsecutiveCalls(3);
->willReturnCallback(function () use (&$callCount) {
return $callCount++ === 0 ? 3 : '';
});
$option->expects($this->once())
->method('getRequired')
->willReturn(true);

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('Please select all required options.', $result);
}
Expand Down Expand Up @@ -1630,9 +1635,11 @@ public function testGetSkuWithoutType(): void
$selectionMock->expects(($this->any()))
->method('getItemByColumnValue')
->willReturn($selectionItemMock);
$selectionItemMock
->method('getEntityId')
->willReturnOnConsecutiveCalls(1);
$callCount = 0;
$selectionItemMock->method('getEntityId')
->willReturnCallback(function () use (&$callCount) {
return $callCount++ === 0 ? 1 : '';
});
$selectionItemMock->expects($this->once())
->method('getSku')
->willReturn($itemSku);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\EntityManager\MetadataPool;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -208,6 +209,19 @@ protected function setUp(): void
->disableOriginalConstructor()
->onlyMethods(['getScope'])
->getMockForAbstractClass();

$objects = [
[
Bundle\RelationsDataSaver::class,
$this->createMock(Bundle\RelationsDataSaver::class)
],
[
StoreManagerInterface::class,
$this->createMock(StoreManagerInterface::class)
]
];
$this->objectManagerHelper->prepareObjectManager($objects);

$this->bundle = $this->objectManagerHelper->getObject(
Bundle::class,
[
Expand Down Expand Up @@ -248,9 +262,12 @@ public function testSaveData(array $skus, array $bunch, bool $allowImport): void
{
$this->entityModel->expects($this->any())->method('getBehavior')->willReturn(Import::BEHAVIOR_APPEND);
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn($skus['newSku']);
$callCount = 0;
$this->entityModel
->method('getNextBunch')
->willReturnOnConsecutiveCalls([$bunch]);
->willReturnCallback(function () use (&$callCount, $bunch) {
return $callCount++ === 0 ? [$bunch] : null;
});
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn($allowImport);
$scope = $this->getMockBuilder(ScopeInterface::class)->getMockForAbstractClass();
$this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope);
Expand Down Expand Up @@ -321,7 +338,7 @@ public function testSaveData(array $skus, array $bunch, bool $allowImport): void
*
* @return array
*/
public function saveDataProvider(): array
public static function saveDataProvider(): array
{
return [
[
Expand Down Expand Up @@ -395,13 +412,12 @@ public function testSaveDataDelete(): void
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn([
'sku' => ['sku' => 'sku', 'entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'bundle']
]);
$callCount = 0;
$this->entityModel
->method('getNextBunch')
->willReturnOnConsecutiveCalls(
[
['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']
]
);
->willReturnCallback(function () use (&$callCount) {
return $callCount++ === 0 ? [['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']] : null;
});
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn(true);
$select = $this->createMock(Select::class);
$this->connection->expects($this->any())->method('select')->willReturn($select);
Expand Down
73 changes: 73 additions & 0 deletions app/code/Magento/Catalog/Model/Category/LayoutCacheTagResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/************************************************************************
*
* Copyright 2024 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
* ************************************************************************
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Category;

use Magento\Catalog\Model\Category;
use Magento\Framework\App\Cache\Tag\StrategyInterface;
use Magento\Framework\Model\AbstractModel;
use Magento\Widget\Model\Widget\Instance;

/**
* Get additional layout cache tag for category layout.
*/
class LayoutCacheTagResolver implements StrategyInterface
{
/**
* @inheritDoc
*/
public function getTags($object)
{
if ($this->isExistingCategoryLayoutChange($object)) {
return [
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_CATEGORY_LAYOUT_HANDLE)
];
}
return [];
}

/**
* Check if existing category page layout change
*
* @param Category $object
* @return bool
*/
private function isExistingCategoryLayoutChange(Category $object): bool
{
return !$object->isObjectNew() && $this->isObjectChanged($object);
}

/**
* Check if the page layout of the given category is changed
*
* @param AbstractModel $object
* @return bool
*/
private function isObjectChanged(AbstractModel $object): bool
{
$isChanged = false;
$objectNewPageLayout = $object->getData('page_layout');
$objectOldPageLayout = $object->getOrigData('page_layout');
if ($objectNewPageLayout !== 'empty' &&
$objectNewPageLayout !== $objectOldPageLayout
) {
$isChanged = true;
}
return $isChanged;
}
}
73 changes: 73 additions & 0 deletions app/code/Magento/Catalog/Model/Product/LayoutCacheTagResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/************************************************************************
*
* Copyright 2024 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
* ************************************************************************
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\App\Cache\Tag\StrategyInterface;
use Magento\Framework\Model\AbstractModel;
use Magento\Widget\Model\Widget\Instance;

/**
* Get additional layout cache tag for product layout.
*/
class LayoutCacheTagResolver implements StrategyInterface
{
/**
* @inheritDoc
*/
public function getTags($object)
{
if ($this->isExistingProductLayoutChange($object)) {
return [
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_PRODUCT_LAYOUT_HANDLE)
];
}
return [];
}

/**
* Check if existing Product page layout change
*
* @param Product $object
* @return bool
*/
private function isExistingProductLayoutChange(Product $object): bool
{
return !$object->isObjectNew() && $this->isObjectChanged($object);
}

/**
* Check if the page layout of the given product is changed
*
* @param AbstractModel $object
* @return bool
*/
private function isObjectChanged(AbstractModel $object): bool
{
$isChanged = false;
$objectNewPageLayout = $object->getData('page_layout');
$objectOldPageLayout = $object->getOrigData('page_layout');
if ($objectNewPageLayout !== 'empty' &&
$objectNewPageLayout !== $objectOldPageLayout
) {
$isChanged = true;
}
return $isChanged;
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ public function save(ProductInterface $product, $saveOptions = false)
$assignToCategories = false;
$tierPrices = $product->getData('tier_price');
$productDataToChange = $product->getData();

if (!$product->getSku()) {
throw new CouldNotSaveException(
__("The \"%1\" attribute value is empty. Set the attribute and try again.", "sku")
);
}

try {
$existingProduct = $product->getId() ?
$this->getById($product->getId()) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function testRedirectOnToolbarAction()
->getMock();
$this->category
->method('hasChildren')
->willReturnOnConsecutiveCalls(true);
->willReturn(true);
$this->category->expects($this->any())
->method('getDisplayMode')
->willReturn('products');
Expand Down Expand Up @@ -297,9 +297,9 @@ public function testApplyCustomLayoutUpdate(array $expectedData): void
->getMock();
$this->category
->method('hasChildren')
->willReturnOnConsecutiveCalls(
$expectedData[1][0]['type'] === 'default'
);
->willReturnCallback(function () use ($expectedData) {
return $expectedData[1][0]['type'] === 'default';
});
$this->category->expects($this->any())
->method('getDisplayMode')
->willReturn($expectedData[2][0]['displaymode']);
Expand Down
Loading

0 comments on commit 31aa73c

Please sign in to comment.