Skip to content

Commit

Permalink
Merge pull request #91 from magento-api/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko committed Jun 9, 2016
2 parents e373ea7 + 0651ebb commit 66883d5
Show file tree
Hide file tree
Showing 23 changed files with 827 additions and 417 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ php:
env:
global:
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=2
- INTEGRATION_SETS=3
matrix:
- TEST_SUITE=unit
- TEST_SUITE=integration INTEGRATION_INDEX=1
- TEST_SUITE=integration INTEGRATION_INDEX=2
- TEST_SUITE=integration INTEGRATION_INDEX=3
- TEST_SUITE=static
cache:
apt: true
Expand Down
47 changes: 47 additions & 0 deletions app/code/Magento/Backend/Model/Setup/MenuBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Model\Setup;

use Magento\Backend\Model\Menu;
use Magento\Backend\Model\Menu\Builder;
use Magento\Framework\App\DocRootLocator;

/**
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
*/
class MenuBuilder
{
/**
* @var DocRootLocator
*/
protected $docRootLocator;

/**
* MenuBuilder constructor.
*
* @param DocRootLocator $docRootLocator
*/
public function __construct(DocRootLocator $docRootLocator)
{
$this->docRootLocator = $docRootLocator;
}

/**
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
*
* @param Builder $subject
* @param Menu $menu
* @return Menu
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetResult(Builder $subject, Menu $menu)
{
if ($this->docRootLocator->isPub()) {
$menu->remove('Magento_Backend::setup_wizard');
}
return $menu;
}
}
42 changes: 42 additions & 0 deletions app/code/Magento/Backend/Test/Unit/Model/MenuBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Unit\Model;

use Magento\Backend\Model\Setup\MenuBuilder;

class MenuBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider afterGetResultDataProvider
*
* @param string $isPub
* @param int $times
* @param bool $result
*/
public function testAfterGetResult($isPub, $times)
{
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false);
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub);
$model = new MenuBuilder($docRootLocator);
/** @var \Magento\Backend\Model\Menu $menu */
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false);
$menu->expects($this->exactly($times))->method('remove')->willReturn(true);

/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false);

$this->assertInstanceOf(
'\Magento\Backend\Model\Menu',
$model->afterGetResult($menuBuilder, $menu)
);
}

public function afterGetResultDataProvider()
{
return [[true, 1], [false, 0],];
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,7 @@
<argument name="isIncludesAvailable" xsi:type="boolean">false</argument>
</arguments>
</type>
<type name="Magento\Backend\Model\Menu\Builder">
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
</type>
</config>
187 changes: 99 additions & 88 deletions app/code/Magento/Tax/Model/Plugin/OrderSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,117 +63,128 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
return;
}

/** @var \Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]|null $taxes */
$taxes = $extensionAttribute->getAppliedTaxes();
if ($taxes == null) {
$taxes = [];
}

/** @var \Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]|null $taxesForItems */
$taxesForItems = $extensionAttribute->getItemAppliedTaxes();
if ($taxesForItems == null) {
$taxesForItems = [];
}

