Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to2ce into BUGS
  • Loading branch information
okarpenko committed Jun 30, 2015
2 parents 7c6e388 + 0d9ecaa commit 4ffe4e1
Show file tree
Hide file tree
Showing 32 changed files with 2,064 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ define(
});
if (proceed) {
quote.setPaymentMethod(methodData.method);
//set the totals before setting PaymentData
quote.setTotals(response);
service.setSelectedPaymentData(methodData);
service.setSelectedPaymentInfo(methodInfo);
quote.setTotals(response);
navigator.setCurrent('paymentMethod').goNext();
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/PageCache/Block/Javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function getScriptOptions()
),
'handles' => $this->_layout->getUpdate()->getHandles(),
'originalRequest' => [
'route' => $this->getRequest()->getRouteName(),
'route' => $this->getRequest()->getRouteName(),
'controller' => $this->getRequest()->getControllerName(),
'action' => $this->getRequest()->getActionName(),
'action' => $this->getRequest()->getActionName(),
'uri' => $this->getRequest()->getRequestUri(),
],
'versionCookieName' => \Magento\Framework\App\PageCache\Version::COOKIE_NAME
];
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/PageCache/Controller/Block/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ public function execute()
$currentRoute = $this->getRequest()->getRouteName();
$currentControllerName = $this->getRequest()->getControllerName();
$currentActionName = $this->getRequest()->getActionName();
$currentRequestUri = $this->getRequest()->getRequestUri();

$origRequest = $this->getRequest()->getParam('originalRequest');
$origRequest = json_decode($origRequest, true);
$this->getRequest()->setRouteName($origRequest['route']);
$this->getRequest()->setControllerName($origRequest['controller']);
$this->getRequest()->setActionName($origRequest['action']);
$this->getRequest()->setRequestUri($origRequest['uri']);

/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
$blocks = $this->_getBlocks();
$data = [];
Expand All @@ -41,6 +44,7 @@ public function execute()
$this->getRequest()->setRouteName($currentRoute);
$this->getRequest()->setControllerName($currentControllerName);
$this->getRequest()->setActionName($currentActionName);
$this->getRequest()->setRequestUri($currentRequestUri);

