Skip to content

Commit

Permalink
Merge pull request #448 from magento-folks/bugfix
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-56866: [GITHUB] Custom option prices unexpectedly change after save #6116 #6342
- MAGETWO-58873: Cannot receive shipping quotes via the admin panel or front end
- MAGETWO-55216: Reference by name to non existing plugin lead to Di compilation failure
- MAGETWO-58958: Fatal error in console in flow for apply new Scheduled Staging Update using CRON
- MAGETWO-55924: [FT] Test fails because of unexpected alert window
- MAGETWO-58664: [GitHub] Free shipping rule with table shipping method breaks checkout #6346
- MAGETWO-58849: [GitHub] Error in product edit page after disable Review module #6704
  • Loading branch information
MomotenkoNatalia authored Sep 30, 2016
2 parents 10ff4f8 + b5ab1ee commit 2f9032b
Show file tree
Hide file tree
Showing 24 changed files with 595 additions and 109 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Helper/Product/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public function getPostDataRemove($product)
$data = [
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
'product' => $product->getId(),
'confirmation' => true,
'confirmationMessage' => __('Are you sure you want to remove this item from your Compare Products list?')
];
return $this->postHelper->getPostData($this->getRemoveUrl(), $data);
}
Expand All @@ -254,6 +256,8 @@ public function getPostDataClearList()
{
$params = [
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
'confirmation' => true,
'confirmationMessage' => __('Are you sure you want to remove all items from your Compare Products list?'),
];
return $this->postHelper->getPostData($this->getClearListUrl(), $params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
protected $_config;

/**
* @var \Magento\Framework\Locale\FormatInterface
*/
private $localeFormat;

/**
* Class constructor
*
Expand Down Expand Up @@ -91,8 +96,9 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
{
$priceTable = $this->getTable('catalog_product_option_type_price');
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());

$price = (double)sprintf('%F', $object->getPrice());
$price = (double)sprintf('%F', $formattedPrice);
$priceType = $object->getPriceType();

if ($object->getPrice() && $priceType) {
Expand Down Expand Up @@ -410,4 +416,19 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $

return $object;
}

/**
* Get FormatInterface to convert price from string to number format
*
* @return \Magento\Framework\Locale\FormatInterface
* @deprecated
*/
private function getLocaleFormatter()
{
if ($this->localeFormat === null) {
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Locale\FormatInterface::class);
}
return $this->localeFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public function testGetPostDataRemove()
$removeUrl = 'catalog/product_compare/remove';
$postParams = [
Action::PARAM_NAME_URL_ENCODED => '',
'product' => $productId
'product' => $productId,
'confirmation' => true,
'confirmationMessage' => __('Are you sure you want to remove this item from your Compare Products list?'),
];

//Verification
Expand Down Expand Up @@ -156,7 +158,9 @@ public function testGetPostDataClearList()
//Data
$clearUrl = 'catalog/product_compare/clear';
$postParams = [
Action::PARAM_NAME_URL_ENCODED => ''
Action::PARAM_NAME_URL_ENCODED => '',
'confirmation' => true,
'confirmationMessage' => __('Are you sure you want to remove all items from your Compare Products list?'),
];

//Verification
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Catalog/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
var config = {
map: {
'*': {
compareItems: 'Magento_Catalog/js/compare',
compareList: 'Magento_Catalog/js/list',
relatedProducts: 'Magento_Catalog/js/related-products',
upsellProducts: 'Magento_Catalog/js/upsell-products',
Expand Down
36 changes: 0 additions & 36 deletions app/code/Magento/Catalog/view/frontend/web/js/compare.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,32 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'uiComponent',
'Magento_Customer/js/customer-data',
'mage/translate'
], function (Component, customerData) {
'jquery',
'mage/mage',
'mage/decorate'
], function (Component, customerData, $) {
'use strict';

var sidebarInitialized = false;

/**
* Initialize sidebar
*/
function initSidebar() {
if (sidebarInitialized) {
return;
}
sidebarInitialized = true;
require([
'jquery',
'mage/mage'
], function ($) {
/*eslint-disable max-len*/
$('[data-role=compare-products-sidebar]').mage('compareItems', {
'removeConfirmMessage': $.mage.__('Are you sure you want to remove this item from your Compare Products list?'),
'removeSelector': '#compare-items a.action.delete',
'clearAllConfirmMessage': $.mage.__('Are you sure you want to remove all items from your Compare Products list?'),
'clearAllSelector': '#compare-clear-all'
});

/*eslint-enable max-len*/
});
sidebarInitialized = true;
$('[data-role=compare-products-sidebar]').decorate('list', true);
}

return Component.extend({
/** @inheritdoc */
initialize: function () {
this._super();
this.compareProducts = customerData.get('compare-products');
Expand Down
52 changes: 39 additions & 13 deletions app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,28 @@ public function collectRates(RateRequest $request)
$request->setPackageQty($oldQty);

if (!empty($rate) && $rate['price'] >= 0) {
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
$method = $this->_resultMethodFactory->create();

$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));

$method->setMethod('bestway');
$method->setMethodTitle($this->getConfigData('name'));

if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
$shippingPrice = 0;
} else {
$shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
}

$method->setPrice($shippingPrice);
$method->setCost($rate['cost']);

$method = $this->createShippingMethod($shippingPrice, $rate['cost']);
$result->append($method);
} elseif (empty($rate) && $request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {

/**
* Promotion rule was applied for the whole cart.
* In this case all other shipping methods could be omitted
* Table rate shipping method with 0$ price must be shown if grand total is more than minimal value.
* Free package weight has been already taken into account.
*/
$request->setPackageValue($freePackageValue);
$request->setPackageQty($freeQty);
$rate = $this->getRate($request);
if (!empty($rate) && $rate['price'] >= 0) {
$method = $this->createShippingMethod(0, 0);
$result->append($method);
}
} else {
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
$error = $this->_rateErrorFactory->create(
Expand Down Expand Up @@ -241,4 +244,27 @@ public function getAllowedMethods()
{
return ['bestway' => $this->getConfigData('name')];
}

/**
* Get the method object based on the shipping price and cost
*
* @param float $shippingPrice
* @param float $cost
* @return \Magento\Quote\Model\Quote\Address\RateResult\Method
*/
private function createShippingMethod($shippingPrice, $cost)
{
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
$method = $this->_resultMethodFactory->create();

$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));

$method->setMethod('bestway');
$method->setMethodTitle($this->getConfigData('name'));

$method->setPrice($shippingPrice);
$method->setCost($cost);
return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest;
use Magento\Framework\UrlInterface;
use Magento\Review\Ui\DataProvider\Product\Form\Modifier\Review;
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;

/**
* Class ReviewTest
Expand All @@ -19,36 +21,73 @@ class ReviewTest extends AbstractModifierTest
*/
protected $urlBuilderMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $moduleManagerMock;

protected function setUp()
{
parent::setUp();
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
->getMockForAbstractClass();
$this->moduleManagerMock = $this->getMock(ModuleManager::class, [], [], '', false);
}

/**
* @return ModifierInterface
*/
protected function createModel()
{
return $this->objectManager->getObject(Review::class, [
$model = $this->objectManager->getObject(Review::class, [
'locator' => $this->locatorMock,
'urlBuilder' => $this->urlBuilderMock,
]);

$reviewClass = new \ReflectionClass(Review::class);
$moduleManagerProperty = $reviewClass->getProperty('moduleManager');
$moduleManagerProperty->setAccessible(true);
$moduleManagerProperty->setValue(
$model,
$this->moduleManagerMock
);

return $model;
}

public function testModifyMetaToBeEmpty()
public function testModifyMetaDoesNotAddReviewSectionForNewProduct()
{
$this->productMock->expects($this->once())
->method('getId');

$this->assertSame([], $this->getModel()->modifyMeta([]));
}

public function testModifyMetaDoesNotAddReviewSectionIfReviewModuleOutputIsDisabled()
{
$this->productMock->expects($this->once())
->method('getId')
->willReturn(0);
->willReturn(1);

$this->moduleManagerMock->expects($this->any())
->method('isOutputEnabled')
->with('Magento_Review')
->willReturn(false);

$this->assertSame([], $this->getModel()->modifyMeta([]));
}

public function testModifyMeta()
public function testModifyMetaAddsReviewSectionForExistingProductIfReviewModuleOutputIsEnabled()
{
$this->productMock->expects($this->once())
->method('getId')
->willReturn(1);

$this->moduleManagerMock->expects($this->any())
->method('isOutputEnabled')
->with('Magento_Review')
->willReturn(true);

$this->assertArrayHasKey(Review::GROUP_REVIEW, $this->getModel()->modifyMeta([]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Ui\Component\Form;
use Magento\Framework\UrlInterface;
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\App\ObjectManager;

/**
* Class Review
Expand All @@ -34,6 +36,11 @@ class Review extends AbstractModifier
*/
protected $urlBuilder;

/**
* @var ModuleManager
*/
private $moduleManager;

/**
* @param LocatorInterface $locator
* @param UrlInterface $urlBuilder
Expand All @@ -51,7 +58,7 @@ public function __construct(
*/
public function modifyMeta(array $meta)
{
if (!$this->locator->getProduct()->getId()) {
if (!$this->locator->getProduct()->getId() || !$this->getModuleManager()->isOutputEnabled('Magento_Review')) {
return $meta;
}

Expand Down Expand Up @@ -114,4 +121,19 @@ public function modifyData(array $data)

return $data;
}

/**
* Retrieve module manager instance using dependency lookup to keep this class backward compatible.
*
* @return ModuleManager
*
* @deprecated
*/
private function getModuleManager()
{
if ($this->moduleManager === null) {
$this->moduleManager = ObjectManager::getInstance()->get(ModuleManager::class);
}
return $this->moduleManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Form $block */
?>
<form id="edit_form" data-order-config='<?php /* @escapeNotVerified */ echo $block->getOrderDataJson() ?>' data-load-base-url="<?php /* @escapeNotVerified */ echo $block->getLoadBlockUrl() ?>" action="<?php /* @escapeNotVerified */ echo $block->getSaveUrl() ?>" method="post" enctype="multipart/form-data">
<form id="edit_form" data-order-config='<?php echo $block->escapeHtml($block->getOrderDataJson()) ?>' data-load-base-url="<?php /* @escapeNotVerified */ echo $block->getLoadBlockUrl() ?>" action="<?php /* @escapeNotVerified */ echo $block->getSaveUrl() ?>" method="post" enctype="multipart/form-data">
<?php echo $block->getBlockHtml('formkey')?>
<div id="order-message">
<?php echo $block->getChildHtml('message') ?>
Expand Down
Loading

0 comments on commit 2f9032b

Please sign in to comment.