-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Voucher] restrict voucher usage per customer #2451
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice idea, very good implementation. I do have some changes for you though. If you need further info, let me know.
@@ -156,6 +159,21 @@ private function addModelsSection(ArrayNodeDefinition $node): void | |||
->end() | |||
->end() | |||
->end() | |||
->arrayNode('cart_price_rule_voucher_code_user') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be called cart_price_rule_voucher_code_customer
class CartPriceRuleVoucherCodeUserRepository extends EntityRepository implements CartPriceRuleVoucherCodeUserRepositoryInterface | ||
{ | ||
|
||
public function findByUsesById(int $userId, int $voucherCodeId): ?CartPriceRuleVoucherCodeUserInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should pass the CustomerInterface direcly
|
||
public function addCodeUserUsage(int $userId, CartPriceRuleVoucherCodeInterface $voucherCode): void | ||
{ | ||
$voucherCodeUser = new CartPriceRuleVoucherCodeUser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We never create entities in the Repository
- You should use the factory to create the entity
return; | ||
} | ||
|
||
$user = $this->security->getUser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $order->getCustomer()
// max usage per user condtion | ||
if (is_numeric($maxUsagePerUser)){ | ||
|
||
$user = $this->security->getUser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get the customer from the cart/order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we get the user from the security component, is that we wanted to explicitly limit the vouchers for registered customers only, because it's just not really possible for guests. This means if you use such a voucher as a guest, it will always be invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the customer you can get the user ;).
$cart->getCustomer()->getUser()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but should we still rename user to customer as in:
#2451 (comment)
and still pass the CustomerInterface in:
#2451 (comment)
if we only work with the CoreShopUser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reality, it also works for Guest Customers. CoreShop re-uses a customer based on the email address. (that is a feature that if a customer wants to convert to a real user, we have the order history)
@@ -19,33 +19,26 @@ | |||
namespace CoreShop\Bundle\OrderBundle\Doctrine\ORM; | |||
|
|||
use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; | |||
use CoreShop\Component\Order\Model\CartPriceRuleVoucherCodeInterface; | |||
use CoreShop\Component\Order\Model\CartPriceRuleVoucherCodeUser; | |||
use CoreShop\Component\Core\Model\CustomerInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use CoreShop\Component\Customer\Model\CustomerInterface.php
@@ -4,13 +4,14 @@ | |||
namespace CoreShop\Bundle\OrderBundle\EventListener; | |||
|
|||
|
|||
use CoreShop\Component\Order\Model\CartPriceRuleVoucherCodeInterface; | |||
use CoreShop\Component\Core\Model\CustomerInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use CoreShop\Component\Customer\Model\CustomerInterface.php
- '@coreshop.repository.cart_price_rule_voucher_code' | ||
- '@Symfony\Component\Security\Core\Security' | ||
- '@CoreShop\Component\Order\Factory\CartPriceRuleVoucherCodeUserFactory.inner' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- '@coreshop\Component\Order\Factory\CartPriceRuleVoucherCodeUserFactoryInterface'
use CoreShop\Component\Order\Model\CartPriceRuleInterface; | ||
use CoreShop\Component\Order\Model\CartPriceRuleVoucherCodeInterface; | ||
use CoreShop\Component\Order\Model\OrderInterface; | ||
use CoreShop\Component\Order\Model\PriceRuleItemInterface; | ||
use CoreShop\Component\Order\Repository\CartPriceRuleVoucherCodeUserRepositoryInterface; | ||
use CoreShop\Component\Order\Repository\CartPriceRuleVoucherRepositoryInterface; | ||
use Symfony\Component\Security\Core\Security; | ||
use Pimcore\Model\DataObject\CoreShopCustomer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove usages of Pimcore DataObject Classes
@@ -18,15 +18,15 @@ | |||
|
|||
namespace CoreShop\Component\Order\Repository; | |||
|
|||
use CoreShop\Component\Order\Model\CartPriceRuleVoucherCodeInterface; | |||
use CoreShop\Component\Core\Model\CustomerInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use CoreShop\Component\Customer\Model\CustomerInterface.php
@Philip-Neusta I added some changes: Mainly: renaming user to customer, and I moved your listener to the voucher modifier we already have. One more thing though: We don't add new features to 3.1 anymore, can you rebase to 3.2? |
now rebased and changed base to 3.2 |
@Philip-Neusta amazing work 🎉 🍻 |
In the conditions for limiting the use of vouchers, it was only possible to set how often a code could be used in total. However, when working with Coreshop, we wanted to be able to limit the use of a voucher per customer. In this pull request we added this feature. Our implementation so far is not final but works. Could you take a look at this and give feedback on whether this is going in the right direction?