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

Call to a member function indexBy() on array #146

Open
franck-thorck opened this issue Dec 9, 2024 · 1 comment
Open

Call to a member function indexBy() on array #146

franck-thorck opened this issue Dec 9, 2024 · 1 comment

Comments

@franck-thorck
Copy link

franck-thorck commented Dec 9, 2024

Describe the bug

When I use wishlist/lists/add-to-cart in a form to add a list to the cart, it throws an error:

Call to a member function indexBy() on array

Steps to reproduce

  1. Create a list
  2. Add items to the list
  3. Create a form to add the list to cart

Craft CMS version

5.5.5

Plugin version

3.0.4

Multi-site?

Yes for multi-language

Additional context

I upgrade a project from Craft CMS 4.x to Craft CMS 5.x.
It worked when the project was on Craft CMS 4.x.
When I use this code in "Add to cart" form:

{% for item in list.items %} <input type="hidden" name="purchasables[{{ item.id }}][qty]" value="{{ item.quantityWished }}"> {% if item.options|length %} <input type="hidden" name="purchasables[{{ item.id }}][options][width_eighth]" value="0"> <input type="hidden" name="purchasables[{{ item.id }}][options][length_eighth]" value="0"> {% for key, value in item.options %} {% if key == 'note' %} <input type="hidden" name="purchasables[{{ item.id }}][{{key}}]" value="{{value}}"> {% else %} <input type="hidden" name="purchasables[{{ item.id }}][options][{{key}}]" value="{{value}}"> {% endif %} {% endfor %} {% endif %} {% endfor %}

It returns a Variant class element in the addToCart function of ListController.php. If I remove this code, it returns the Purchasable class element, but I got this error then, but all my product types in the CMS is related to a tax category:

craft\commerce\base\Purchasable::getTaxCategory(): Return value must be of type craft\commerce\models\TaxCategory, null returned

Capture d’écran 2024-12-08 233913

@engram-design
Copy link
Member

Fixed for the next release. To get this early, run composer require verbb/wishlist:"dev-craft-5 as 3.0.4".

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

2 participants