Skip to content

Commit

Permalink
Merge pull request #581 from magento-fearless-kiwis/develop
Browse files Browse the repository at this point in the history
[FearlessKiwis] Bug Fixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Sep 9, 2015
2 parents e20786f + 20c85c3 commit ae8c9cd
Show file tree
Hide file tree
Showing 41 changed files with 608 additions and 252 deletions.
26 changes: 16 additions & 10 deletions app/code/Magento/Braintree/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Observer
* @var \Magento\Framework\DB\TransactionFactory
*/
protected $transactionFactory;

/**
* @param Vault $vault
* @param \Magento\Braintree\Model\Config\Cc $config
Expand Down Expand Up @@ -80,21 +79,28 @@ public function processBraintreePayment(\Magento\Framework\DataObject $observer)
&& $order->canInvoice() && $this->shouldInvoice()) {
$qtys = [];
foreach ($shipment->getAllItems() as $shipmentItem) {
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getQty();
if ($shipmentItem->getOrderItem()->getQtyToInvoice() >= $shipmentItem->getQty()) {
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getQty();
} else {
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getOrderItem()->getQtyToInvoice();
}
}
foreach ($order->getAllItems() as $orderItem) {
if (!array_key_exists($orderItem->getId(), $qtys)) {
$qtys[$orderItem->getId()] = 0;
}
}
$invoice = $order->prepareInvoice($qtys);
$invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE);
$invoice->register();
/** @var \Magento\Framework\DB\Transaction $transaction */
$transaction = $this->transactionFactory->create();
$transaction->addObject($invoice)
->addObject($invoice->getOrder())
->save();
if (array_sum($qtys)>0) {
$invoice = $order->prepareInvoice($qtys);
$invoice->setOrder($order);
$invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE);
$invoice->register();
/** @var \Magento\Framework\DB\Transaction $transaction */
$transaction = $this->transactionFactory->create();
$transaction->addObject($invoice)
->addObject($invoice->getOrder())
->save();
}
}
return $this;
}
Expand Down
15 changes: 12 additions & 3 deletions app/code/Magento/Braintree/Test/Unit/Model/ObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ protected function setupOrderShipmentItems($orderMock, $shipmentMock)
$shipment3Qty = 3;

