Skip to content

Commit

Permalink
Merge pull request #619 from magento-firedrakes/MAGETWO-52746
Browse files Browse the repository at this point in the history
[Firedrakes] P0-P1 Bug fixes
  • Loading branch information
slavvka committed May 14, 2016
2 parents fe3bf09 + 4d5ca55 commit b5900bc
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 33 deletions.
5 changes: 5 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<argument name="productRepository" xsi:type="object">Magento\Catalog\Api\ProductRepositoryInterface\Proxy</argument>
</arguments>
</type>
<type name="Magento\Catalog\Helper\Product\Edit\Action\Attribute">
<arguments>
<argument name="session" xsi:type="object">Magento\Backend\Model\Session\Proxy</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Product">
<arguments>
<argument name="catalogProductStatus" xsi:type="object">Magento\Catalog\Model\Product\Attribute\Source\Status\Proxy</argument>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Indexer\Fulltext;

use Magento\Framework\Indexer\AbstractProcessor;
use Magento\CatalogSearch\Model\Indexer\Fulltext;

/**
* Class Processor
*/
class Processor extends AbstractProcessor
{
/**
* Indexer ID
*/
const INDEXER_ID = Fulltext::INDEXER_ID;
}
44 changes: 34 additions & 10 deletions app/code/Magento/Sales/Model/Order/Creditmemo/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,40 @@ public function setOrderItem(\Magento\Sales\Model\Order\Item $item)
public function getOrderItem()
{
if ($this->_orderItem === null) {
if ($this->getCreditmemo()) {
$this->_orderItem = $this->getCreditmemo()->getOrder()->getItemById($this->getOrderItemId());
} else {
$this->_orderItem = $this->_orderItemFactory->create()->load($this->getOrderItemId());
}
$this->_orderItem = $this->getOrderItemWithoutCaching();
}
return $this->_orderItem;
}

/**
* Retrieve order item instance without set it to property.
* It is need for ability to process setQty on api when credit memo and order has not built yet.
*
* @return \Magento\Sales\Model\Order\Item
*/
private function getOrderItemWithoutCaching()
{
if ($this->getCreditmemo()) {
$orderItem = $this->getCreditmemo()->getOrder()->getItemById($this->getOrderItemId());
} else {
$orderItem = $this->_orderItemFactory->create()->load($this->getOrderItemId());
}

return $orderItem;
}

/**
* Checks if quantity available for refund
*
* @param int $qty
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return bool
*/
private function isQtyAvailable($qty, \Magento\Sales\Model\Order\Item $orderItem)
{
return $qty <= $orderItem->getQtyToRefund() || $orderItem->isDummy();
}

