Skip to content
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

[Shop][Payment] Prevent selecting payment method not assigned to channel #5689

Merged
merged 2 commits into from
Aug 9, 2016

Conversation

tuka217
Copy link
Contributor

@tuka217 tuka217 commented Aug 3, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Related tickets -
License MIT

/**
* {@inheritdoc}
*/
public function findEnabledForChannel(ChannelInterface $channel)
Copy link
Contributor

@pamil pamil Aug 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why won't we just use $channel->getPaymentMethods() collection? It implements Doctrine\Common\Collections\Selectable, so:

$channel->getPaymentsMethods()->matching(new Criteria(new Comparison('enabled', Comparison::EQ, true)))

Should work even faster (we won't need to hydrate all the payment methods only to pass them to another query).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we would not need this custom repository, we can use it directly in the resolver or implement on the model - see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course the typehint is oversimplified now, it's either ArrayCollection (if created manually) or PersistentCollection (if hydrated by Doctrine), but both of them implements Collection and Selectable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yups :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current implementation it cannot be done in this way.

@tuka217 tuka217 force-pushed the payment-method-per-channel branch 3 times, most recently from 8593dbc to 322fbae Compare August 4, 2016 09:03
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface as BasePaymentMethodRepositoryInterface;
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line

…toryInterface

[CoreBundle] Add implementation for method from PaymentMethodRepositoryInterface
Add implementation of scenario
@pjedrzejewski pjedrzejewski merged commit 30d20ba into Sylius:master Aug 9, 2016
@pjedrzejewski
Copy link
Member

Thank you Ania! :)

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
[Shop][Payment] Prevent selecting payment method not assigned to channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants