Skip to content

Commit

Permalink
Merge pull request #1 from magento/2.2-develop
Browse files Browse the repository at this point in the history
2.2 develop
  • Loading branch information
lisovyievhenii authored Nov 11, 2018
2 parents 0d99fa8 + 17f7686 commit 9688409
Show file tree
Hide file tree
Showing 54 changed files with 1,118 additions and 253 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Controller/Adminhtml/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class Index extends \Magento\Backend\App\Action
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Backend::backup';
const ADMIN_RESOURCE = 'Magento_Backup::backup';

/**
* Core registry
Expand Down
19 changes: 13 additions & 6 deletions app/code/Magento/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
Expand Down Expand Up @@ -269,7 +270,8 @@ public function setStoreId($store)

/**
* Return current category path or get it from current category
* and creating array of categories|product paths for breadcrumbs
*
* Creating array of categories|product paths for breadcrumbs
*
* @return array
*/
Expand Down Expand Up @@ -378,6 +380,7 @@ public function getLastViewedUrl()

/**
* Split SKU of an item by dashes and spaces
*
* Words will not be broken, unless this length is greater than $length
*
* @param string $sku
Expand Down Expand Up @@ -406,14 +409,15 @@ public function getAttributeHiddenFields()
/**
* Retrieve Catalog Price Scope
*
* @return int
* @return int|null
*/
public function getPriceScope()
{
return $this->scopeConfig->getValue(
$priceScope = $this->scopeConfig->getValue(
self::XML_PATH_PRICE_SCOPE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
ScopeInterface::SCOPE_STORE
);
return isset($priceScope) ? (int)$priceScope : null;
}

/**
Expand Down Expand Up @@ -449,7 +453,7 @@ public function isUrlDirectivesParsingAllowed()
{
return $this->scopeConfig->isSetFlag(
self::CONFIG_PARSE_URL_DIRECTIVES,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$this->_storeId
);
}
Expand All @@ -466,19 +470,22 @@ public function getPageTemplateProcessor()

/**
* Whether to display items count for each filter option
*
* @param int $storeId Store view ID
* @return bool
*/
public function shouldDisplayProductCountOnLayer($storeId = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* Convert tax address array to address data object with country id and postcode
*
* @param array $taxAddress
* @return \Magento\Customer\Api\Data\AddressInterface|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public function execute($entity, $arguments = [])
__('Tier prices data should be array, but actually other type is received')
);
}
$websiteId = $this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
$websiteId = (int)$this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
$isGlobal = $attribute->isScopeGlobal() || $websiteId === 0;
$identifierField = $this->metadataPoll->getMetadata(ProductInterface::class)->getLinkField();
$productId = $entity->getData($identifierField);
$productId = (int)$entity->getData($identifierField);

// prepare original data to compare
$origPrices = $entity->getOrigData($attribute->getName());
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
$old = $this->prepareOldTierPriceToCompare($origPrices);
// prepare data for save
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);

Expand Down Expand Up @@ -262,19 +262,18 @@ private function isWebsiteGlobal(int $websiteId): bool
}

