3BRS / sylius-payment-restrictions-plugin

Restrict payment methods by zone or by shipping method.
MIT License
2 stars 4 forks source link

ShippingMethod getChannels method returns null instead of collection #2

Open ajax7700sk opened 2 years ago

ajax7700sk commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

@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