Skip to content

Commit

Permalink
MAGETWO-56910: [Backport] Braintree doesn't work when using table pre…
Browse files Browse the repository at this point in the history
…fixing for 2.1.x

- Merge commit
  • Loading branch information
Dmytro Yushkin committed Sep 9, 2016
2 parents b18b6a6 + 68112cc commit cd29741
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function execute()
$attributesData[$attributeCode] = $value;
} elseif ($attribute->getFrontendInput() == 'multiselect') {
// Check if 'Change' checkbox has been checked by admin for this attribute
$isChanged = (bool)$this->getRequest()->getPost($attributeCode . '_checkbox');
$isChanged = (bool)$this->getRequest()->getPost('toggle_' . $attributeCode);
if (!$isChanged) {
unset($attributesData[$attributeCode]);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry)
foreach ($existingMediaGalleryEntries as $key => $existingEntry) {
if ($existingEntry->getId() == $entry->getId()) {
$found = true;
if ($entry->getFile()) {
$entry->setId(null);
}
$existingMediaGalleryEntries[$key] = $entry;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public function testUpdate()
$this->productMock->expects($this->once())->method('getMediaGalleryEntries')
->willReturn([$existingEntryMock]);
$entryMock->expects($this->once())->method('getId')->willReturn($entryId);
$entryMock->expects($this->once())->method('getFile')->willReturn("base64");
$entryMock->expects($this->once())->method('setId')->with(null);

$this->productMock->expects($this->once())->method('setMediaGalleryEntries')
->willReturn([$entryMock]);
Expand Down
45 changes: 25 additions & 20 deletions app/code/Magento/Catalog/view/base/web/js/price-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'Magento_Catalog/js/price-utils',
Expand Down Expand Up @@ -29,6 +30,7 @@ define([
*/
_init: function initPriceBox() {
var box = this.element;

box.trigger('updatePrice');
this.cache.displayPrices = utils.deepClone(this.options.prices);
},
Expand Down Expand Up @@ -70,7 +72,8 @@ define([
updatePrice: function updatePrice(newPrices) {
var prices = this.cache.displayPrices,
additionalPrice = {},
pricesCode = [];
pricesCode = [],
priceValue, origin, finalPrice;

this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};

Expand All @@ -89,19 +92,19 @@ define([
pricesCode = _.keys(additional);
}
_.each(pricesCode, function (priceCode) {
var priceValue = additional[priceCode] || {};
priceValue = additional[priceCode] || {};
priceValue.amount = +priceValue.amount || 0;
priceValue.adjustments = priceValue.adjustments || {};

additionalPrice[priceCode] = additionalPrice[priceCode] || {
'amount': 0,
'adjustments': {}
};
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0)
+ priceValue.amount;
'amount': 0,
'adjustments': {}
};
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0) +
priceValue.amount;
_.each(priceValue.adjustments, function (adValue, adCode) {
additionalPrice[priceCode].adjustments[adCode] = 0
+ (additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
additionalPrice[priceCode].adjustments[adCode] = 0 +
(additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
});
});
});
Expand All @@ -110,23 +113,24 @@ define([
this.cache.displayPrices = utils.deepClone(this.options.prices);
} else {
_.each(additionalPrice, function (option, priceCode) {
var origin = this.options.prices[priceCode] || {},
final = prices[priceCode] || {};
origin = this.options.prices[priceCode] || {};
finalPrice = prices[priceCode] || {};
option.amount = option.amount || 0;
origin.amount = origin.amount || 0;
origin.adjustments = origin.adjustments || {};
final.adjustments = final.adjustments || {};
finalPrice.adjustments = finalPrice.adjustments || {};

final.amount = 0 + origin.amount + option.amount;
finalPrice.amount = 0 + origin.amount + option.amount;
_.each(option.adjustments, function (pa, paCode) {
final.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
finalPrice.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
});
}, this);
}

this.element.trigger('reloadPrice');
},

/*eslint-disable no-extra-parens*/
/**
* Render price unit block.
*/
Expand All @@ -135,16 +139,19 @@ define([
priceTemplate = mageTemplate(this.options.priceTemplate);

_.each(this.cache.displayPrices, function (price, priceCode) {
price.final = _.reduce(price.adjustments, function(memo, amount) {
price.final = _.reduce(price.adjustments, function (memo, amount) {
return memo + amount;
}, price.amount);

price.formatted = utils.formatPrice(price.final, priceFormat);

$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({data: price}));
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
data: price
}));
}, this);
},

/*eslint-enable no-extra-parens*/
/**
* Overwrites initial (default) prices object.
* @param {Object} prices
Expand Down Expand Up @@ -177,6 +184,7 @@ define([
var box = this.element,
priceHolders = $('[data-price-type]', box),
prices = this.options.prices;

this.options.productId = box.data('productId');

if (_.isEmpty(prices)) {
Expand All @@ -199,10 +207,7 @@ define([
_setDefaultsFromPriceConfig: function _setDefaultsFromPriceConfig() {
var config = this.options.priceConfig;

if (config) {
if (+config.productId !== +this.options.productId) {
return;
}
if (config && config.prices) {
this.options.prices = config.prices;
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Checkout/Block/Cart/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public function getConfig()
'removeItemUrl' => $this->getRemoveItemUrl(),
'imageTemplate' => $this->getImageHtmlTemplate(),
'baseUrl' => $this->getBaseUrl(),
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount(),
'websiteId' => $this->_storeManager->getStore()->getWebsiteId()
];
}

Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/CustomerData/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function getSectionData()
'items' => $this->getRecentItems(),
'extra_actions' => $this->layout->createBlock('Magento\Catalog\Block\ShortcutButtons')->toHtml(),
'isGuestCheckoutAllowed' => $this->isGuestCheckoutAllowed(),
'website_id' => $this->getQuote()->getStore()->getWebsiteId()
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function testGetTotalsHtml()
public function testGetConfig()
{
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
$websiteId = 100;

$shoppingCartUrl = 'http://url.com/cart';
$checkoutUrl = 'http://url.com/checkout';
Expand All @@ -139,7 +140,8 @@ public function testGetConfig()
'removeItemUrl' => $removeItemUrl,
'imageTemplate' => $imageTemplate,
'baseUrl' => $baseUrl,
'minicartMaxItemsVisible' => 3
'minicartMaxItemsVisible' => 3,
'websiteId' => $websiteId
];

$valueMap = [
Expand All @@ -156,8 +158,9 @@ public function testGetConfig()
$this->urlBuilderMock->expects($this->exactly(4))
->method('getUrl')
->willReturnMap($valueMap);
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
$this->storeManagerMock->expects($this->exactly(2))->method('getStore')->willReturn($storeMock);
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);

$this->scopeConfigMock->expects($this->once())
Expand Down
20 changes: 16 additions & 4 deletions app/code/Magento/Checkout/Test/Unit/CustomerData/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function testGetSectionData()
$subtotalValue = 200;
$productId = 10;
$storeId = 20;
$websiteId = 100;
$productRewrite = [$productId => ['rewrite' => 'product']];
$itemData = ['item' => 'data'];
$shortcutButtonsHtml = '<span>Buttons</span>';
Expand All @@ -100,7 +101,7 @@ public function testGetSectionData()

$quoteMock = $this->getMock(
'\Magento\Quote\Model\Quote',
['getTotals', 'getHasError', 'getAllVisibleItems'],
['getTotals', 'getHasError', 'getAllVisibleItems', 'getStore'],
[],
'',
false
Expand All @@ -109,6 +110,10 @@ public function testGetSectionData()
$quoteMock->expects($this->once())->method('getTotals')->willReturn($totals);
$quoteMock->expects($this->once())->method('getHasError')->willReturn(false);

$storeMock = $this->getMock(\Magento\Store\Model\System\Store::class, ['getWebsiteId'], [], '', false);
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);

$this->checkoutCartMock->expects($this->once())->method('getSummaryQty')->willReturn($summaryQty);
$this->checkoutHelperMock->expects($this->once())
->method('formatPrice')
Expand Down Expand Up @@ -166,7 +171,8 @@ public function testGetSectionData()
['item' => 'data']
],
'extra_actions' => '<span>Buttons</span>',
'isGuestCheckoutAllowed' => 1
'isGuestCheckoutAllowed' => 1,
'website_id' => $websiteId
];
$this->assertEquals($expectedResult, $this->model->getSectionData());
}
Expand All @@ -180,6 +186,7 @@ public function testGetSectionDataWithCompositeProduct()
$subtotalValue = 200;
$productId = 10;
$storeId = 20;
$websiteId = 100;

$productRewrite = [$productId => ['rewrite' => 'product']];
$itemData = ['item' => 'data'];
Expand All @@ -190,7 +197,7 @@ public function testGetSectionDataWithCompositeProduct()

$quoteMock = $this->getMock(
'\Magento\Quote\Model\Quote',
['getTotals', 'getHasError', 'getAllVisibleItems'],
['getTotals', 'getHasError', 'getAllVisibleItems', 'getStore'],
[],
'',
false
Expand All @@ -216,6 +223,10 @@ public function testGetSectionDataWithCompositeProduct()

$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([$quoteItemMock]);

$storeMock = $this->getMock(\Magento\Store\Model\System\Store::class, ['getWebsiteId'], [], '', false);
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);

$productMock = $this->getMock(
'\Magento\Catalog\Model\Product',
['isVisibleInSiteVisibility', 'getId', 'setUrlDataObject'],
Expand Down Expand Up @@ -271,7 +282,8 @@ public function testGetSectionDataWithCompositeProduct()
['item' => 'data']
],
'extra_actions' => '<span>Buttons</span>',
'isGuestCheckoutAllowed' => 1
'isGuestCheckoutAllowed' => 1,
'website_id' => $websiteId
];
$this->assertEquals($expectedResult, $this->model->getSectionData());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ define([
addToCartCalls++;
self.isLoading(true);
});
if (cartData().website_id !== window.checkout.websiteId) {
customerData.reload(['cart'], false);
}

return this._super();
},
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Sales/Api/Data/InvoiceItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ interface InvoiceItemInterface extends \Magento\Framework\Api\ExtensibleDataInte
* Base discount tax compensation amount.
*/
const BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT = 'base_discount_tax_compensation_amount';

/**
* Invoice
*/
const INVOICE = 'invoice';

/**
* Gets the additional data for the invoice item.
*
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/Model/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ public function getComments()
}

//@codeCoverageIgnoreStart

/**
* Returns increment id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class State
*/
public function check(Order $order)
{
if (!$order->getId()) {
return $order;
}
if (!$order->isCanceled() && !$order->canUnhold() && !$order->canInvoice() && !$order->canShip()) {
if (0 == $order->getBaseGrandTotal() || $order->canCreditmemo()) {
if ($order->getState() !== Order::STATE_COMPLETE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ protected function setUp()
public function testCheckOrderEmpty()
{
$this->orderMock->expects($this->once())
->method('getId')
->will($this->returnValue(null));
$this->assertEquals($this->orderMock, $this->state->check($this->orderMock));
->method('getBaseGrandTotal')
->willReturn(100);
$this->orderMock->expects($this->never())
->method('setState');

$this->state->check($this->orderMock);
}

/**
* test check order - set state complete
*/
public function testCheckSetStateComplete()
{
$this->orderMock->expects($this->once())
$this->orderMock->expects($this->any())
->method('getId')
->will($this->returnValue(1));
$this->orderMock->expects($this->once())
Expand Down Expand Up @@ -120,7 +123,7 @@ public function testCheckSetStateComplete()
*/
public function testCheckSetStateClosed()
{
$this->orderMock->expects($this->once())
$this->orderMock->expects($this->any())
->method('getId')
->will($this->returnValue(1));
$this->orderMock->expects($this->once())
Expand Down Expand Up @@ -162,7 +165,7 @@ public function testCheckSetStateClosed()
*/
public function testCheckSetStateProcessing()
{
$this->orderMock->expects($this->once())
$this->orderMock->expects($this->any())
->method('getId')
->will($this->returnValue(1));
$this->orderMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formN
$actionsFieldSetId = $model->getActionsFieldSetId($formName);

$newChildUrl = $this->getUrl(
'sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset_' . $actionsFieldSetId,
'sales_rule/promo_quote/newActionHtml/form/' . $actionsFieldSetId,
['form_namespace' => $formName]
);

Expand Down
Loading

0 comments on commit cd29741

Please sign in to comment.