$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
$this->translateInline->processResponseBody($data);
Expand Down
25 changes: 19 additions & 6 deletions app/code/Magento/PageCache/Test/Unit/Block/JavascriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ protected function setUp()
'getControllerName',
'getModuleName',
'getActionName',
'getRequestUri',
'getParam',
'setParams',
'getParams',
'setModuleName',
'isSecure',
'setActionName',
'setRequestUri',
'getCookie'
],
[],
Expand Down Expand Up @@ -122,6 +124,9 @@ public function testGetScriptOptions($isSecure, $url, $expectedResult)
$this->requestMock->expects($this->once())
->method('getActionName')
->will($this->returnValue('action'));
$this->requestMock->expects($this->once())
->method('getRequestUri')
->will($this->returnValue('uri'));
$this->urlBuilderMock->expects($this->once())
->method('getUrl')
->willReturn($url);
Expand Down Expand Up @@ -153,10 +158,11 @@ public function getScriptOptionsDataProvider()
* @param string $route
* @param string $controller
* @param string $action
* @param string $uri
* @param string $expectedResult
* @dataProvider getScriptOptionsPrivateContentDataProvider
*/
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $expectedResult)
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $uri, $expectedResult)
{
$handles = [
'some',
Expand All @@ -179,6 +185,10 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a
->method('getActionName')
->will($this->returnValue($action));

$this->requestMock->expects($this->once())
->method('getRequestUri')
->will($this->returnValue($uri));

$this->urlBuilderMock->expects($this->once())
->method('getUrl')
->willReturn($url);
Expand All @@ -191,14 +201,17 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a

public function getScriptOptionsPrivateContentDataProvider()
{
// @codingStandardsIgnoreStart
return [
'http' => [
'url' => 'http://some-name.com/page_cache/block/render',
'route' => 'route',
'controller' => 'controller',
'action' => 'action',
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action"}~'
'url' => 'http://some-name.com/page_cache/block/render',
'route' => 'route',
'controller' => 'controller',
'action' => 'action',
'uri' => 'uri',
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action","uri":"uri"}~'
],
];
//@codingStandardsIgnoreEnd
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public function testExecuteNotAjax()
public function testExecuteNoParams()
{
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
$this->requestMock->expects($this->at(8))
$this->requestMock->expects($this->at(10))
->method('getParam')
->with($this->equalTo('blocks'), $this->equalTo(''))
->will($this->returnValue(''));
$this->requestMock->expects($this->at(9))
$this->requestMock->expects($this->at(11))
->method('getParam')
->with($this->equalTo('handles'), $this->equalTo(''))
->will($this->returnValue(''));
Expand All @@ -103,7 +103,7 @@ public function testExecute()
{
$blocks = ['block1', 'block2'];
$handles = ['handle1', 'handle2'];
$originalRequest = '{"route":"route","controller":"controller","action":"action"}';
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];

$blockInstance1 = $this->getMock(
Expand Down Expand Up @@ -136,15 +136,18 @@ public function testExecute()
->method('getActionName')
->will($this->returnValue('render'));
$this->requestMock->expects($this->at(4))
->method('getRequestUri')
->will($this->returnValue('uri'));
$this->requestMock->expects($this->at(5))
->method('getParam')
->with($this->equalTo('originalRequest'))
->will($this->returnValue($originalRequest));

$this->requestMock->expects($this->at(8))
$this->requestMock->expects($this->at(10))
->method('getParam')
->with($this->equalTo('blocks'), $this->equalTo(''))
->will($this->returnValue(json_encode($blocks)));
$this->requestMock->expects($this->at(9))
$this->requestMock->expects($this->at(11))
->method('getParam')
->with($this->equalTo('handles'), $this->equalTo(''))
->will($this->returnValue(json_encode($handles)));
Expand Down
14 changes: 0 additions & 14 deletions app/code/Magento/Sales/etc/extension_attributes.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/code/Magento/Tax/Model/App/Action/ContextPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function aroundDispatch(
\Closure $proceed,
\Magento\Framework\App\RequestInterface $request
) {
if (!$this->moduleManager->isEnabled('Magento_PageCache') ||
if (!$this->customerSession->isLoggedIn() ||
!$this->moduleManager->isEnabled('Magento_PageCache') ||
!$this->cacheConfig->isEnabled() ||
!$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
return $proceed($request);
Expand Down
155 changes: 0 additions & 155 deletions app/code/Magento/Tax/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class Observer
*/
protected $_taxData;

/**
* @var \Magento\Tax\Model\Sales\Order\TaxFactory
*/
protected $_orderTaxFactory;

/**
* @var \Magento\Sales\Model\Order\Tax\ItemFactory
*/
protected $_taxItemFactory;

/**
* @var \Magento\Tax\Model\Calculation
*/
Expand Down Expand Up @@ -57,8 +47,6 @@ class Observer

/**
* @param \Magento\Tax\Helper\Data $taxData
* @param \Magento\Tax\Model\Sales\Order\TaxFactory $orderTaxFactory
* @param \Magento\Sales\Model\Order\Tax\ItemFactory $taxItemFactory
* @param \Magento\Tax\Model\Calculation $calculation
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Tax\Model\Resource\Report\TaxFactory $reportTaxFactory
Expand All @@ -67,17 +55,13 @@ class Observer
*/
public function __construct(
\Magento\Tax\Helper\Data $taxData,
\Magento\Tax\Model\Sales\Order\TaxFactory $orderTaxFactory,
\Magento\Sales\Model\Order\Tax\ItemFactory $taxItemFactory,
\Magento\Tax\Model\Calculation $calculation,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Tax\Model\Resource\Report\TaxFactory $reportTaxFactory,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\Registry $registry
) {
$this->_taxData = $taxData;
$this->_orderTaxFactory = $orderTaxFactory;
$this->_taxItemFactory = $taxItemFactory;
$this->_calculation = $calculation;
$this->_localeDate = $localeDate;
$this->_reportTaxFactory = $reportTaxFactory;
Expand Down Expand Up @@ -114,145 +98,6 @@ public function salesEventConvertQuoteAddressToOrder(\Magento\Framework\Event\Ob
}
}

/**
* Save order tax information
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function salesEventOrderAfterSave(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();

if (!$order->getConvertingFromQuote() || $order->getAppliedTaxIsSaved()) {
return;
}

$taxesAttr = $order->getCustomAttribute('applied_taxes');
if (is_null($taxesAttr) || !is_array($taxesAttr->getValue())) {
$taxes = [];
} else {
$taxes = $taxesAttr->getValue();
}

$getTaxesForItemsAttr = $order->getCustomAttribute('item_applied_taxes');
if (is_null($getTaxesForItemsAttr) || !is_array($getTaxesForItemsAttr->getValue())) {
$getTaxesForItems = [];
} else {
$getTaxesForItems = $getTaxesForItemsAttr->getValue();
}

$ratesIdQuoteItemId = [];
foreach ($getTaxesForItems 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) {
$real_amount = $rates['amount'] * $rate['percent'] / $rates['percent'];
$real_base_amount = $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' => $real_amount,
'real_base_amount' => $real_base_amount,
];
$percentSum += $rate['percent'];
}
}
}
}

foreach ($taxes as $row) {
$id = $row['id'];
foreach ($row['rates'] as $tax) {
if (is_null($row['percent'])) {
$baseRealAmount = $row['base_amount'];
} else {
if ($row['percent'] == 0 || $tax['percent'] == 0) {
continue;
}
$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->getId(),
'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();

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();
}
}
}
}
}

$order->setAppliedTaxIsSaved(true);
}

/**
* Refresh sales tax report statistics for last day
*
Expand Down
Loading

0 comments on commit 4ffe4e1

Please sign in to comment.