Skip to content

Commit f825363

Browse files
authored
ENGCOM-7561: [Wishlist] Giving the possibility to set/update item description on item update #28222
2 parents c08ad91 + baf9b58 commit f825363

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class Wishlist extends AbstractModel implements IdentityInterface
181181
* @param Json|null $serializer
182182
* @param StockRegistryInterface|null $stockRegistry
183183
* @param ScopeConfigInterface|null $scopeConfig
184+
*
184185
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
185186
*/
186187
public function __construct(
@@ -226,6 +227,7 @@ public function __construct(
226227
*
227228
* @param int $customerId
228229
* @param bool $create Create wishlist if don't exists
230+
*
229231
* @return $this
230232
*/
231233
public function loadByCustomerId($customerId, $create = false)
@@ -274,6 +276,7 @@ public function generateSharingCode()
274276
* Load by sharing code
275277
*
276278
* @param string $code
279+
*
277280
* @return $this
278281
*/
279282
public function loadByCode($code)
@@ -370,6 +373,7 @@ protected function _addCatalogProduct(Product $product, $qty = 1, $forciblySetQt
370373
* Retrieve wishlist item collection
371374
*
372375
* @return \Magento\Wishlist\Model\ResourceModel\Item\Collection
376+
*
373377
* @throws NoSuchEntityException
374378
*/
375379
public function getItemCollection()
@@ -389,6 +393,7 @@ public function getItemCollection()
389393
* Retrieve wishlist item collection
390394
*
391395
* @param int $itemId
396+
*
392397
* @return false|Item
393398
*/
394399
public function getItem($itemId)
@@ -403,7 +408,9 @@ public function getItem($itemId)
403408
* Adding item to wishlist
404409
*
405410
* @param Item $item
411+
*
406412
* @return $this
413+
*
407414
* @throws Exception
408415
*/
409416
public function addItem(Item $item)
@@ -424,9 +431,12 @@ public function addItem(Item $item)
424431
* @param int|Product $product
425432
* @param DataObject|array|string|null $buyRequest
426433
* @param bool $forciblySetQty
434+
*
427435
* @return Item|string
436+
*
428437
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
429438
* @SuppressWarnings(PHPMD.NPathComplexity)
439+
*
430440
* @throws LocalizedException
431441
* @throws InvalidArgumentException
432442
*/
@@ -529,7 +539,9 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
529539
* Set customer id
530540
*
531541
* @param int $customerId
542+
*
532543
* @return $this
544+
*
533545
* @throws LocalizedException
534546
*/
535547
public function setCustomerId($customerId)
@@ -541,6 +553,7 @@ public function setCustomerId($customerId)
541553
* Retrieve customer id
542554
*
543555
* @return int
556+
*
544557
* @throws LocalizedException
545558
*/
546559
public function getCustomerId()
@@ -552,6 +565,7 @@ public function getCustomerId()
552565
* Retrieve data for save
553566
*
554567
* @return array
568+
*
555569
* @throws LocalizedException
556570
*/
557571
public function getDataForSave()
@@ -567,6 +581,7 @@ public function getDataForSave()
567581
* Retrieve shared store ids for current website or all stores if $current is false
568582
*
569583
* @return array
584+
*
570585
* @throws NoSuchEntityException
571586
*/
572587
public function getSharedStoreIds()
@@ -590,6 +605,7 @@ public function getSharedStoreIds()
590605
* Set shared store ids
591606
*
592607
* @param array $storeIds
608+
*
593609
* @return $this
594610
*/
595611
public function setSharedStoreIds($storeIds)
@@ -602,6 +618,7 @@ public function setSharedStoreIds($storeIds)
602618
* Retrieve wishlist store object
603619
*
604620
* @return \Magento\Store\Model\Store
621+
*
605622
* @throws NoSuchEntityException
606623
*/
607624
public function getStore()
@@ -616,6 +633,7 @@ public function getStore()
616633
* Set wishlist store
617634
*
618635
* @param Store $store
636+
*
619637
* @return $this
620638
*/
621639
public function setStore($store)
@@ -653,6 +671,7 @@ public function isSalable()
653671
* Retrieve if product has stock or config is set for showing out of stock products
654672
*
655673
* @param int $productId
674+
*
656675
* @return bool
657676
*/
658677
private function isInStock($productId)
@@ -671,7 +690,9 @@ private function isInStock($productId)
671690
* Check customer is owner this wishlist
672691
*
673692
* @param int $customerId
693+
*
674694
* @return bool
695+
*
675696
* @throws LocalizedException
676697
*/
677698
public function isOwner($customerId)
@@ -696,10 +717,13 @@ public function isOwner($customerId)
696717
* @param int|Item $itemId
697718
* @param DataObject $buyRequest
698719
* @param null|array|DataObject $params
720+
*
699721
* @return $this
722+
*
700723
* @throws LocalizedException
701724
*
702725
* @see \Magento\Catalog\Helper\Product::addParamsToBuyRequest()
726+
*
703727
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
704728
* @SuppressWarnings(PHPMD.NPathComplexity)
705729
*/
@@ -748,10 +772,11 @@ public function updateItem($itemId, $buyRequest, $params = null)
748772
throw new LocalizedException(__($resultItem));
749773
}
750774

775+
if ($resultItem->getDescription() != $item->getDescription()) {
776+
$resultItem->setDescription($item->getDescription())->save();
777+
}
778+
751779
if ($resultItem->getId() != $itemId) {
752-
if ($resultItem->getDescription() != $item->getDescription()) {
753-
$resultItem->setDescription($item->getDescription())->save();
754-
}
755780
$item->isDeleted(true);
756781
$this->setDataChanges(true);
757782
} else {

dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ public function testUpdateItemQtyInWishList(): void
217217
$this->assertEquals(55, $updatedItem->getQty());
218218
}
219219

220+
/**
221+
* Update description of wishlist item
222+
*
223+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
224+
*
225+
* @return void
226+
*/
227+
public function testUpdateItemDescriptionInWishList(): void
228+
{
229+
$itemDescription = 'Test Description';
230+
$wishlist = $this->getWishlistByCustomerId->execute(1);
231+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple');
232+
$item->setDescription($itemDescription);
233+
$this->assertNotNull($item);
234+
$buyRequest = $this->dataObjectFactory->create(['data' => ['qty' => 55]]);
235+
$wishlist->updateItem($item, $buyRequest);
236+
$updatedItem = $this->getWishlistByCustomerId->getItemBySku(1, 'simple');
237+
$this->assertEquals(55, $updatedItem->getQty());
238+
$this->assertEquals($itemDescription, $updatedItem->getDescription());
239+
}
240+
220241
/**
221242
* @return void
222243
*/

0 commit comments

Comments
 (0)