Skip to content

Commit 4693537

Browse files
author
Robert He
committed
MAGETWO-33665 : Refactor Quote module to use mutable data object interfaces
-- fixes from code review -- fixes to testcases
1 parent 118a6b5 commit 4693537

File tree

9 files changed

+125
-95
lines changed

9 files changed

+125
-95
lines changed

app/code/Magento/Quote/Api/Data/AddressInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ public function setRegion($region);
8383
/**
8484
* Get region id
8585
*
86-
* @return string
86+
* @return int
8787
*/
8888
public function getRegionId();
8989

9090
/**
9191
* Set region id
9292
*
93-
* @param string $regionId
93+
* @param int $regionId
9494
* @return $this
9595
*/
9696
public function setRegionId($regionId);
@@ -308,14 +308,14 @@ public function setVatId($vatId);
308308
/**
309309
* Get customer id
310310
*
311-
* @return string|null
311+
* @return int
312312
*/
313313
public function getCustomerId();
314314

315315
/**
316316
* Set customer id
317317
*
318-
* @param string $customerId
318+
* @param int $customerId
319319
* @return $this
320320
*/
321321
public function setCustomerId($customerId);

app/code/Magento/Quote/Api/Data/CartInterface.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getId();
6262
/**
6363
* Sets the cart/quote ID.
6464
*
65-
* @param string $id
65+
* @param int $id
6666
* @return $this
6767
*/
6868
public function setId($id);
@@ -74,13 +74,29 @@ public function setId($id);
7474
*/
7575
public function getCreatedAt();
7676

77+
/**
78+
* Sets the cart creation date and time.
79+
*
80+
* @param string $createdAt
81+
* @return $this
82+
*/
83+
public function setCreatedAt($createdAt);
84+
7785
/**
7886
* Returns the cart last update date and time.
7987
*
8088
* @return string|null Cart last update date and time. Otherwise, null.
8189
*/
8290
public function getUpdatedAt();
8391

92+
/**
93+
* Sets the cart last update date and time.
94+
*
95+
* @param string $updatedAt
96+
* @return $this
97+
*/
98+
public function setUpdatedAt($updatedAt);
99+
84100
/**
85101
* Returns the cart conversion date and time.
86102
*
@@ -228,29 +244,29 @@ public function setBillingAddress(\Magento\Quote\Api\Data\AddressInterface $bill
228244
/**
229245
* Returns the reserved order ID for the cart.
230246
*
231-
* @return string|null Reserved order ID. Otherwise, null.
247+
* @return int|null Reserved order ID. Otherwise, null.
232248
*/
233249
public function getReservedOrderId();
234250

235251
/**
236252
* Sets the reserved order ID for the cart.
237253
*
238-
* @param string $reservedOrderId
254+
* @param int $reservedOrderId
239255
* @return $this
240256
*/
241257
public function setReservedOrderId($reservedOrderId);
242258

243259
/**
244260
* Returns the original order ID for the cart.
245261
*
246-
* @return string|null Original order ID. Otherwise, null.
262+
* @return int|null Original order ID. Otherwise, null.
247263
*/
248264
public function getOrigOrderId();
249265

250266
/**
251267
* Sets the original order ID for the cart.
252268
*
253-
* @param string $origOrderId
269+
* @param int $origOrderId
254270
* @return $this
255271
*/
256272
public function setOrigOrderId($origOrderId);
@@ -318,14 +334,14 @@ public function setCustomerNoteNotify($customerNoteNotify);
318334
/**
319335
* Get customer tax class ID.
320336
*
321-
* @return string|null
337+
* @return int|null
322338
*/
323339
public function getCustomerTaxClassId();
324340

325341
/**
326342
* Set customer tax class ID.
327343
*
328-
* @param string $customerTaxClassId
344+
* @param int $customerTaxClassId
329345
* @return $this
330346
*/
331347
public function setCustomerTaxClassId($customerTaxClassId);

app/code/Magento/Quote/Api/Data/CartItemInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function setSku($sku);
5959
/**
6060
* Returns the product quantity.
6161
*
62-
* @return int Product quantity.
62+
* @return float Product quantity.
6363
*/
6464
public function getQty();
6565

