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 Aug 19, 2023
2 parents 4696f50 + 70f8114 commit 70a0b88
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class Plugin
{
private const MESSAGES_LIMIT = 5;
/**
* @var \Magento\AdminNotification\Model\System\MessageFactory
*/
Expand Down Expand Up @@ -95,27 +96,32 @@ public function afterToArray(
$this->bulkNotificationManagement->getAcknowledgedBulksByUser($userId)
);
$bulkMessages = [];
$messagesCount = 0;
$data = [];
foreach ($userBulks as $bulk) {
$bulkUuid = $bulk->getBulkId();
if (!in_array($bulkUuid, $acknowledgedBulks)) {
$details = $this->operationDetails->getDetails($bulkUuid);
$text = $this->getText($details);
$bulkStatus = $this->statusMapper->operationStatusToBulkSummaryStatus($bulk->getStatus());
if ($bulkStatus === \Magento\Framework\Bulk\BulkSummaryInterface::IN_PROGRESS) {
$text = __('%1 item(s) are currently being updated.', $details['operations_total']) . $text;
if ($messagesCount < self::MESSAGES_LIMIT) {
$details = $this->operationDetails->getDetails($bulkUuid);
$text = $this->getText($details);
$bulkStatus = $this->statusMapper->operationStatusToBulkSummaryStatus($bulk->getStatus());
if ($bulkStatus === \Magento\Framework\Bulk\BulkSummaryInterface::IN_PROGRESS) {
$text = __('%1 item(s) are currently being updated.', $details['operations_total']) . $text;
}
$data = [
'data' => [
'text' => __('Task "%1": ', $bulk->getDescription()) . $text,
'severity' => \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR,
// md5() here is not for cryptographic use.
// phpcs:ignore Magento2.Security.InsecureFunction
'identity' => md5('bulk' . $bulkUuid),
'uuid' => $bulkUuid,
'status' => $bulkStatus,
'created_at' => $bulk->getStartTime()
]
];
$messagesCount++;
}
$data = [
'data' => [
'text' => __('Task "%1": ', $bulk->getDescription()) . $text,
'severity' => \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR,
// md5() here is not for cryptographic use.
// phpcs:ignore Magento2.Security.InsecureFunction
'identity' => md5('bulk' . $bulkUuid),
'uuid' => $bulkUuid,
'status' => $bulkStatus,
'created_at' => $bulk->getStartTime()
]
];
$bulkMessages[] = $this->messageFactory->create($data)->toArray();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
class PluginTest extends TestCase
{
private const MESSAGES_LIMIT = 5;
/**
* @var Plugin
*/
Expand Down Expand Up @@ -163,6 +164,60 @@ public function testAfterTo($operationDetails)
$this->assertEquals(2, $result2['totalRecords']);
}

/**
* Tests that message building operations don't get called more than Plugin::MESSAGES_LIMIT times
*
* @return void
*/
public function testAfterToWithMessageLimit()
{
$result = ['items' =>[], 'totalRecords' => 1];
$messagesCount = self::MESSAGES_LIMIT + 1;
$userId = 1;
$bulkUuid = 2;
$bulkArray = [
'status' => BulkSummaryInterface::NOT_STARTED
];

$bulkMock = $this->getMockBuilder(BulkSummary::class)
->addMethods(['getStatus'])
->onlyMethods(['getBulkId', 'getDescription', 'getStartTime'])
->disableOriginalConstructor()
->getMock();
$userBulks = array_fill(0, $messagesCount, $bulkMock);
$bulkMock->expects($this->exactly($messagesCount))
->method('getBulkId')->willReturn($bulkUuid);
$this->operationsDetailsMock
->expects($this->exactly(self::MESSAGES_LIMIT))
->method('getDetails')
->with($bulkUuid)
->willReturn([
'operations_successful' => 1,
'operations_failed' => 0
]);
$bulkMock->expects($this->exactly(self::MESSAGES_LIMIT))
->method('getDescription')->willReturn('Bulk Description');
$this->messagefactoryMock->expects($this->exactly($messagesCount))
->method('create')->willReturn($this->messageMock);
$this->messageMock->expects($this->exactly($messagesCount))->method('toArray')->willReturn($bulkArray);
$this->authorizationMock
->expects($this->once())
->method('isAllowed')
->with($this->resourceName)
->willReturn(true);
$this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId);
$this->bulkNotificationMock
->expects($this->once())
->method('getAcknowledgedBulksByUser')
->with($userId)
->willReturn([]);
$this->statusMapper->expects($this->exactly(self::MESSAGES_LIMIT))
->method('operationStatusToBulkSummaryStatus');
$this->bulkStatusMock->expects($this->once())->method('getBulksByUser')->willReturn($userBulks);
$result2 = $this->plugin->afterToArray($this->collectionMock, $result);
$this->assertEquals($result['totalRecords'] + $messagesCount, $result2['totalRecords']);
}

/**
* @return array
*/
Expand Down
43 changes: 30 additions & 13 deletions app/code/Magento/Catalog/Block/Adminhtml/Category/Tab/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Category\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid;
use Magento\Backend\Block\Widget\Grid\Column;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Helper\Data;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ProductFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Registry;

class Product extends \Magento\Backend\Block\Widget\Grid\Extended
class Product extends Extended
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
* @var Registry
*/
protected $_coreRegistry = null;

/**
* @var \Magento\Catalog\Model\ProductFactory
* @var ProductFactory
*/
protected $_productFactory;

Expand All @@ -43,19 +45,19 @@ class Product extends \Magento\Backend\Block\Widget\Grid\Extended
private $visibility;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param \Magento\Framework\Registry $coreRegistry
* @param Context $context
* @param Data $backendHelper
* @param ProductFactory $productFactory
* @param Registry $coreRegistry
* @param array $data
* @param Visibility|null $visibility
* @param Status|null $status
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\Framework\Registry $coreRegistry,
Context $context,
Data $backendHelper,
ProductFactory $productFactory,
Registry $coreRegistry,
array $data = [],
Visibility $visibility = null,
Status $status = null
Expand All @@ -68,6 +70,8 @@ public function __construct(
}

/**
* Initialize object
*
* @return void
*/
protected function _construct()
Expand All @@ -79,6 +83,8 @@ protected function _construct()
}

/**
* Get current category
*
* @return array|null
*/
public function getCategory()
Expand All @@ -87,6 +93,8 @@ public function getCategory()
}

/**
* Add column filter to collection
*
* @param Column $column
* @return $this
*/
Expand All @@ -110,6 +118,8 @@ protected function _addColumnFilterToCollection($column)
}

