Skip to content

Commit

Permalink
Merge pull request #606 from magento-mpi/MPI-PR
Browse files Browse the repository at this point in the history
[MPI] Bug Fixes
  • Loading branch information
Voskoboinikov, Dmytro(dvoskoboinikov) committed May 12, 2016
2 parents 32e7ab6 + b8b52ad commit 964f540
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 12 deletions.
11 changes: 5 additions & 6 deletions app/code/Magento/Braintree/view/adminhtml/web/js/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
define([
'jquery',
'uiComponent',
'Magento_Ui/js/modal/alert',
'Magento_Checkout/js/model/full-screen-loader'
], function ($, Class, alert, fullScreenLoader) {
'Magento_Ui/js/modal/alert'
], function ($, Class, alert) {
'use strict';

return Class.extend({
Expand Down Expand Up @@ -84,7 +83,7 @@ define([
submitOrder: function () {
this.$selector.validate().form();
this.$selector.trigger('afterValidate.beforeSubmit');
fullScreenLoader.stopLoader();
$('body').trigger('processStop');

// validate parent form
if (this.$selector.validate().errorList.length) {
Expand All @@ -106,7 +105,7 @@ define([
getPaymentMethodNonce: function () {
var self = this;

fullScreenLoader.startLoader();
$('body').trigger('processStart');

$.get(self.nonceUrl, {
'public_hash': self.publicHash
Expand All @@ -118,7 +117,7 @@ define([

self.error(failed.message);
}).always(function () {
fullScreenLoader.stopLoader();
$('body').trigger('processStop');
});
},

Expand Down
41 changes: 41 additions & 0 deletions app/code/Magento/Bundle/Pricing/Price/FinalPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
use Magento\Bundle\Model\Product\Price;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;

/**
* Final price model
Expand All @@ -36,6 +38,11 @@ class FinalPrice extends \Magento\Catalog\Pricing\Price\FinalPrice implements Fi
*/
protected $bundleOptionPrice;

/**
* @var \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface
*/
private $productOptionRepository;

/**
* @param Product $saleableItem
* @param float $quantity
Expand Down Expand Up @@ -81,6 +88,22 @@ public function getMaximalPrice()
return $this->maximalPrice;
}

/**
* Return ProductCustomOptionRepository
*
* @return ProductCustomOptionRepositoryInterface
* @deprecated
*/
private function getProductOptionRepository()
{
if (!$this->productOptionRepository) {
$this->productOptionRepository = ObjectManager::getInstance()->get(
ProductCustomOptionRepositoryInterface::class
);
}
return $this->productOptionRepository;
}

/**
* Returns min price
*
Expand All @@ -101,6 +124,7 @@ public function getAmount()
if (!$this->minimalPrice) {
$price = parent::getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
$this->loadProductCustomOptions();
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(true);
Expand All @@ -110,6 +134,23 @@ public function getAmount()
return $this->minimalPrice;
}

/**
* Load product custom options
*
* @return void
*/
private function loadProductCustomOptions()
{
if (!$this->product->getOptions()) {
$options = [];
foreach ($this->getProductOptionRepository()->getProductOptions($this->product) as $option) {
$option->setProduct($this->product);
$options[] = $option;
}
$this->product->setOptions($options);
}
}

/**
* get bundle product price without any option
*
Expand Down
31 changes: 29 additions & 2 deletions app/code/Magento/Bundle/Test/Unit/Pricing/Price/FinalPriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
use Magento\Bundle\Pricing\Price\BundleOptionPrice;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
use Magento\Bundle\Model\Product\Price;

use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

/**
* @SuppressWarnings(PHPMD)
*/
class FinalPriceTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Bundle\Pricing\Price\FinalPrice */
Expand Down Expand Up @@ -45,10 +49,15 @@ class FinalPriceTest extends \PHPUnit_Framework_TestCase
protected $customOptionPriceMock;

/**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;

/**
* @var ProductCustomOptionRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $productOptionRepositoryMock;

/**
* @return void
*/
Expand Down Expand Up @@ -96,6 +105,14 @@ protected function prepareMock()
$this->bundleCalculatorMock,
$this->priceCurrencyMock
);

$this->productOptionRepositoryMock = $this->getMockForAbstractClass(
ProductCustomOptionRepositoryInterface::class
);
$reflection = new \ReflectionClass(get_class($this->finalPrice));
$reflectionProperty = $reflection->getProperty('productOptionRepository');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->finalPrice, $this->productOptionRepositoryMock);
}

/**
Expand Down Expand Up @@ -172,6 +189,16 @@ public function testGetMinimalPriceFixedBundleWithOption()
$this->baseAmount = 5;
$result = 7;
$this->prepareMock();
$customOptions = [
$this->getMockBuilder(\Magento\Catalog\Api\Data\ProductCustomOptionInterface::class)
->setMethods(['setProduct'])
->getMockForAbstractClass()
];

$this->productOptionRepositoryMock->expects(static::once())
->method('getProductOptions')
->with($this->saleableInterfaceMock)
->willReturn($customOptions);

$this->saleableInterfaceMock->expects($this->once())
->method('getPriceType')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ protected function _construct()
$this->setUseAjax(true);
}

/**
* Get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('paypal/billing_agreement/ordersGrid', ['_current' => true]);
}

/**
* Apply various selection filters to prepare the sales order grid collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<referenceBlock name="sales.order.grid.export" remove="true"/>
<referenceBlock name="sales.order.grid.massaction" remove="true"/>
<container name="root">
<block class="Magento\Backend\Block\Widget\Grid\Container" name="sales_order.grid.container" template="Magento_Backend::widget/grid/container/empty.phtml"/>
<block class="Magento\Paypal\Block\Adminhtml\Billing\Agreement\View\Tab\Orders" name="sales_order.grid.container"/>
</container>
</layout>
34 changes: 33 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function getQuote()
*/
public function importData(array $data)
{
$data = $this->convertPaymentData($data);
$data = new \Magento\Framework\DataObject($data);
$this->_eventManager->dispatch(
$this->_eventPrefix . '_import_data_before',
Expand Down Expand Up @@ -177,6 +178,37 @@ public function importData(array $data)
return $this;
}

/**
* Converts request to payment data
*
* @param array $rawData
* @return array
*/
private function convertPaymentData(array $rawData)
{
$paymentData = [
PaymentInterface::KEY_METHOD => null,
PaymentInterface::KEY_PO_NUMBER => null,
PaymentInterface::KEY_ADDITIONAL_DATA => [],
'checks' => []
];

foreach (array_keys($rawData) as $requestKey) {
if (!array_key_exists($requestKey, $paymentData)) {
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA][$requestKey] = $rawData[$requestKey];
} elseif ($requestKey === PaymentInterface::KEY_ADDITIONAL_DATA) {
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA] = array_merge(
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA],
(array) $rawData[$requestKey]
);
} else {
$paymentData[$requestKey] = $rawData[$requestKey];
}
}

return $paymentData;
}

/**
* Prepare object for save
*
Expand Down Expand Up @@ -226,7 +258,7 @@ public function getOrderPlaceRedirectUrl()
public function getMethodInstance()
{
$method = parent::getMethodInstance();
$method->setStore($this->getQuote()->getStore()->getStoreId());
$method->setStore($this->getQuote()->getStoreId());
return $method;
}

Expand Down
Loading

0 comments on commit 964f540

Please sign in to comment.