/**
* Declare qty
*
Expand All @@ -145,16 +170,14 @@ public function getOrderItem()
*/
public function setQty($qty)
{
if ($this->getOrderItem()->getIsQtyDecimal()) {
$orderItem = $this->getOrderItemWithoutCaching();
if ($orderItem->getIsQtyDecimal()) {
$qty = (double)$qty;
} else {
$qty = (int)$qty;
}
$qty = $qty > 0 ? $qty : 0;
/**
* Check qty availability
*/
if ($qty <= $this->getOrderItem()->getQtyToRefund() || $this->getOrderItem()->isDummy()) {
if ($this->isQtyAvailable($qty, $orderItem)) {
$this->setData('qty', $qty);
} else {
throw new \Magento\Framework\Exception\LocalizedException(
Expand Down Expand Up @@ -582,6 +605,7 @@ public function getWeeeTaxRowDisposition()
}

//@codeCoverageIgnoreStart

/**
* {@inheritdoc}
*/
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/Model/Service/CreditmemoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function refund(
$creditmemo->setState(\Magento\Sales\Model\Order\Creditmemo::STATE_REFUNDED);

foreach ($creditmemo->getAllItems() as $item) {
$item->setCreditMemo($creditmemo);
if ($item->getQty() > 0) {
$item->register();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ public function testSetQtyDecimalException()
$orderItemMock->expects($this->once())
->method('getQtyToRefund')
->willReturn($orderItemQty);

$orderItemMock->expects($this->atLeastOnce())
->method('load')
->willReturnSelf();
$this->orderItemFactoryMock->expects($this->atLeastOnce())
->method('create')
->willReturn($orderItemMock);
$this->item->setData(CreditmemoItemInterface::NAME, $name);
$this->item->setOrderItem($orderItemMock);
$this->item->setQty($qty);
Expand All @@ -136,7 +141,12 @@ public function testSetQtyNumericException()
$orderItemMock->expects($this->once())
->method('getQtyToRefund')
->willReturn($orderItemQty);

$orderItemMock->expects($this->atLeastOnce())
->method('load')
->willReturnSelf();
$this->orderItemFactoryMock->expects($this->atLeastOnce())
->method('create')
->willReturn($orderItemMock);
$this->item->setData(CreditmemoItemInterface::NAME, $name);
$this->item->setOrderItem($orderItemMock);
$this->item->setQty($qty);
Expand All @@ -156,7 +166,12 @@ public function testSetQty()
$orderItemMock->expects($this->once())
->method('getQtyToRefund')
->willReturn($orderItemQty);

$orderItemMock->expects($this->atLeastOnce())
->method('load')
->willReturnSelf();
$this->orderItemFactoryMock->expects($this->atLeastOnce())
->method('create')
->willReturn($orderItemMock);
$this->item->setOrderItem($orderItemMock);
$this->item->setQty($qty);
$this->assertEquals($qty, $this->item->getQty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
*/
namespace Magento\Sales\Test\Unit\Model\Service;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Sales\Api\Data\CreditmemoInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Creditmemo;
use Magento\Sales\Model\Order\Creditmemo\Item;

/**
* Class CreditmemoServiceTest
Expand Down Expand Up @@ -37,6 +42,11 @@ class CreditmemoServiceTest extends \PHPUnit_Framework_TestCase
*/
protected $creditmemoNotifierMock;

/**
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $priceCurrencyMock;

/**
* @var \Magento\Sales\Model\Service\CreditmemoService
*/
Expand Down Expand Up @@ -82,6 +92,7 @@ protected function setUp()
'',
false
);
$this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)->getMockForAbstractClass();

$this->creditmemoService = $objectManager->getObject(
'Magento\Sales\Model\Service\CreditmemoService',
Expand All @@ -90,7 +101,8 @@ protected function setUp()
'creditmemoCommentRepository' => $this->creditmemoCommentRepositoryMock,
'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock,
'filterBuilder' => $this->filterBuilderMock,
'creditmemoNotifier' => $this->creditmemoNotifierMock
'creditmemoNotifier' => $this->creditmemoNotifierMock,
'priceCurrency' => $this->priceCurrencyMock
]
);
}
Expand Down Expand Up @@ -183,4 +195,69 @@ public function testNotify()

$this->assertEquals($returnValue, $this->creditmemoService->notify($id));
}

public function testRefund()
{
$creditMemoMock = $this->getMockBuilder(Creditmemo::class)
->setMethods(['getId', 'getOrder', 'getBaseGrandTotal', 'getAllItems', 'setDoTransaction'])
->disableOriginalConstructor()
->getMock();
$creditMemoMock->expects($this->once())->method('getId')->willReturn(null);
$orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
$creditMemoMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock);
$itemMock = $this->getMockBuilder(
Item::class
)->disableOriginalConstructor()->getMock();
$creditMemoMock->expects($this->once())->method('getAllItems')->willReturn([$itemMock]);
$itemMock->expects($this->once()) -> method('setCreditMemo')->with($creditMemoMock);
$itemMock->expects($this->once()) -> method('getQty')->willReturn(1);
$itemMock->expects($this->once()) -> method('register');
$creditMemoMock->expects($this->once())->method('setDoTransaction')->with(false);
$this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true));
}