/**
* Prepare collection.
*
* @return Grid
*/
protected function _prepareCollection()
Expand All @@ -136,6 +146,7 @@ protected function _prepareCollection()
'left'
);
$storeId = (int)$this->getRequest()->getParam('store', 0);
$collection->setStoreId($storeId);
if ($storeId > 0) {
$collection->addStoreFilter($storeId);
}
Expand All @@ -153,6 +164,8 @@ protected function _prepareCollection()
}

/**
* Prepare columns.
*
* @return Extended
*/
protected function _prepareColumns()
Expand Down Expand Up @@ -230,6 +243,8 @@ protected function _prepareColumns()
}

/**
* Retrieve grid reload url
*
* @return string
*/
public function getGridUrl()
Expand All @@ -238,6 +253,8 @@ public function getGridUrl()
}

/**
* Get selected products
*
* @return array
*/
protected function _getSelectedProducts()
Expand Down
14 changes: 8 additions & 6 deletions app/code/Magento/CustomerImportExport/Model/Import/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
namespace Magento\CustomerImportExport\Model\Import;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\ImportExport\Model\Import\AbstractSource;
use Magento\Customer\Model\Indexer\Processor;
use Magento\Framework\App\ObjectManager;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\Import\AbstractSource;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;

/**
* Customer entity import
Expand Down Expand Up @@ -162,6 +162,7 @@ class Customer extends AbstractCustomer
'failures_num',
'first_failure',
'lock_expires',
CustomerInterface::DISABLE_AUTO_GROUP_CHANGE,
];

/**
Expand Down Expand Up @@ -413,7 +414,6 @@ protected function _prepareDataForUpdate(array $rowData)
} else {
$createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
}

$emailInLowercase = strtolower(trim($rowData[self::COLUMN_EMAIL]));
$newCustomer = false;
$entityId = $this->_getCustomerId($emailInLowercase, $rowData[self::COLUMN_WEBSITE]);
Expand Down Expand Up @@ -448,7 +448,6 @@ protected function _prepareDataForUpdate(array $rowData)
$value = (new \DateTime())->setTimestamp(strtotime($value));
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
}

if (!$this->_attributes[$attributeCode]['is_static']) {
/** @var $attribute \Magento\Customer\Model\Attribute */
$attribute = $this->_customerModel->getAttribute($attributeCode);
Expand Down Expand Up @@ -488,9 +487,12 @@ protected function _prepareDataForUpdate(array $rowData)
} else {
$entityRow['store_id'] = $this->getCustomerStoreId($emailInLowercase, $rowData[self::COLUMN_WEBSITE]);
}
if (!empty($rowData[CustomerInterface::DISABLE_AUTO_GROUP_CHANGE])) {
$entityRow[CustomerInterface::DISABLE_AUTO_GROUP_CHANGE] =
$rowData[CustomerInterface::DISABLE_AUTO_GROUP_CHANGE];
}
$entitiesToUpdate[] = $entityRow;
}