6666
/**
6767
* Sets the product quantity.
6868
*
69-
* @param int $qty
69+
* @param float $qty
7070
* @return $this
7171
*/
7272
public function setQty($qty);

app/code/Magento/Quote/Api/Data/TotalsItemInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public function setBasePrice($basePrice);
126126
/**
127127
* Returns the item quantity.
128128
*
129-
* @return int Item quantity.
129+
* @return float Item quantity.
130130
*/
131131
public function getQty();
132132

133133
/**
134134
* Sets the item quantity.
135135
*
136-
* @param int $qty
136+
* @param float $qty
137137
* @return $this
138138
*/
139139
public function setQty($qty);
@@ -216,14 +216,14 @@ public function setBaseTaxAmount($baseTaxAmount);
216216
/**
217217
* Returns the tax percent.
218218
*
219-
* @return int|null Tax percent. Otherwise, null.
219+
* @return float|null Tax percent. Otherwise, null.
220220
*/
221221
public function getTaxPercent();
222222

223223
/**
224224
* Sets the tax percent.
225225
*
226-
* @param int $taxPercent
226+
* @param float $taxPercent
227227
* @return $this
228228
*/
229229
public function setTaxPercent($taxPercent);
@@ -261,14 +261,14 @@ public function setBaseDiscountAmount($baseDiscountAmount);
261261
/**
262262
* Returns the discount percent.
263263
*
264-
* @return int|null Discount percent. Otherwise, null.
264+
* @return float|null Discount percent. Otherwise, null.
265265
*/
266266
public function getDiscountPercent();
267267

268268
/**
269269
* Sets the discount percent.
270270
*
271-
* @param int $discountPercent
271+
* @param float $discountPercent
272272
* @return $this
273273
*/
274274
public function setDiscountPercent($discountPercent);

app/code/Magento/Quote/Model/Quote.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
* sales_quote_delete_after
2828
*
2929
* @method Quote setStoreId(int $value)
30-
* @method Quote setCreatedAt(string $value)
31-
* @method Quote setUpdatedAt(string $value)
3230
* @method Quote setIsVirtual(int $value)
3331
* @method int getIsMultiShipping()
3432
* @method Quote setIsMultiShipping(int $value)
@@ -502,6 +500,14 @@ public function getCreatedAt()
502500
return $this->_getData(self::KEY_CREATED_AT);
503501
}
504502

503+
/**
504+
* {@inheritdoc}
505+
*/
506+
public function setCreatedAt($createdAt)
507+
{
508+
return $this->setData(self::KEY_CREATED_AT, $createdAt);
509+
}
510+
505511
/**
506512
* {@inheritdoc}
507513
*/
@@ -510,6 +516,14 @@ public function getUpdatedAt()
510516
return $this->_getData(self::KEY_UPDATED_AT);
511517
}
512518

519+
/**
520+
* {@inheritdoc}
521+
*/
522+
public function setUpdatedAt($updatedAt)
523+
{
524+
return $this->setData(self::KEY_UPDATED_AT, $updatedAt);
525+
}
526+
513527
/**
514528
* {@inheritdoc}
515529
*/

app/code/Magento/Quote/Model/Quote/Item.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,31 @@ public function addQty($qty)
330330
return $this;
331331
}
332332

