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

ShippingMethod getChannels method returns null instead of collection #2

Open
ajax7700sk opened this issue Apr 11, 2022 · 2 comments
Open

Comments

@ajax7700sk
Copy link

Hello,

can you replace targetEntity="Sylius\Component\Core\Model\ShippingMethod" with targetEntity="Sylius\Component\Core\Model\ShippingMethodInterface" in trait PaymentMethodRestrictionTrait as it is causing type error if you are accessing channel in PaymentMethod's shippingMethods collection?

You should always use/target entity/resource interface instead of particular resource instance.

   /**
     * @var Collection<array-key, ShippingMethodInterface>|ShippingMethodInterface[]
     * @ORM\ManyToMany(targetEntity="Sylius\Component\Core\Model\ShippingMethod", inversedBy="paymentMethods")
     * @ORM\JoinTable(name="threebrs_payment_method_shipping_method",
     *     joinColumns={@ORM\JoinColumn(name="payment_method_id", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="method_shipping_id", referencedColumnName="id")}
     * )
     */
    private $shippingMethods
   /**
     * @var Collection<array-key, ShippingMethodInterface>|ShippingMethodInterface[]
     * @ORM\ManyToMany(targetEntity="Sylius\Component\Core\Model\ShippingMethodInterface", inversedBy="paymentMethods")
     * @ORM\JoinTable(name="threebrs_payment_method_shipping_method",
     *     joinColumns={@ORM\JoinColumn(name="payment_method_id", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="method_shipping_id", referencedColumnName="id")}
     * )
     */
    private $shippingMethods;

Thanks

@hornofj
Copy link
Member

hornofj commented Apr 14, 2022

Hi, Thanks for letting us know. This will work in newer versions of sylius as you can not map interfaces to target entities on older versions (not sure which exactly), sometimes you need an additional mapping to make it work. Which Sylius version are you using? Could you post a pull request so we can see if the tests will proceed successfully? We could make new version of the plugin supporting only new Sylius versions.

@jaroslavtyc
Copy link
Collaborator

@ajax7700sk Hi, fix is on the way https://github.com/3BRS/sylius-payment-restrictions-plugin/pull/4/files#diff-4a8098d07b0c277f5e28eacf0a2df751c1614874bb8fa0b053aeeb04dfa01e87R21

Note that it is part of bigger update and it will require Sylius 1.12

@hornofj FYI

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

No branches or pull requests

3 participants