/**
* Prepare old data to compare.
*
* @param array|null $origPrices
* @param bool $isGlobal
* @return array
*/
private function prepareOriginalDataToCompare($origPrices, $isGlobal = true): array
private function prepareOldTierPriceToCompare($origPrices): array
{
$old = [];
if (is_array($origPrices)) {
foreach ($origPrices as $data) {
if ($isGlobal === $this->isWebsiteGlobal((int)$data['website_id'])) {
$key = $this->getPriceKey($data);
$old[$key] = $data;
}
$key = $this->getPriceKey($data);
$old[$key] = $data;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function testGetWithNonExistingProduct()

/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedExceptionText Such image doesn't exist
* @expectedExceptionMessage Such image doesn't exist
*/
public function testGetWithNonExistingImage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function setUp()

/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedMessage This product doesn't have tier price
* @expectedExceptionMessage Product hasn't group price with such data: customerGroupId = '1', website = 1, qty = 3
*/
public function testRemoveWhenTierPricesNotExists()
{
Expand All @@ -72,7 +72,7 @@ public function testRemoveWhenTierPricesNotExists()

/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedMessage For current customerGroupId = '10' with 'qty' = 15 any tier price exist'.
* @expectedExceptionMessage Product hasn't group price with such data: customerGroupId = '10', website = 1, qty = 5
*/
public function testRemoveTierPriceForNonExistingCustomerGroup()
{
Expand All @@ -83,7 +83,7 @@ public function testRemoveTierPriceForNonExistingCustomerGroup()
->will($this->returnValue($this->prices));
$this->productMock->expects($this->never())->method('setData');
$this->productRepositoryMock->expects($this->never())->method('save');
$this->priceModifier->removeTierPrice($this->productMock, 10, 15, 1);
$this->priceModifier->removeTierPrice($this->productMock, 10, 5, 1);
}

public function testSuccessfullyRemoveTierPriceSpecifiedForAllGroups()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function testSuccessDeleteTierPrice()

/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @message Such product doesn't exist
* @expectedExceptionMessage No such entity.
*/
public function testDeleteTierPriceFromNonExistingProduct()
{
Expand Down
15 changes: 11 additions & 4 deletions app/code/Magento/Catalog/view/frontend/web/js/product/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

define([
'underscore',
'jquery',
'mageUtils',
'uiElement',
'Magento_Catalog/js/product/storage/storage-service',
'Magento_Customer/js/customer-data'
], function (_, utils, Element, storage, customerData) {
'Magento_Customer/js/customer-data',
'Magento_Catalog/js/product/view/product-ids-resolver'
], function (_, $, utils, Element, storage, customerData, productResolver) {
'use strict';

return Element.extend({
Expand Down Expand Up @@ -135,11 +137,16 @@ define([
*/
filterIds: function (ids) {
var _ids = {},
currentTime = new Date().getTime() / 1000;
currentTime = new Date().getTime() / 1000,
currentProductIds = productResolver($('#product_addtocart_form'));

_.each(ids, function (id) {
if (currentTime - id['added_at'] < ~~this.idsStorage.lifetime) {
if (
currentTime - id['added_at'] < ~~this.idsStorage.lifetime &&
!_.contains(currentProductIds, id['product_id'])
) {
_ids[id['product_id']] = id;

}
}, this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public function execute()
['request' => $this->getRequest()]
);
$data = $this->getRequest()->getPostValue();

$filterValues = ['from_date' => $this->_dateFilter];
if ($this->getRequest()->getParam('to_date')) {
$filterValues['to_date'] = $this->_dateFilter;
}
$inputFilter = new \Zend_Filter_Input(
$filterValues,
[],
$data
);
$data = $inputFilter->getUnescaped();
$id = $this->getRequest()->getParam('rule_id');
if ($id) {
$model = $ruleRepository->get($id);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/Test/Unit/Model/SidebarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testCheckQuoteItem()

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @exceptedExceptionMessage We can't find the quote item.
* @expectedExceptionMessage We can't find the quote item.
*/
public function testCheckQuoteItemWithException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ define([
if (countryId) {
if (addressData.region && addressData.region['region_id']) {
regionId = addressData.region['region_id'];
} else if (!addressData['region_id']) {
regionId = undefined;
} else if (countryId === window.checkoutConfig.defaultCountryId) {
regionId = window.checkoutConfig.defaultRegionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function getVariationMatrix()
$configurableMatrix = json_decode($configurableMatrix, true);

foreach ($configurableMatrix as $item) {
if ($item['newProduct']) {
if (isset($item['newProduct']) && $item['newProduct']) {
$result[$item['variationKey']] = $this->mapData($item);

if (isset($item['qty'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
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
{
Expand All @@ -38,28 +39,22 @@ 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
{
/**
* 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 @@ -69,17 +64,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)
{
$option = $item->getOptionByCode('simple_product');
$product = $item->getProduct();

if ($option) {
$product = $option->getProduct();
}
return $option ? $option->getProduct() : null;
}

return $product;
/**
* 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';
}
}
Loading

0 comments on commit 9688409

Please sign in to comment.