Skip to content

Commit

Permalink
Merge pull request #425 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Bug fixes
  • Loading branch information
vpelipenko committed Jul 8, 2015
2 parents e9b1713 + e76abd7 commit c0658ab
Showing 4 changed files with 155 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/Model/Quote/Item/Processor.php
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ public function prepare(Item $item, Object $request, Product $candidate)
/**
* We specify qty after we know about parent (for stock)
*/
if ($request->getResetCount()) {
if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
$item->setData(CartItemInterface::KEY_QTY, 0);
}
$item->addQty($candidate->getCartQty());
161 changes: 149 additions & 12 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php
Original file line number Diff line number Diff line change
@@ -72,7 +72,16 @@ protected function setUp()

$this->itemMock = $this->getMock(
'Magento\Quote\Model\Quote\Item',
['getId', 'setOptions', '__wakeup', 'setProduct', 'addQty', 'setCustomPrice', 'setOriginalCustomPrice'],
[
'getId',
'setOptions',
'__wakeup',
'setProduct',
'addQty',
'setCustomPrice',
'setOriginalCustomPrice',
'setData'
],
[],
'',
false
@@ -109,7 +118,7 @@ protected function setUp()

$this->productMock = $this->getMock(
'Magento\Catalog\Model\Product',
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty'],
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent'],
[],
'',
false
@@ -148,8 +157,12 @@ public function testInitWithQtyModification()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->any())
->method('setData')
->with($this->equalTo('qty'), $this->equalTo(0));

->willReturnMap(
[
['store_id', $storeId],
['qty', 0],
]
);

$this->storeMock->expects($this->any())
->method('getId')
@@ -177,15 +190,20 @@ public function testInitWithoutModification()
->method('getParentProductId')
->will($this->returnValue(true));


$this->itemMock->expects($this->never())->method('setOptions');
$this->itemMock->expects($this->never())->method('setProduct');

$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));

$this->itemMock->expects($this->never())->method('setData');
$this->itemMock->expects($this->any())
->method('setData')
->willReturnMap(
[
['store_id', $storeId],
]
);

$this->storeMock->expects($this->any())
->method('getId')
@@ -222,7 +240,13 @@ public function testInitWithoutModificationAdminhtmlAreaCode()
->method('getId')
->will($this->returnValue($itemId));

$this->itemMock->expects($this->never())->method('setData');
$this->itemMock->expects($this->any())
->method('setData')
->willReturnMap(
[
['store_id', $storeId],
]
);

$this->storeMock->expects($this->any())
->method('getId')
@@ -238,58 +262,171 @@ public function testPrepare()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));

$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');

$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(false));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));

$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));

$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}

public function testPrepareWithResetCountAndStick()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(true));

$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');

$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));

$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));

$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}

public function testPrepareWithResetCountAndNotStickAndOtherItemId()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 2;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));

$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');

$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));

$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));

$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
}

public function testPrepareResetCount()
public function testPrepareWithResetCountAndNotStickAndSameItemId()
{
$qty = 3000000000;
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;

$this->objectMock->expects($this->any())
->method('getResetCount')
->will($this->returnValue(true));

$this->itemMock->expects($this->any())
->method('getId')
->will($this->returnValue($itemId));
$this->itemMock->expects($this->once())
->method('setData')
->with(CartItemInterface::KEY_QTY, 0);

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));

$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);

$this->objectMock->expects($this->any())
->method('getCustomPrice')
->will($this->returnValue($customPrice));
$this->objectMock->expects($this->any())
->method('getId')
->will($this->returnValue($requestItemId));

$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('setCustomPrice')
->will($this->returnValue($customPrice));
$this->itemMock->expects($this->any())
$this->itemMock->expects($this->once())
->method('setOriginalCustomPrice')
->will($this->returnValue($customPrice));

2 changes: 1 addition & 1 deletion app/code/Magento/Reports/Model/Event/Observer.php
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ public function catalogProductView(\Magento\Framework\Event\Observer $observer)
$productId = $observer->getEvent()->getProduct()->getId();

$viewData['product_id'] = $productId;

$viewData['store_id'] = $this->_storeManager->getStore()->getId();
if ($this->_customerSession->isLoggedIn()) {
$viewData['customer_id'] = $this->_customerSession->getCustomerId();
} else {
Original file line number Diff line number Diff line change
@@ -85,7 +85,6 @@ public function setUp()

/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject $storeManager */
$storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');

$this->storeMock = $this->getMockBuilder('\Magento\Store\Model\Store')
->disableOriginalConstructor()->getMock();

@@ -128,7 +127,8 @@ public function testCatalogProductViewCustomer()
$storeId = 1;
$expectedViewedData = [
'product_id' => $productId,
'customer_id' => $customerId
'customer_id' => $customerId,
'store_id' => $storeId,
];

$expectedEventData = [
@@ -160,7 +160,8 @@ public function testCatalogProductViewVisitor()
$storeId = 1;
$expectedViewedData = [
'product_id' => $productId,
'visitor_id' => $visitorId
'visitor_id' => $visitorId,
'store_id' => $storeId,
];

$expectedEventData = [

0 comments on commit c0658ab

Please sign in to comment.