Brille24 / SyliusTierpricePlugin

A plugin for Sylius that implements tier pricing
MIT License
44 stars 38 forks source link

Issues with JavaScript Functions, toArray() Error, and Missing Persistence for Tier Prices #88

Open MatBonnin opened 2 days ago

MatBonnin commented 2 days ago

I am reaching out to report several issues I encountered while integrating your plugin into my Sylius 1.12 and 1.13 projects. I have followed the tutorial provided on your GitHub repository multiple times, but I still face the following problems. I managed to work around some of the issues by tweaking the code, but I am unsure if I might have done something wrong during the setup.

1. JavaScript Error: tierPriceTableAdd is not defined When attempting to add tier prices in the admin interface, I received the following error:

Uncaught ReferenceError: tierPriceTableAdd is not defined

I was able to bypass this issue by manually including the required JavaScript files in the Twig templates. However, this seemed strange as I followed the installation instructions to the letter. Could this be related to the way assets are handled?

2. JavaScript Error: Uncaught TypeError: table.find(...).filter(...).sortElements is not a function After resolving the script inclusion issue, I encountered another error:

Uncaught TypeError: table.find(...).filter(...).sortElements is not a function

Again, I managed to bypass this by rewriting the sorting logic using native JavaScript, as the sortElements method seems to be from an outdated jQuery plugin. Could there be something missing in the default installation instructions regarding jQuery or required libraries?

3. Twig Error: Call to a member function toArray() on null When rendering the product variant tier prices on the front end, I encountered the following error:

Call to a member function toArray() on null

It appears that the tierPrices property is null when accessed. Should this collection be automatically initialized, or is there something I might have missed in the configuration?

4. Tier Prices Not Persisting to the Database Although tier prices are added successfully in the admin interface, they are not being persisted to the brille24_tierprice table in the database. I have checked the Doctrine mapping, and everything seems to be in order, but the data is still not saved.

I would greatly appreciate any guidance or insights into what might be going wrong. As mentioned, I followed the GitHub tutorial closely and even tried both Sylius 1.12 and 1.13, but I continue to face these issues.

Thank you in advance for your assistance.

mamazu commented 2 days ago

Thanks for reporting those issues. I haven't checked the admin UI after updating for the last few versions.

I'd really appreciate if you could already make a PR with the JQuery to native browser migration and I can take it from there. As for the issue of it not being properly saved in the database that's odd.

MatBonnin commented 1 day ago

Hi,

I wanted to inform you that I have made the pull request to address the migration from jQuery to native JavaScript, as requested. This should fix the error:

Uncaught TypeError: table.find(...).filter(...).sortElements is not a function.

Regarding the issue Uncaught ReferenceError: tierPriceTableAdd is not defined, this issue has also been resolved, but I'm not entirely sure how it was fixed.

As for the problem of tier prices not being saved to the database, I discovered that it was due to my doctrine.yaml configuration. Initially, I was using annotation for the mapping type, but once I switched it to attribute, the issue was resolved, and the tier prices are now being properly persisted.

Thank you again for your help, and feel free to review the pull request!

mamazu commented 14 hours ago

Oh wow you manage to fix all the issues. That's great. Thank you so much for your work.

I have left some minor maintainance comments on the pull request, but looks good so far.