/**
* @expectedExceptionMessage The most money available to refund is 1.
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testRefundExpectsMoneyAvailableToReturn()
{
$baseGrandTotal = 10;
$baseTotalRefunded = 9;
$baseTotalPaid = 10;
$creditMemoMock = $this->getMockBuilder(CreditmemoInterface::class)
->setMethods(['getId', 'getOrder', 'getBaseGrandTotal', 'formatBasePrice'])
->getMockForAbstractClass();
$creditMemoMock->expects($this->once())->method('getId')->willReturn(null);
$orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
$creditMemoMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock);
$creditMemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn($baseGrandTotal);
$orderMock->expects($this->atLeastOnce())->method('getBaseTotalRefunded')->willReturn($baseTotalRefunded);
$this->priceCurrencyMock->expects($this->exactly(2))->method('round')->withConsecutive(
[$baseTotalRefunded + $baseGrandTotal],
[$baseTotalPaid]
)->willReturnOnConsecutiveCalls(
$baseTotalRefunded + $baseGrandTotal,
$baseTotalPaid
);
$orderMock->expects($this->atLeastOnce())->method('getBaseTotalPaid')->willReturn($baseTotalPaid);
$baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
$orderMock->expects($this->once())->method('formatBasePrice')->with(
$baseAvailableRefund
)->willReturn($baseAvailableRefund);
$this->creditmemoService->refund($creditMemoMock, true);
}

/**
* @expectedExceptionMessage We cannot register an existing credit memo.
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testRefundDoNotExpectsId()
{
$creditMemoMock = $this->getMockBuilder(CreditmemoInterface::class)
->setMethods(['getId'])
->getMockForAbstractClass();
$creditMemoMock->expects($this->once())->method('getId')->willReturn(444);
$this->creditmemoService->refund($creditMemoMock, true);
}
}
18 changes: 18 additions & 0 deletions app/code/Magento/Sales/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/orders/create" method="PUT">
<service class="Magento\Sales\Api\OrderRepositoryInterface" method="save"/>
<resources>
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/orders/:parent_id" method="PUT">
<service class="Magento\Sales\Api\OrderAddressRepositoryInterface" method="save"/>
<resources>
Expand Down Expand Up @@ -157,6 +163,12 @@
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/creditmemo/refund" method="POST">
<service class="Magento\Sales\Api\CreditmemoManagementInterface" method="refund"/>
<resources>
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/creditmemo/:id/comments" method="POST">
<service class="Magento\Sales\Api\CreditmemoCommentRepositoryInterface" method="save"/>
<resources>
Expand Down Expand Up @@ -223,6 +235,12 @@
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/orders/" method="POST">
<service class="Magento\Sales\Api\OrderRepositoryInterface" method="save"/>
<resources>
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/transactions/:id" method="GET">
<service class="Magento\Sales\Api\TransactionRepositoryInterface" method="get"/>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
<field name="apply_to_shipping">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox-toggle-notice</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="source" xsi:type="string">sales_rule</item>
Expand All @@ -445,6 +446,10 @@
<item name="true" xsi:type="number">1</item>
<item name="false" xsi:type="number">0</item>
</item>
<item name="notices" xsi:type="array">
<item name="0" xsi:type="string" translate="true">Discount amount is applied to subtotal only</item>
<item name="1" xsi:type="string" translate="true">Discount amount is applied to subtotal and shipping amount separately</item>
</item>
<item name="default" xsi:type="number">0</item>
<item name="label" xsi:type="string" translate="true">Apply to Shipping Amount</item>
</item>
Expand Down
27 changes: 26 additions & 1 deletion app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ class Store extends AbstractExtensibleModel implements
*/
private $_storeManager;

/**
* @var \Magento\Framework\Url\ModifierInterface
*/
private $urlModifier;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -640,7 +645,10 @@ public function getBaseUrl($type = UrlInterface::URL_TYPE_LINK, $secure = null)
$url = str_replace(self::BASE_URL_PLACEHOLDER, $this->_request->getDistroBaseUrl(), $url);
}

$this->_baseUrlCache[$cacheKey] = rtrim($url, '/') . '/';
$this->_baseUrlCache[$cacheKey] = $this->getUrlModifier()->execute(
rtrim($url, '/') . '/',
\Magento\Framework\Url\ModifierInterface::MODE_BASE
);
}

return $this->_baseUrlCache[$cacheKey];
Expand Down Expand Up @@ -1306,4 +1314,21 @@ public function setExtensionAttributes(
) {
return $this->_setExtensionAttributes($extensionAttributes);
}

/**
* Gets URL modifier.
*
* @return \Magento\Framework\Url\ModifierInterface
* @deprecated
*/
private function getUrlModifier()
{
if ($this->urlModifier === null) {
$this->urlModifier = \Magento\Framework\App\ObjectManager::getInstance()->get(
'Magento\Framework\Url\ModifierInterface'
);
}

return $this->urlModifier;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Store/Model/StoreResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
*/
protected $scopeCode;

/*
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
Expand Down
Loading

0 comments on commit b5900bc

Please sign in to comment.