$orderItem1 = new \Magento\Framework\DataObject(
['id' => $orderItem1Id]
[
'id' => $orderItem1Id,
'qty_to_invoice' => $orderItem1Id
]
);
$orderItem2 = new \Magento\Framework\DataObject(
['id' => $orderItem2Id]
[
'id' => $orderItem2Id,
'qty_to_invoice' => $orderItem2Id
]
);
$orderItem3 = new \Magento\Framework\DataObject(
['id' => $orderItem3Id]
[
'id' => $orderItem3Id,
'qty_to_invoice' => $orderItem3Id
]
);
$orderItems = [$orderItem1, $orderItem2, $orderItem3];
$orderMock->expects($this->any())
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Block/Product/View/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use Magento\Catalog\Model\Product;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Options extends \Magento\Framework\View\Element\Template
{
/**
Expand Down Expand Up @@ -190,6 +193,7 @@ protected function _getPriceConfiguration($option)
],
],
'type' => $option->getPriceType(),
'name' => $option->getTitle()
];
return $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getValuesHtml()
);
$select->addOption(
$_value->getOptionTypeId(),
$_value->getTitle() . ' ' . $priceStr . '',
$_value->getTitle() . ' ' . strip_tags($priceStr) . '',
['price' => $this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false)]
);
}
Expand Down
45 changes: 45 additions & 0 deletions app/code/Magento/Catalog/Pricing/Price/CustomOptionPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Magento\Catalog\Model\Product\Option;
use Magento\Catalog\Pricing\Price;
use Magento\Framework\Pricing\Price\AbstractPrice;
use Magento\Framework\Pricing\Object\SaleableInterface;
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Framework\Pricing\Amount\AmountInterface;

/**
* Class OptionPrice
Expand All @@ -26,6 +29,31 @@ class CustomOptionPrice extends AbstractPrice implements CustomOptionPriceInterf
*/
protected $priceOptions;

/**
* Code of parent adjustment to be skipped from calculation
*
* @var string
*/
protected $excludeAdjustment = null;

/**
* @param SaleableInterface $saleableItem
* @param float $quantity
* @param CalculatorInterface $calculator
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
* @param string $excludeAdjustment
*/
public function __construct(
SaleableInterface $saleableItem,
$quantity,
CalculatorInterface $calculator,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
$excludeAdjustment = null
) {
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
$this->excludeAdjustment = $excludeAdjustment;
}

/**
* Get minimal and maximal option values
*
Expand Down Expand Up @@ -83,6 +111,23 @@ public function getValue()
return $optionValues;
}

/**
* @param float $amount
* @param null|bool|string $exclude
* @param null|array $context
* @return AmountInterface|bool|float
*/
public function getCustomAmount($amount = null, $exclude = null, $context = [])
{
if (null !== $amount) {
$amount = $this->priceCurrency->convertAndRound($amount);
} else {
$amount = $this->getValue();
}
$exclude = $this->excludeAdjustment;
return $this->calculator->getAmount($amount, $this->getProduct(), $exclude, $context);
}

/**
* Return the minimal or maximal price for custom options
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<item name="render_template" xsi:type="string">Magento_Catalog::product/price/final_price.phtml</item>
</item>
<item name="custom_option_price" xsi:type="array">
<item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/option.phtml</item>
<item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
</item>
<item name="configured_price" xsi:type="array">
<item name="render_class" xsi:type="string">Magento\Catalog\Pricing\Render\ConfiguredPriceBox</item>
Expand Down

This file was deleted.

78 changes: 76 additions & 2 deletions app/code/Magento/Catalog/view/base/web/js/price-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
define([
'jquery',
'underscore',
'mage/template',
'priceUtils',
'priceBox',
'jquery/ui'
], function ($, _, utils) {
], function ($, _, mageTemplate, utils) {
'use strict';

var globalOptions = {
Expand All @@ -16,6 +18,10 @@ define([
optionsSelector: '.product-custom-option',
optionConfig: {},
optionHandlers: {},
optionTemplate: '<%- data.label %>' +
'<% if (data.finalPrice.value) { %>' +
' +<%- data.finalPrice.formatted %>' +
'<% } %>',
controlContainer: 'dd'
};

Expand All @@ -29,7 +35,17 @@ define([
*/
_create: function createPriceOptions() {
var form = this.element,
options = $(this.options.optionsSelector, form);
options = $(this.options.optionsSelector, form),
priceBox = $(this.options.priceHolderSelector, $(this.options.optionsSelector).element);

if (priceBox.data('magePriceBox') && priceBox.priceBox('option') && priceBox.priceBox('option').priceConfig) {
if (priceBox.priceBox('option').priceConfig.optionTemplate) {
this._setOption('optionTemplate', priceBox.priceBox('option').priceConfig.optionTemplate);
}
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
}

this._applyOptionNodeFix(options);

options.on('change', this._onOptionChanged.bind(this));
},
Expand All @@ -53,6 +69,64 @@ define([
$(this.options.priceHolderSelector).trigger('updatePrice', changes);
},


/**
* Helper to fix issue with option nodes:
* - you can't place any html in option ->
* so you can't style it via CSS
* @param {jQuery} options
* @private
*/
_applyOptionNodeFix: function applyOptionNodeFix(options) {
var config = this.options,
format = config.priceFormat,
template = config.optionTemplate;
template = mageTemplate(template);
options.filter('select').each(function (index, element) {
var $element = $(element),
optionId = utils.findOptionId($element),
optionName = $element.prop('name'),
optionType = $element.prop('type');
var optionConfig = config.optionConfig && config.optionConfig[optionId];

$element.find('option').each(function (idx, option) {
var $option,
optionValue,
toTemplate,
prices;

$option = $(option);
optionValue = $option.val();

if (!optionValue && optionValue !== 0) {
return;
}

toTemplate = {
data: {
label: optionConfig[optionValue] && optionConfig[optionValue].name
}
};
prices = optionConfig[optionValue] ? optionConfig[optionValue].prices : null;

if (prices) {
_.each(prices, function (price, type) {
var value = +(price.amount);
value += _.reduce(price.adjustments, function (sum, x) {
return sum + x;
}, 0);
toTemplate.data[type] = {
value: value,
formatted: utils.formatPrice(value, format)
};
});

$option.text(template(toTemplate));
}
});
});
},

/**
* Custom behavior on getting options:
* now widget able to deep merge accepted configuration with instance options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,14 @@ public function addFieldToFilterInconsistentArraysDataProvider()
],
];
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage When passing an array of fields there must be at least one field in the array.
* @dataProvider addFieldToFilterInconsistentArraysDataProvider
*/
public function testAddFieldToFilterEmptyArrays()
{
$this->serviceCollection->addFieldToFilter([], []);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @api
*/
interface CurrencyInformationInterface
interface CurrencyInformationInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* Get the base currency code for the store.
Expand Down Expand Up @@ -105,17 +105,17 @@ public function setExchangeRates(array $exchangeRates = null);
/**
* Retrieve existing extension attributes object or create a new one.
*
* @return \Magento\Directory\Api\Data\CurrencyInformationInterface|null
* @return \Magento\Directory\Api\Data\CurrencyInformationExtensionInterface|null
*/
public function getExtensionAttributes();

/**
* Set an extension attributes object.
*
* @param \Magento\Directory\Api\Data\CurrencyInformationInterface $extensionAttributes
* @param \Magento\Directory\Api\Data\CurrencyInformationExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Directory\Api\Data\CurrencyInformationInterface $extensionAttributes
\Magento\Directory\Api\Data\CurrencyInformationExtensionInterface $extensionAttributes
);
}
8 changes: 4 additions & 4 deletions app/code/Magento/Directory/Api/Data/ExchangeRateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @api
*/
interface ExchangeRateInterface
interface ExchangeRateInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* Get the currency code associated with the exchange rate.
Expand Down Expand Up @@ -45,17 +45,17 @@ public function setRate($rate);
/**
* Retrieve existing extension attributes object or create a new one.
*
* @return \Magento\Directory\Api\Data\ExchangeRateInterface|null
* @return \Magento\Directory\Api\Data\ExchangeRateExtensionInterface|null
*/
public function getExtensionAttributes();

/**
* Set an extension attributes object.
*
* @param \Magento\Directory\Api\Data\ExchangeRateInterface $extensionAttributes
* @param \Magento\Directory\Api\Data\ExchangeRateExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Directory\Api\Data\ExchangeRateInterface $extensionAttributes
\Magento\Directory\Api\Data\ExchangeRateExtensionInterface $extensionAttributes
);
}
2 changes: 1 addition & 1 deletion app/code/Magento/Directory/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function getRegionCollection()
/**
* Retrieve country collection
*
* @param mixed $store
* @param null|int|string|\Magento\Store\Model\Store $store
* @return \Magento\Directory\Model\Resource\Country\Collection
*/
public function getCountryCollection($store = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getExtensionAttributes()
* @inheritDoc
*/
public function setExtensionAttributes(
\Magento\Directory\Api\Data\CurrencyInformationInterface $extensionAttributes
\Magento\Directory\Api\Data\CurrencyInformationExtensionInterface $extensionAttributes
) {
return $this->_setExtensionAttributes($extensionAttributes);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Directory/Model/Data/ExchangeRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getExtensionAttributes()
* @inheritDoc
*/
public function setExtensionAttributes(
\Magento\Directory\Api\Data\ExchangeRateInterface $extensionAttributes
\Magento\Directory\Api\Data\ExchangeRateExtensionInterface $extensionAttributes
) {
return $this->_setExtensionAttributes($extensionAttributes);
}
Expand Down
Loading

0 comments on commit ae8c9cd

Please sign in to comment.