Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#19260: Issue magento#19205 Fixed: Bundle Product Option with input type is checkbox and add to cart with 3 values only 2 values added to cart. (by @maheshWebkul721)
 - magento#19237: [Backport] magento#18956 Fixes for set root_category_id (by @gelanivishal)
 - magento#19240: [Backport] Add missing unit test for WishlistSettings plugin (by @gelanivishal)
 - magento#19216: [Backport] Covering the \Magento\Weee observers by Unit Tests (by @eduard13)
 - magento#19217: [Backport] Covering the CheckUserLoginBackendObserver by Unit Test (by @eduard13)
 - magento#18808: fixed Quote Item Prices are NULL in cart related events. magento#18685 (by @ashutoshwebkul)
 - magento#16342: magento#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does� (by @novikor)


Fixed GitHub Issues:
 - magento#19205: Bundle Product Option with input type is checkbox and add to cart with 3 values only 2 values added to cart (reported by @sneha-panchal) has been fixed in magento#19260 by @maheshWebkul721 in 2.2-develop branch
   Related commits:
     1. aa379ea
     2. 1a321d2

 - magento#18956: Import of RootCategoryId should be possbile (Magento/Store/Model/Config/Importer/Processor/Create.php) (reported by @larsroettig) has been fixed in magento#19237 by @gelanivishal in 2.2-develop branch
   Related commits:
     1. aa4abec
     2. acefdb3
     3. 5866a39
     4. fee2712
     5. 7be21e2

 - magento#18685: Quote Item Prices are NULL in cart related events. (reported by @qsolutions-pl) has been fixed in magento#18808 by @ashutoshwebkul in 2.2-develop branch
   Related commits:
     1. 09586e4
     2. 1638891
     3. 175ebc0
     4. 59bd874

 - magento#14020: Cart Sales Rule with negated condition over special_price does not work for configurable products (reported by @Filipe-Bicho) has been fixed in magento#16342 by @novikor in 2.2-develop branch
   Related commits:
     1. 90b6803
     2. 2717cb1
     3. d2a0de8
     4. fae98c0
     5. 9a35b45
     6. 887ee4a
     7. 0c9aa81
     8. 4e68337
     9. 5b95b22
     10. 618f408
     11. 7c8482b
     12. e7130bf
     13. 5a7e78a
     14. 8d417ac
     15. 90ff989
     16. c52e0e8
     17. 5c3154b
     18. 51adb9d
  • Loading branch information