$ratesIdQuoteItemId = [];
foreach ($taxesForItems as $taxesArray) {
foreach ($taxesArray as $rates) {
if (count($rates['rates']) == 1) {
$ratesIdQuoteItemId[$rates['id']][] = [
'id' => $rates['item_id'],
'percent' => $rates['percent'],
'code' => $rates['rates'][0]['code'],
'associated_item_id' => $rates['associated_item_id'],
'item_type' => $rates['item_type'],
'amount' => $rates['amount'],
'base_amount' => $rates['base_amount'],
'real_amount' => $rates['amount'],
'real_base_amount' => $rates['base_amount'],
];
} else {
$percentSum = 0;
foreach ($rates['rates'] as $rate) {
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
$ratesIdQuoteItemId[$rates['id']][] = [
'id' => $rates['item_id'],
'percent' => $rate['percent'],
'code' => $rate['code'],
'associated_item_id' => $rates['associated_item_id'],
'item_type' => $rates['item_type'],
'amount' => $rates['amount'],
'base_amount' => $rates['base_amount'],
'real_amount' => $realAmount,
'real_base_amount' => $realBaseAmount,
];
$percentSum += $rate['percent'];
foreach ($taxesArray['applied_taxes'] as $rates) {
if (isset($rates['extension_attributes'])) {
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
$taxRates = $rates['extension_attributes']->getRates();
if (is_array($taxRates)) {
if (count($taxRates) == 1) {
$ratesIdQuoteItemId[$rates['id']][] = [
'id' => $taxesArray['item_id'],
'percent' => $rates['percent'],
'code' => $taxRates[0]['code'],
'associated_item_id' => $taxesArray['associated_item_id'],
'item_type' => $taxesArray['type'],
'amount' => $rates['amount'],
'base_amount' => $rates['base_amount'],
'real_amount' => $rates['amount'],
'real_base_amount' => $rates['base_amount'],
];
} else {
$percentSum = 0;
foreach ($taxRates as $rate) {
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
$ratesIdQuoteItemId[$rates['id']][] = [
'id' => $taxesArray['item_id'],
'percent' => $rate['percent'],
'code' => $rate['code'],
'associated_item_id' => $taxesArray['associated_item_id'],
'item_type' => $taxesArray['type'],
'amount' => $rates['amount'],
'base_amount' => $rates['base_amount'],
'real_amount' => $realAmount,
'real_base_amount' => $realBaseAmount,
];
$percentSum += $rate['percent'];
}
}
}
}
}
}

foreach ($taxes as $row) {
$id = $row['id'];
// @todo: should be refactored as part of MAGETWO-53366
if (isset($row['rates'])) {
foreach ($row['rates'] as $tax) {
if ($row['percent'] == null) {
$baseRealAmount = $row['base_amount'];
} else {
if ($row['percent'] == 0 || $tax['percent'] == 0) {
continue;
if (isset($row['extension_attributes'])) {
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
$taxRates = $row['extension_attributes']->getRates();
if (is_array($taxRates)) {
foreach ($taxRates as $tax) {
if ($row['percent'] == null) {
$baseRealAmount = $row['base_amount'];
} else {
if ($row['percent'] == 0 || $tax['percent'] == 0) {
continue;
}
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
}
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
}
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
$position = isset($tax['position']) ? $tax['position'] : 0;
$process = isset($row['process']) ? $row['process'] : 0;
$data = [
'order_id' => $order->getEntityId(),
'code' => $tax['code'],
'title' => $tax['title'],
'hidden' => $hidden,
'percent' => $tax['percent'],
'priority' => $priority,
'position' => $position,
'amount' => $row['amount'],
'base_amount' => $row['base_amount'],
'process' => $process,
'base_real_amount' => $baseRealAmount,
];
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
$position = isset($tax['position']) ? $tax['position'] : 0;
$process = isset($row['process']) ? $row['process'] : 0;
$data = [
'order_id' => $order->getEntityId(),
'code' => $tax['code'],
'title' => $tax['title'],
'hidden' => $hidden,
'percent' => $tax['percent'],
'priority' => $priority,
'position' => $position,
'amount' => $row['amount'],
'base_amount' => $row['base_amount'],
'process' => $process,
'base_real_amount' => $baseRealAmount,
];

/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
$orderTax = $this->orderTaxFactory->create();
$result = $orderTax->setData($data)->save();
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
$orderTax = $this->orderTaxFactory->create();
$result = $orderTax->setData($data)->save();

if (isset($ratesIdQuoteItemId[$id])) {
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
if ($quoteItemId['code'] == $tax['code']) {
$itemId = null;
$associatedItemId = null;
if (isset($quoteItemId['id'])) {
//This is a product item
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
$itemId = $item->getId();
} elseif (isset($quoteItemId['associated_item_id'])) {
//This item is associated with a product item
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
$associatedItemId = $item->getId();
}
if (isset($ratesIdQuoteItemId[$id])) {
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
if ($quoteItemId['code'] == $tax['code']) {
$itemId = null;
$associatedItemId = null;
if (isset($quoteItemId['id'])) {
//This is a product item
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
$itemId = $item->getId();
} elseif (isset($quoteItemId['associated_item_id'])) {
//This item is associated with a product item
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
$associatedItemId = $item->getId();
}

$data = [
'item_id' => $itemId,
'tax_id' => $result->getTaxId(),
'tax_percent' => $quoteItemId['percent'],
'associated_item_id' => $associatedItemId,
'amount' => $quoteItemId['amount'],
'base_amount' => $quoteItemId['base_amount'],
'real_amount' => $quoteItemId['real_amount'],
'real_base_amount' => $quoteItemId['real_base_amount'],
'taxable_item_type' => $quoteItemId['item_type'],
];
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
$taxItem = $this->taxItemFactory->create();
$taxItem->setData($data)->save();
$data = [
'item_id' => $itemId,
'tax_id' => $result->getTaxId(),
'tax_percent' => $quoteItemId['percent'],
'associated_item_id' => $associatedItemId,
'amount' => $quoteItemId['amount'],
'base_amount' => $quoteItemId['base_amount'],
'real_amount' => $quoteItemId['real_amount'],
'real_base_amount' => $quoteItemId['real_base_amount'],
'taxable_item_type' => $quoteItemId['item_type'],
];
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
$taxItem = $this->taxItemFactory->create();
$taxItem->setData($data)->save();
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion app/code/Magento/Tax/Model/Quote/ToOrderConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,31 @@ public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order
$extensionAttributes = $this->orderExtensionFactory->create();
}
if (!empty($taxes)) {
foreach ($taxes as $key => $tax) {
$tax['extension_attributes']['rates'] = $tax['rates'];
unset($tax['rates']);
$taxes[$key] = $tax;
}
$extensionAttributes->setAppliedTaxes($taxes);
$extensionAttributes->setConvertingFromQuote(true);
}

$itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
$itemAppliedTaxesModified = [];
if (!empty($itemAppliedTaxes)) {
$extensionAttributes->setItemAppliedTaxes($itemAppliedTaxes);
foreach ($itemAppliedTaxes as $key => $itemAppliedTaxItem) {
if (is_array($itemAppliedTaxItem) && !empty($itemAppliedTaxItem)) {
foreach ($itemAppliedTaxItem as $itemAppliedTax) {
$itemAppliedTaxesModified[$key]['type'] = $itemAppliedTax['item_type'];
$itemAppliedTaxesModified[$key]['item_id'] = $itemAppliedTax['item_id'];
$itemAppliedTaxesModified[$key]['associated_item_id'] = $itemAppliedTax['associated_item_id'];
$itemAppliedTax['extension_attributes']['rates'] = $itemAppliedTax['rates'];
unset($itemAppliedTax['rates']);
$itemAppliedTaxesModified[$key]['applied_taxes'][] = $itemAppliedTax;
}
}
}
$extensionAttributes->setItemAppliedTaxes($itemAppliedTaxesModified);
}
$order->setExtensionAttributes($extensionAttributes);
return $order;
Expand Down
20 changes: 20 additions & 0 deletions app/code/Magento/Tax/Model/Sales/Order/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Tax extends \Magento\Framework\Model\AbstractExtensibleModel implements
const KEY_PERCENT = 'percent';
const KEY_AMOUNT = 'amount';
const KEY_BASE_AMOUNT = 'base_amount';
const KEY_RATES = 'rates';
/**#@-*/

/**
Expand Down Expand Up @@ -136,6 +137,25 @@ public function setBaseAmount($baseAmount)
return $this->setData(self::KEY_BASE_AMOUNT, $baseAmount);
}

/**
*
* @return \Magento\Tax\Api\Data\AppliedTaxRateInterface[]
*/
public function getRates()
{
return $this->getData(self::KEY_RATES);
}

/**
*
* @param \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $rates
* @return $this
*/
public function setRates($rates)
{
return $this->setData(self::KEY_RATES, $rates);
}

/**
* {@inheritdoc}
*
Expand Down
Loading

0 comments on commit 66883d5

Please sign in to comment.