Skip to content

Commit

Permalink
Merge pull request #29 from BrunoPYT/main
Browse files Browse the repository at this point in the history
fix: add missing wishlish data
  • Loading branch information
zawaze authored Oct 31, 2024
2 parents 014125f + cd1d41f commit c0757bb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.1.3</version>
<version>2.1.4</version>
<authors>
<author>
<name>Michaël Espeche</name>
Expand Down
16 changes: 14 additions & 2 deletions Loop/WishList.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*************************************************************************************/
/* */
/* Thelia */
Expand Down Expand Up @@ -55,7 +56,9 @@ protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('customer_id')
Argument::createIntListTypeArgument('customer_id'),
Argument::createAlphaNumStringTypeArgument('code'),
Argument::createBooleanTypeArgument('default'),
);
}

Expand Down Expand Up @@ -83,6 +86,10 @@ public function buildModelCriteria()
$wishList->filterById($id);
}

if (null !== $code = $this->getCode()) {
$wishList->filterByCode($code);
}

if (null !== $customerId) {
$wishList->filterByCustomerId($customerId);
}
Expand All @@ -91,6 +98,10 @@ public function buildModelCriteria()
$wishList->filterBySessionId($sessionId);
}

if (null !== $default = $this->getDefault()) {
$wishList->filterByDefault($default);
}

return $wishList;
}

Expand All @@ -103,7 +114,7 @@ public function buildModelCriteria()
public function parseResults(LoopResult $loopResult)
{
/** @var \WishList\Model\WishList $wishlist */
foreach ($loopResult->getResultDataCollection() as $wishlist){
foreach ($loopResult->getResultDataCollection() as $wishlist) {

$loopResultRow = new LoopResultRow($wishlist);

Expand All @@ -112,6 +123,7 @@ public function parseResults(LoopResult $loopResult)

$loopResultRow
->set("ID", $wishlist->getId())
->set("DEFAULT", $wishlist->getDefault())
->set("TITLE", $wishlist->getTitle())
->set("CODE", $wishlist->getCode())
->set("CUSTOMER_ID", $wishlist->getCustomerId())
Expand Down
27 changes: 27 additions & 0 deletions Model/Api/WishList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class WishList extends BaseApiModel
*/
protected $id;

/**
* @var boolean
* @OA\Property(
* type="boolean",
* )
* @Constraint\NotBlank(groups={"read", "update"})
*/
protected $default;

/**
* @var integer
* @OA\Property(
Expand Down Expand Up @@ -110,6 +119,24 @@ public function setId($id): WishList
return $this;
}

/**
* @return boolean
*/
public function getDefault()
{
return $this->default;
}

/**
* @param boolean $default
* @return WishList
*/
public function setDefault($default): WishList
{
$this->default = $default;
return $this;
}

/**
* @return int
*/
Expand Down
28 changes: 16 additions & 12 deletions Service/WishListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function addProduct($pseId, $quantity, $wishListId = null)
->setQuantity($quantity)
->save();
} catch (\Exception $e) {
Tlog::getInstance()->error('Error during wishlist add :'.$e->getMessage());
Tlog::getInstance()->error('Error during wishlist add :' . $e->getMessage());

return false;
}
Expand All @@ -83,7 +83,7 @@ public function removeProduct($pseId, $wishListId = null)
$productWishList->delete();
}
} catch (\Exception $e) {
Tlog::getInstance()->error('Error during wishlist remove :'.$e->getMessage());
Tlog::getInstance()->error('Error during wishlist remove :' . $e->getMessage());

return false;
}
Expand Down Expand Up @@ -218,6 +218,10 @@ public function createUpdateWishList($title, $products = null, $wishListId = nul
$rewrittenUrl = $hash;
}

if (null !== $title) {
$wishList->setTitle($title);
}

$wishList->save();

if (null !== $rewrittenUrl) {
Expand Down Expand Up @@ -256,8 +260,7 @@ public function duplicateWishList($wishListId, $title)
$newWishList = (new WishList())
->setTitle($title)
->setCustomerId($customerId)
->setSessionId($sessionId)
;
->setSessionId($sessionId);

$code = $this->getWishList($newWishList);

Expand Down Expand Up @@ -326,8 +329,7 @@ public function cloneWishList($wishListId)
$newWishList = (new WishList())
->setTitle($wishList->getTitle())
->setCustomerId($customerId)
->setSessionId($sessionId)
;
->setSessionId($sessionId);

$code = $this->getWishList($newWishList);

Expand All @@ -346,7 +348,7 @@ public function cloneWishList($wishListId)
return $newWishList;
}

protected function getWishListObject($wishListId, $customerId, $sessionId)
protected function getWishListObject($wishListId, $customerId, $sessionId): ?WishList
{
$wishList = WishListQuery::create()
->filterById($wishListId);
Expand Down Expand Up @@ -401,14 +403,16 @@ public function createWishlistSlug(Wishlist $wishlist)
$count = 0;

while (true) {
if (WishListQuery::create()
->filterByCode($wishlistHash)
->filterById($wishlist->getId(), Criteria::NOT_EQUAL)
->count() === 0) {
if (
WishListQuery::create()
->filterByCode($wishlistHash)
->filterById($wishlist->getId(), Criteria::NOT_EQUAL)
->count() === 0
) {
break;
}

$wishlistHash = Slugify::create()->slugify($wishlist->getTitle().'-'.++$count, '-');
$wishlistHash = Slugify::create()->slugify($wishlist->getTitle() . '-' . ++$count, '-');
}

return $wishlistHash;
Expand Down

0 comments on commit c0757bb

Please sign in to comment.