Skip to content

Commit

Permalink
Merge pull request #13 from gillesbourgeat/bump-1-2-1
Browse files Browse the repository at this point in the history
Bump version 1.2.1 and improvment login listener
  • Loading branch information
gillesbourgeat authored Dec 9, 2016
2 parents 3255ab7 + a2c728f commit 1133388
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<descriptive locale="en_US">
<title>Wish list</title>
</descriptive>
<version>1.2.0</version>
<version>1.2.1</version>
<author>
<name>Michaël Espeche</name>
<email>mespeche@openstudio.fr</email>
Expand Down
23 changes: 21 additions & 2 deletions EventListener/CustomerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\SecurityContext;
use WishList\Controller\Front\WishListController;
use WishList\Model\WishList;
use WishList\Model\WishListQuery;

/**
Expand Down Expand Up @@ -35,9 +36,27 @@ public function customerLogout(Event $event)
public function customerLogin(Event $event)
{
if ($this->securityContext->hasCustomerUser()) {
$ids = WishListQuery::create()->filterByCustomerId($this->securityContext->getCustomerUser()->getId())->select('id')->find()->toArray();
$productIds = array_unique(
array_merge(
is_array($this->requestStack->getCurrentRequest()->getSession()->get(WishListController::SESSION_NAME)) ?
$this->requestStack->getCurrentRequest()->getSession()->get(WishListController::SESSION_NAME) : [],
WishListQuery::create()->filterByCustomerId($this->securityContext->getCustomerUser()->getId())->select('product_id')->find()->toArray()
), SORT_REGULAR
);

$this->requestStack->getCurrentRequest()->getSession()->set(WishListController::SESSION_NAME, $ids);
foreach ($productIds as $productId) {
if (null === WishListQuery::create()
->filterByCustomerId($this->securityContext->getCustomerUser()->getId())
->filterByProductId($productId)
->findOne()) {
(new WishList())
->setCustomerId($this->securityContext->getCustomerUser()->getId())
->setProductId($productId)
->save();
}
}

$this->requestStack->getCurrentRequest()->getSession()->set(WishListController::SESSION_NAME, $productIds);
}
}

Expand Down

0 comments on commit 1133388

Please sign in to comment.