VladimirZaets authored Nov 21, 2018
2 parents b1e26d5 + 9945dc7 commit 32a7c4b
Show file tree
Hide file tree
Showing 16 changed files with 840 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ private function recursiveIntval(array $array)
private function multiToFlatArray(array $array)
{
$flatArray = [];
foreach ($array as $key => $value) {
foreach ($array as $value) {
if (is_array($value)) {
$flatArray = array_merge($flatArray, $this->multiToFlatArray($value));
} else {
$flatArray[$key] = $value;
$flatArray[] = $value;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Captcha\Test\Unit\Observer;

use Magento\Captcha\Helper\Data;
use Magento\Captcha\Model\DefaultModel;
use Magento\Captcha\Observer\CaptchaStringResolver;
use Magento\Captcha\Observer\CheckUserLoginBackendObserver;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Framework\Message\ManagerInterface;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class CheckUserLoginBackendObserverTest
*/
class CheckUserLoginBackendObserverTest extends TestCase
{
/**
* @var CheckUserLoginBackendObserver
*/
private $observer;

/**
* @var ManagerInterface|MockObject
*/
private $messageManagerMock;

/**
* @var CaptchaStringResolver|MockObject
*/
private $captchaStringResolverMock;

/**
* @var RequestInterface|MockObject
*/
private $requestMock;

/**
* @var Data|MockObject
*/
private $helperMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->helperMock = $this->createMock(Data::class);
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
$this->captchaStringResolverMock = $this->createMock(CaptchaStringResolver::class);
$this->requestMock = $this->createMock(RequestInterface::class);

$this->observer = new CheckUserLoginBackendObserver(
$this->helperMock,
$this->captchaStringResolverMock,
$this->requestMock
);
}

/**
* Test check user login in backend with correct captcha
*
* @dataProvider requiredCaptchaDataProvider
* @param bool $isRequired
* @return void
*/
public function testCheckOnBackendLoginWithCorrectCaptcha(bool $isRequired)
{
$formId = 'backend_login';
$login = 'admin';
$captchaValue = 'captcha-value';

/** @var Observer|MockObject $observerMock */
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
$captcha = $this->createMock(DefaultModel::class);

$eventMock->method('getUsername')->willReturn('admin');
$observerMock->method('getEvent')->willReturn($eventMock);
$captcha->method('isRequired')->with($login)->willReturn($isRequired);
$captcha->method('isCorrect')->with($captchaValue)->willReturn(true);
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
->willReturn($captchaValue);

$this->observer->execute($observerMock);
}

/**
* @return array
*/
public function requiredCaptchaDataProvider(): array
{
return [
[true],
[false]
];
}

/**
* Test check user login in backend with wrong captcha
*
* @return void
* @expectedException \Magento\Framework\Exception\Plugin\AuthenticationException
*/
public function testCheckOnBackendLoginWithWrongCaptcha()
{
$formId = 'backend_login';
$login = 'admin';
$captchaValue = 'captcha-value';

/** @var Observer|MockObject $observerMock */
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
$captcha = $this->createMock(DefaultModel::class);

$eventMock->method('getUsername')->willReturn($login);
$observerMock->method('getEvent')->willReturn($eventMock);
$captcha->method('isRequired')->with($login)->willReturn(true);
$captcha->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
->willReturn($captchaValue);

$this->observer->execute($observerMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;

/**
* Class Product
*
* @package Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition
*/
class Product
{
/**
* @param \Magento\SalesRule\Model\Rule\Condition\Product $subject
* @param \Magento\Framework\Model\AbstractModel $model
*/
public function beforeValidate(
\Magento\SalesRule\Model\Rule\Condition\Product $subject,
\Magento\Framework\Model\AbstractModel $model
) {
$product = $this->getProductToValidate($subject, $model);
if ($model->getProduct() !== $product) {
// We need to replace product only for validation and keep original product for all other cases.
$clone = clone $model;
$clone->setProduct($product);
$model = $clone;
}

return [$model];
}

/**
* @param \Magento\SalesRule\Model\Rule\Condition\Product $subject
* @param \Magento\Framework\Model\AbstractModel $model
*
* @return \Magento\Catalog\Api\Data\ProductInterface|\Magento\Catalog\Model\Product
*/
private function getProductToValidate(
\Magento\SalesRule\Model\Rule\Condition\Product $subject,
\Magento\Framework\Model\AbstractModel $model
) {
/** @var \Magento\Catalog\Model\Product $product */
$product = $model->getProduct();

$attrCode = $subject->getAttribute();

/* Check for attributes which are not available for configurable products */
if ($product->getTypeId() == Configurable::TYPE_CODE && !$product->hasData($attrCode)) {
/** @var \Magento\Catalog\Model\AbstractModel $childProduct */
$childProduct = current($model->getChildren())->getProduct();
if ($childProduct->hasData($attrCode)) {
$product = $childProduct;
}
}

return $product;
}
}
36 changes: 33 additions & 3 deletions app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;

/**
* Upgrade Data script
Expand Down Expand Up @@ -62,6 +62,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
}
}

if (version_compare($context->getVersion(), '2.2.2', '<')) {
$this->upgradeQuoteItemPrice($setup);
}

$setup->endSetup();
}

Expand Down Expand Up @@ -97,4 +101,30 @@ private function updateRelatedProductTypes(string $attributeId, array $relatedPr
implode(',', $relatedProductTypes)
);
}

/**
* Update 'price' value for quote items without price of configurable products subproducts.
*
* @param ModuleDataSetupInterface $setup
*/
private function upgradeQuoteItemPrice(ModuleDataSetupInterface $setup)
{
$connection = $setup->getConnection();
$quoteItemTable = $setup->getTable('quote_item');
$select = $connection->select();
$select->joinLeft(
['qi2' => $quoteItemTable],
'qi1.parent_item_id = qi2.item_id',
['price']
)->where(
'qi1.price = 0'
. ' AND qi1.parent_item_id IS NOT NULL'
. ' AND qi2.product_type = "' . Configurable::TYPE_CODE . '"'
);
$updateQuoteItem = $setup->getConnection()->updateFromSelect(
$select,
['qi1' => $quoteItemTable]
);
$setup->getConnection()->query($updateQuoteItem);
}
}
Loading

0 comments on commit 32a7c4b

Please sign in to comment.