Skip to content

Commit

Permalink
Merge pull request #1518 from magento-mpi/MPI-PR-2.1.10
Browse files Browse the repository at this point in the history
[MPI] 2.1.10 Bug fixes
  • Loading branch information
viktym authored Sep 26, 2017
2 parents fa59b15 + 9759929 commit de49e22
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@
type="submit"
data-bind="
click: placeOrderClick,
attr: {title: $t('Place Order')}
">
attr: {title: $t('Place Order')},
css: {disabled: !isPlaceOrderActionAllowed()},
enable: isActive()
"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
Expand Down
51 changes: 35 additions & 16 deletions app/code/Magento/Catalog/Cron/DeleteOutdatedPriceValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* Cron operation is responsible for deleting all product prices on WEBSITE level
* in case 'Catalog Price Scope' configuratoin parameter is set to GLOBAL.
* in case 'Catalog Price Scope' configuration parameter is set to GLOBAL.
*/
class DeleteOutdatedPriceValues
{
Expand Down Expand Up @@ -48,27 +48,46 @@ public function __construct(
}

/**
* Delete all price values for non-admin stores if PRICE_SCOPE is global
* Delete all price values for non-admin stores if PRICE_SCOPE is set to global.
*
* @return void
*/
public function execute()
{
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
if ($priceScope == Store::PRICE_SCOPE_GLOBAL) {
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
$priceAttribute = $this->attributeRepository
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
$connection = $this->resource->getConnection();
$conditions = [
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
];
if ($this->isPriceScopeSetToGlobal() === false) {
return;
}

/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
$priceAttribute = $this->attributeRepository
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
$connection = $this->resource->getConnection();
$conditions = [
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
];

$connection->delete(
$priceAttribute->getBackend()->getTable(),
$conditions
);
$connection->delete(
$priceAttribute->getBackend()->getTable(),
$conditions
);
}

/**
* Checks if price scope config option explicitly equal to global value.
*
* Such strict comparision is required to prevent price deleting when
* price scope config option is null for some reason.
*
* @return bool
*/
private function isPriceScopeSetToGlobal()
{
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
if ($priceScope === null) {
return false;
}

return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL;
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/CustomerData/DefaultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function doGetItemData()
'item_id' => $this->item->getId(),
'configure_url' => $this->getConfigureUrl(),
'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
'product_id' => $this->item->getProduct()->getId(),
'product_name' => $this->item->getProduct()->getName(),
'product_sku' => $this->item->getProduct()->getSku(),
'product_url' => $this->getProductUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<link src="Magento_Checkout::js/view/configure/product-customer-data.js"/>
</head>
<update handle="catalog_product_view"/>
<body>
<referenceBlock name="head.components">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
<fieldset class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
<label class="label" for="qty"><span><?php echo $block->escapeHtml(__('Qty')); ?></span></label>
<div class="control">
<input type="number" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="{'required-number':true,digits:true}"/>
<input type="number" name="qty" id="qty" maxlength="12" value=""
title="<?php echo $block->escapeHtml(__('Qty')); ?>"
class="input-text qty" data-validate="{'required-number':true,digits:true}"/>
</div>
</div>
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?php /* @escapeNotVerified */ echo $buttonTitle ?>"
title="<?php echo $block->escapeHtml($buttonTitle); ?>"
class="action primary tocart"
id="product-updatecart-button">
<span><?php /* @escapeNotVerified */ echo $buttonTitle ?></span>
<span><?php echo $block->escapeHtml($buttonTitle); ?></span>
</button>
<?php echo $block->getChildHtml('', true) ?>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require([
'jquery',
'Magento_Customer/js/customer-data'
], function ($, customerData) {
'use strict';

var selectors = {
qtySelector: '#product_addtocart_form [name="qty"]',
productIdSelector: '#product_addtocart_form [name="product"]'
},
cartData = customerData.get('cart'),
productId = $(selectors.productIdSelector).val(),
productQty,
productQtyInput,

/**
* Updates product's qty input value according to actual data
*/
updateQty = function () {

if (productQty || productQty === 0) {
productQtyInput = productQtyInput || $(selectors.qtySelector);

if (productQtyInput && productQty.toString() !== productQtyInput.val()) {
productQtyInput.val(productQty);
}
}
},

/**
* Sets productQty according to cart data from customer-data
*
* @param {Object} data - cart data from customer-data
*/
setProductQty = function (data) {
var product;

if (!(data && data.items && data.items.length && productId)) {
return;
}
product = data.items.find(function (item) {
return item['product_id'] === productId ||
item['item_id'] === productId;
});

if (!product) {
return;
}
productQty = product.qty;
};

cartData.subscribe(function (updateCartData) {
setProductQty(updateCartData);
updateQty();
});

setProductQty(cartData());
updateQty();
});
29 changes: 1 addition & 28 deletions app/code/Magento/Paypal/Model/Express/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Magento\Quote\Model\Quote\Address;
use Magento\Framework\DataObject;
use Magento\Paypal\Model\Cart as PaypalCart;
use Magento\Framework\App\ObjectManager;
use Magento\Sales\Api\OrderRepositoryInterface;

/**
* Wrapper that performs Paypal Express and Checkout communication
Expand Down Expand Up @@ -270,13 +268,6 @@ class Checkout
*/
protected $totalsCollector;

/**
* Order repository interface.
*
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Customer\Model\Url $customerUrl
Expand Down Expand Up @@ -805,8 +796,7 @@ public function place($token, $shippingMethodCode = null)

$this->ignoreAddressValidation();
$this->_quote->collectTotals();
$orderId = $this->quoteManagement->placeOrder($this->_quote->getId());
$order = $this->getOrderRepository()->get($orderId);
$order = $this->quoteManagement->submit($this->_quote);

if (!$order) {
return;
Expand Down Expand Up @@ -1174,21 +1164,4 @@ protected function prepareGuestQuote()
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
return $this;
}

/**
* Returns order repository instance.
*
* @return OrderRepositoryInterface
*
* @deprecated
*/
private function getOrderRepository()
{
if ($this->orderRepository === null) {
$this->orderRepository = ObjectManager::getInstance()
->get(OrderRepositoryInterface::class);
}

return $this->orderRepository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function setUp()
/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
* @magentoConfigFixture current_store catalog/price/scope 2
* @magentoConfigFixture current_store catalog/price/scope 1
* @magentoDbIsolation enabled
*/
public function testExecute()
{
$defaultStorePrice = 10.00;
$secondStorePrice = 9.99;
$secondStoreId = $this->store->load('fixture_second_store')->getId();
/** @var \Magento\Catalog\Model\Product\Action $productAction */
$productAction = $this->objectManager->create(
Expand All @@ -64,7 +66,7 @@ public function testExecute()
);
$product->setOrigData();
$product->setStoreId($secondStoreId);
$product->setPrice(9.99);
$product->setPrice($secondStorePrice);

$productResource->save($product);
$attribute = $this->objectManager->get(\Magento\Eav\Model\Config::class)
Expand All @@ -73,22 +75,33 @@ public function testExecute()
'price'
);
$this->assertEquals(
'9.99',
$secondStorePrice,
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
);
/** @var MutableScopeConfigInterface $config */
$config = $this->objectManager->get(
MutableScopeConfigInterface::class
);

$config->setValue(
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
null,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->cron->execute();
$this->assertEquals(
$secondStorePrice,
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
);

$config->setValue(
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
\Magento\Store\Model\Store::PRICE_SCOPE_GLOBAL,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
/** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
$this->cron->execute();
$this->assertEquals(
'10.0000',
$defaultStorePrice,
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
);
}
Expand Down

0 comments on commit de49e22

Please sign in to comment.