Skip to content

Commit

Permalink
Merge pull request #6049 from magento-tsg-csl3/2.4-develop-pr38
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr38)
  • Loading branch information
zakdma authored Aug 20, 2020
2 parents eb50002 + a89f35d commit b0eec73
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 53 deletions.
14 changes: 14 additions & 0 deletions app/code/Magento/Customer/view/frontend/web/js/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ define([
], function ($, moment, utils) {
'use strict';

$.validator.addMethod(
'validate-date',
function (value, element, params) {
var dateFormat = utils.convertToMomentFormat(params.dateFormat);

if (value === '') {
return true;
}

return moment(value, dateFormat, true).isValid();
},
$.mage.__('Invalid date')
);

$.validator.addMethod(
'validate-dob',
function (value, element, params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Reports\Model\ResourceModel\Quote\Item;

Expand All @@ -17,6 +18,8 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
private const PREPARED_FLAG_NAME = 'reports_collection_prepared';

/**
* Join fields
*
Expand Down Expand Up @@ -99,6 +102,11 @@ protected function _construct()
public function prepareActiveCartItems()
{
$quoteItemsSelect = $this->getSelect();

if ($this->getFlag(self::PREPARED_FLAG_NAME)) {
return $quoteItemsSelect;
}

$quoteItemsSelect->reset()
->from(['main_table' => $this->getTable('quote_item')], '')
->columns('main_table.product_id')
Expand All @@ -114,6 +122,7 @@ public function prepareActiveCartItems()
)->group(
'main_table.product_id'
);
$this->setFlag(self::PREPARED_FLAG_NAME, true);

return $quoteItemsSelect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Model\ResourceModel\Quote;
use Magento\Reports\Model\ResourceModel\Quote\Collection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -42,7 +43,7 @@ protected function setUp(): void
public function testGetSelectCountSql()
{
/** @var MockObject $collection */
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Collection::class)
$collection = $this->getMockBuilder(Collection::class)
->setMethods(['getSelect'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -62,20 +63,25 @@ public function testPrepareActiveCartItems()
$constructArgs = $this->objectManager
->getConstructArguments(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class);
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class)
->setMethods(['getSelect', 'getTable'])
->setMethods(['getSelect', 'getTable', 'getFlag', 'setFlag'])
->disableOriginalConstructor()
->setConstructorArgs($constructArgs)
->getMock();

$collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
$collection->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
$this->selectMock->expects($this->once())->method('reset')->willReturnSelf();
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
$this->selectMock->expects($this->atLeastOnce())->method('columns')->willReturnSelf();
$this->selectMock->expects($this->once())->method('joinInner')->willReturnSelf();
$this->selectMock->expects($this->once())->method('where')->willReturnSelf();
$this->selectMock->expects($this->once())->method('group')->willReturnSelf();
$collection->expects($this->exactly(2))->method('getTable')->willReturn('table');
$collection->expects($this->once())->method('setFlag')
->with('reports_collection_prepared')->willReturnSelf();
$collection->prepareActiveCartItems();
$collection->method('getFlag')
->with('reports_collection_prepared')->willReturn(true);
$this->assertEquals($this->selectMock, $collection->prepareActiveCartItems());
}

public function testLoadWithFilter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\Sales\Model\Order;

/**
* Class State
* Checking order status and adjusting order status before saving
*/
class State
{
Expand All @@ -34,6 +34,7 @@ public function check(Order $order)
if (in_array($currentState, [Order::STATE_PROCESSING, Order::STATE_COMPLETE])
&& !$order->canCreditmemo()
&& !$order->canShip()
&& $order->getIsNotVirtual()
) {
$order->setState(Order::STATE_CLOSED)
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CLOSED));
Expand Down
Loading

0 comments on commit b0eec73

Please sign in to comment.