333+
/**
334+
* Declare quote item quantity
335+
*
336+
* @param float $qty
337+
* @return $this
338+
*/
339+
public function setQty($qty)
340+
{
341+
$qty = $this->_prepareQty($qty);
342+
$oldQty = $this->_getData(self::KEY_QTY);
343+
$this->setData(self::KEY_QTY, $qty);
344+
345+
$this->_eventManager->dispatch('sales_quote_item_qty_set_after', ['item' => $this]);
346+
347+
if ($this->getQuote() && $this->getQuote()->getIgnoreOldQty()) {
348+
return $this;
349+
}
350+
351+
if ($this->getUseOldQty()) {
352+
$this->setData(self::KEY_QTY, $oldQty);
353+
}
354+
355+
return $this;
356+
}
357+
333358
/**
334359
* Retrieve option product with Qty
335360
*
@@ -481,6 +506,25 @@ public function compare($item)
481506
return $this->quoteItemCompare->compare($this, $item);
482507
}
483508

509+
/**
510+
* Get item product type
511+
*
512+
* @return string
513+
*/
514+
public function getProductType()
515+
{
516+
$option = $this->getOptionByCode(self::KEY_PRODUCT_TYPE);
517+
if ($option) {
518+
return $option->getValue();
519+
}
520+
$product = $this->getProduct();
521+
if ($product) {
522+
return $product->getTypeId();
523+
}
524+
// $product should always exist or there will be an error in getProduct()
525+
return $this->_getData(self::KEY_PRODUCT_TYPE);
526+
}
527+
484528
/**
485529
* Return real product type of item
486530
*
@@ -902,31 +946,6 @@ public function getQty()
902946
return $this->getData(self::KEY_QTY);
903947
}
904948

905-
/**
906-
* Declare quote item quantity
907-
*
908-
* @param float $qty
909-
* @return $this
910-
*/
911-
public function setQty($qty)
912-
{
913-
$qty = $this->_prepareQty($qty);
914-
$oldQty = $this->_getData(self::KEY_QTY);
915-
$this->setData(self::KEY_QTY, $qty);
916-
917-
$this->_eventManager->dispatch('sales_quote_item_qty_set_after', ['item' => $this]);
918-
919-
if ($this->getQuote() && $this->getQuote()->getIgnoreOldQty()) {
920-
return $this;
921-
}
922-
923-
if ($this->getUseOldQty()) {
924-
$this->setData(self::KEY_QTY, $oldQty);
925-
}
926-
927-
return $this;
928-
}
929-
930949
/**
931950
* {@inheritdoc}
932951
*/
@@ -959,25 +978,6 @@ public function setPrice($price)
959978
return $this->setData(self::KEY_PRICE, $price);
960979
}
961980

962-
/**
963-
* Get item product type
964-
*
965-
* @return string
966-
*/
967-
public function getProductType()
968-
{
969-
$option = $this->getOptionByCode(self::KEY_PRODUCT_TYPE);
970-
if ($option) {
971-
return $option->getValue();
972-
}
973-
$product = $this->getProduct();
974-
if ($product) {
975-
return $product->getTypeId();
976-
}
977-
// $product should always exist or there will be an error in getProduct()
978-
return $this->_getData(self::KEY_PRODUCT_TYPE);
979-
}
980-
981981
/**
982982
* {@inheritdoc}
983983
*/

dev/tests/unit/testsuite/Magento/Quote/Model/Quote/Item/RepositoryTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ protected function setUp()
5555
$this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false);
5656
$this->productRepositoryMock =
5757
$this->getMock('Magento\Catalog\Api\ProductRepositoryInterface', [], [], '', false);
58-
$methods = ['setQuoteId', 'setItemId', 'create'];
5958
$this->itemDataFactoryMock =
60-
$this->getMock('Magento\Quote\Api\Data\CartItemInterfaceFactory', $methods, [], '', false);
59+
$this->getMock('Magento\Quote\Api\Data\CartItemInterfaceFactory', ['create'], [], '', false);
6160
$this->dataMock = $this->getMock('Magento\Quote\Api\Data\CartItemInterface');
6261
$this->quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
6362
$this->productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
@@ -313,10 +312,10 @@ public function testDeleteById()
313312
{
314313
$cartId = 11;
315314
$itemId = 5;
316-
$this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->itemDataFactoryMock);
317-
$this->itemDataFactoryMock->expects($this->once())->method('setQuoteId')
318-
->with($cartId)->willReturn($this->itemDataFactoryMock);
319-
$this->itemDataFactoryMock->expects($this->once())->method('setItemId')
315+
$this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock);
316+
$this->dataMock->expects($this->once())->method('setQuoteId')
317+
->with($cartId)->willReturn($this->dataMock);
318+
$this->dataMock->expects($this->once())->method('setItemId')
320319
->with($itemId)->willReturn($this->dataMock);
321320
$this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
322321
$this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);

dev/tests/unit/testsuite/Magento/Quote/Model/QuoteRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function setUp()
6363
$this->storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
6464
$this->searchResultsDataFactory = $this->getMock(
6565
'\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory',
66-
['setSearchCriteria', 'setTotalCount', 'setItems', 'create'],
66+
['create'],
6767
[],
6868
'',
6969
false

0 commit comments

Comments
 (0)