Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3405 from magento-chaika/chaika_november
Browse files Browse the repository at this point in the history
[Chaika] Bugfixes
  • Loading branch information
Lysenko Olexandr authored Nov 6, 2018
2 parents 2a389b0 + 9c5ade5 commit 53a8966
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ define([
var checkoutConfig = window.checkoutConfig,
validators = [],
observedElements = [],
postcodeElement = null,
postcodeElementName = 'postcode';

validators.push(defaultValidator);
Expand Down Expand Up @@ -79,7 +78,11 @@ define([
}

$.each(elements, function (index, field) {
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
var elementBinding = self.doElementBinding.bind(self),
fullPath = formPath + '.' + field,
func = uiRegistry.async(fullPath);

func(elementBinding);
});
},

Expand All @@ -101,7 +104,6 @@ define([

if (element.index === postcodeElementName) {
this.bindHandler(element, delay);
postcodeElement = element;
}
},

Expand Down Expand Up @@ -136,7 +138,7 @@ define([
if (!formPopUpState.isVisible()) {
clearTimeout(self.validateAddressTimeout);
self.validateAddressTimeout = setTimeout(function () {
self.postcodeValidation();
self.postcodeValidation(element);
self.validateFields();
}, delay);
}
Expand All @@ -148,7 +150,7 @@ define([
/**
* @return {*}
*/
postcodeValidation: function () {
postcodeValidation: function (postcodeElement) {
var countryId = $('select[name="country_id"]').val(),
validationResult,
warnMessage;
Expand Down Expand Up @@ -178,8 +180,8 @@ define([
*/
validateFields: function () {
var addressFlat = addressConverter.formDataProviderToFlatData(
this.collectObservedData(),
'shippingAddress'
this.collectObservedData(),
'shippingAddress'
),
address;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ define([
'Magento_Customer/js/customer-data',
'Magento_Checkout/js/action/set-billing-address',
'Magento_Ui/js/model/messageList',
'mage/translate'
'mage/translate',
'Magento_Checkout/js/model/shipping-rates-validator'
],
function (
ko,
Expand All @@ -33,7 +34,8 @@ function (
customerData,
setBillingAddressAction,
globalMessageList,
$t
$t,
shippingRatesValidator
) {
'use strict';

Expand Down Expand Up @@ -71,6 +73,7 @@ function (
quote.paymentMethod.subscribe(function () {
checkoutDataResolver.resolveBillingAddress();
}, this);
shippingRatesValidator.initFields(this.get('name') + '.form-fields');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Catalog\Model\Product;
use Magento\Store\Model\ScopeInterface;

/**
* {@inheritdoc}
* Resolves the product from a configured item.
*/
class ItemProductResolver implements ItemResolverInterface
{
/**
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
*/
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';
public const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';

/**
* @var ScopeConfigInterface
Expand All @@ -38,27 +39,21 @@ public function __construct(ScopeConfigInterface $scopeConfig)
}

/**
* {@inheritdoc}
* Get the final product from a configured item by product type and selection.
*
* @param ItemInterface $item
* @return ProductInterface
*/
public function getFinalProduct(ItemInterface $item) : ProductInterface
public function getFinalProduct(ItemInterface $item): ProductInterface
{
/**
* Show parent product thumbnail if it must be always shown according to the related setting in system config
* or if child thumbnail is not available.
*/
$parentProduct = $item->getProduct();
$finalProduct = $parentProduct;
$finalProduct = $item->getProduct();
$childProduct = $this->getChildProduct($item);
if ($childProduct !== $parentProduct) {
$configValue = $this->scopeConfig->getValue(
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$childThumb = $childProduct->getData('thumbnail');
$finalProduct =
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
? $parentProduct
: $childProduct;
if ($childProduct !== null && $this->isUseChildProduct($childProduct)) {
$finalProduct = $childProduct;
}
return $finalProduct;
}
Expand All @@ -67,15 +62,30 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
* Get item configurable child product.
*
* @param ItemInterface $item
* @return Product
* @return Product | null
*/
private function getChildProduct(ItemInterface $item) : Product
private function getChildProduct(ItemInterface $item): ?Product
{
/** @var \Magento\Quote\Model\Quote\Item\Option $option */
$option = $item->getOptionByCode('simple_product');
$product = $item->getProduct();
if ($option) {
$product = $option->getProduct();
}
return $product;
return $option ? $option->getProduct() : null;
}

/**
* Is need to use child product
*
* @param Product $childProduct
* @return bool
*/
private function isUseChildProduct(Product $childProduct): bool
{
$configValue = $this->scopeConfig->getValue(
self::CONFIG_THUMBNAIL_SOURCE,
ScopeInterface::SCOPE_STORE
);
$childThumb = $childProduct->getData('thumbnail');
return $configValue !== Thumbnail::OPTION_USE_PARENT_IMAGE
&& $childThumb !== null
&& $childThumb !== 'no_selection';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Model\Product\Configuration\Item;

use Magento\Catalog\Model\Config\Source\Product\Thumbnail;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Quote\Model\Quote\Item\Option;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ItemProductResolverTest extends TestCase
{
/** @var ItemProductResolver */
private $model;
/** @var ItemInterface | MockObject */
private $item;
/** @var Product | MockObject */
private $parentProduct;
/** @var ScopeConfigInterface | MockObject */
private $scopeConfig;
/** @var OptionInterface | MockObject */
private $option;
/** @var Product | MockObject */
private $childProduct;

/**
* Set up method
*/
protected function setUp()
{
parent::setUp();

$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
->disableOriginalConstructor()
->getMock();

$this->parentProduct = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
$this->parentProduct
->method('getSku')
->willReturn('parent_product');

$this->childProduct = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
$this->childProduct
->method('getSku')
->willReturn('child_product');

$this->option = $this->getMockBuilder(Option::class)
->disableOriginalConstructor()
->getMock();

$this->option
->method('getProduct')
->willReturn($this->childProduct);

$this->item = $this->getMockBuilder(ItemInterface::class)
->disableOriginalConstructor()
->getMock();

$this->item
->expects($this->once())
->method('getProduct')
->willReturn($this->parentProduct);

$this->model = new ItemProductResolver($this->scopeConfig);
}

/**
* Test for deleted child product from configurable product
*/
public function testGetFinalProductChildIsNull(): void
{
$this->scopeConfig->expects($this->never())->method('getValue');
$this->childProduct->expects($this->never())->method('getData');

$this->item->expects($this->once())
->method('getOptionByCode')
->willReturn(null);

$finalProduct = $this->model->getFinalProduct($this->item);
$this->assertEquals(
$this->parentProduct->getSku(),
$finalProduct->getSku()
);
}

/**
* Tests child product from configurable product
*
* @dataProvider provideScopeConfig
* @param string $expectedSku
* @param string $scopeValue
* @param string | null $thumbnail
*/
public function testGetFinalProductChild($expectedSku, $scopeValue, $thumbnail): void
{
$this->item->expects($this->once())
->method('getOptionByCode')
->willReturn($this->option);

$this->childProduct
->expects($this->once())
->method('getData')
->willReturn($thumbnail);

$this->scopeConfig->expects($this->once())
->method('getValue')
->willReturn($scopeValue);

$finalProduct = $this->model->getFinalProduct($this->item);
$this->assertEquals($expectedSku, $finalProduct->getSku());
}

/**
* Dataprovider for scope test
* @return array
*/
public function provideScopeConfig(): array
{
return [
['child_product', Thumbnail::OPTION_USE_OWN_IMAGE, 'thumbnail'],
['parent_product', Thumbnail::OPTION_USE_PARENT_IMAGE, 'thumbnail'],

['parent_product', Thumbnail::OPTION_USE_OWN_IMAGE, null],
['parent_product', Thumbnail::OPTION_USE_OWN_IMAGE, 'no_selection'],

['parent_product', Thumbnail::OPTION_USE_PARENT_IMAGE, null],
['parent_product', Thumbnail::OPTION_USE_PARENT_IMAGE, 'no_selection'],
];
}
}
8 changes: 5 additions & 3 deletions app/code/Magento/Integration/Plugin/Model/AdminUser.php
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.
*/

namespace Magento\Integration\Plugin\Model;

use Magento\Integration\Model\AdminTokenService;
Expand Down Expand Up @@ -31,14 +32,15 @@ public function __construct(
*
* @param \Magento\User\Model\User $subject
* @param \Magento\Framework\DataObject $object
* @return $this
* @return \Magento\User\Model\User
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function afterSave(
\Magento\User\Model\User $subject,
\Magento\Framework\DataObject $object
) {
): \Magento\User\Model\User {
$isActive = $object->getIsActive();
if (isset($isActive) && $isActive == 0) {
if ($isActive !== null && $isActive == 0) {
$this->adminTokenService->revokeAdminAccessToken($object->getId());
}
return $subject;
Expand Down
Loading

0 comments on commit 53a8966

Please sign in to comment.