return [
self::ENTITIES_TO_CREATE_KEY => $entitiesToCreate,
self::ENTITIES_TO_UPDATE_KEY => $entitiesToUpdate,
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Sales/Model/Order/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ public function isLast()
{
$items = $this->getAllItems();
foreach ($items as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}

if (!$item->isLast()) {
return false;
}
Expand Down
37 changes: 37 additions & 0 deletions app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Sales\Model\Order\Creditmemo\CommentFactory;
use Magento\Sales\Model\Order\Creditmemo\Config;
use Magento\Sales\Model\Order\Creditmemo\Item;
use Magento\Sales\Model\Order\Item as OrderItem;
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Item\Collection as ItemCollection;
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Item\CollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -201,4 +202,40 @@ public function testGetItemsCollectionWithoutId()
$itemsCollection = $this->creditmemo->getItemsCollection();
$this->assertEquals($items, $itemsCollection);
}

public function testIsLastForLastCreditMemo(): void
{
$item = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock();
$orderItem = $this->getMockBuilder(OrderItem::class)->disableOriginalConstructor()->getMock();
$orderItem
->expects($this->once())
->method('isDummy')
->willReturn(true);
$item->expects($this->once())
->method('getOrderItem')
->willReturn($orderItem);
$this->creditmemo->setItems([$item]);
$this->assertTrue($this->creditmemo->isLast());
}

public function testIsLastForNonLastCreditMemo(): void
{
$item = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock();
$orderItem = $this->getMockBuilder(OrderItem::class)->disableOriginalConstructor()->getMock();
$orderItem
->expects($this->once())
->method('isDummy')
->willReturn(false);
$item->expects($this->once())
->method('getOrderItem')
->willReturn($orderItem);
$item->expects($this->once())
->method('getOrderItem')
->willReturn($orderItem);
$item->expects($this->once())
->method('isLast')
->willReturn(false);
$this->creditmemo->setItems([$item]);
$this->assertFalse($this->creditmemo->isLast());
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/SalesRule/Model/Quote/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function collect(
$address->setCartFixedRules([]);
$quote->setCartFixedRules([]);
foreach ($items as $item) {
$this->rulesApplier->setAppliedRuleIds($item, []);
$item->setAppliedRuleIds(null);
if ($item->getExtensionAttributes()) {
$item->getExtensionAttributes()->setDiscounts(null);
}
Expand Down
Loading

0 comments on commit 70a0b88

Please sign in to comment.