nystudio107 / craft-autocomplete

Provides Twig template IDE autocomplete of Craft CMS & plugin variables
MIT License
42 stars 3 forks source link

Craft Commerce auto-complete broken (again?) #10

Closed TomDeSmet closed 1 year ago

TomDeSmet commented 1 year ago

Describe the bug

Similar to this issue: https://github.com/nystudio107/craft-autocomplete/issues/6

craft.commerce craft.orders craft.products

None are autocompleted or recognized.

Versions

khalwat commented 1 year ago

Seems to be working here?

Screen Shot 2022-10-13 at 6 26 19 PM

Maybe check this file to ensure it has the annotations in it that you'd expect to see?

Screen Shot 2022-10-13 at 6 26 35 PM
khalwat commented 1 year ago

btw I think it should be:

craft.commerce
craft.commerce.products
craft.commerce.orders
TomDeSmet commented 1 year ago

Hi Andrew,

The commerce annotation is in the file as expected. Is there anything else that could be wrong?

PS: The official docs also use craft.orders() and craft.products() I guess they are the same as craft.commerce.orders.

khalwat commented 1 year ago

Are you still having issues with this?

TomDeSmet commented 1 year ago

Unfortunately yes.

khalwat commented 1 year ago

To be clear, you're saying this doesn't autocomplete:

craft.orders
craft.products

...but this does?

craft.commerce
craft.commerce.orders
craft.commerce.products

?

If the answer is that neither autocomplete, please go to Preferences -> Symfony and ensure Enable Plugin for this Project is enabled, and then click on the CLEAR INDEX button.

Screen Shot 2022-12-19 at 2 37 45 PM

Wait for it to re-index, and then try the second examples again, they are autocompleting for me here:

Screen Shot 2022-12-19 at 2 38 11 PM
khalwat commented 1 year ago

Addressed via: https://github.com/nystudio107/craft-autocomplete/commit/73216c7817957fe936e2db4e2f6f6309d7779fa8

Released as 1.11.0 -> https://github.com/nystudio107/craft-autocomplete/releases/tag/1.11.0

You can update to it via:

composer update nystudio107/craft-autocomplete

It will now generate something that looks like this in storage/runtime/compiled_classes/AutocompleteVariable.php for Commerce, and other plugins that add Behaviors to the CraftVariable:

/**
 * ...
 * @property \craft\commerce\Plugin $commerce
 * @method orders($criteria): craft\commerce\elements\db\OrderQuery
 * @method subscriptions($criteria): craft\commerce\elements\db\SubscriptionQuery
 * @method products($criteria): craft\commerce\elements\db\ProductQuery
 * @method variants($criteria): craft\commerce\elements\db\VariantQuery
 */

This means that you will now get autocomplete for:

craft.commerce
craft.orders()
craft.subscriptions()
craft.products()
craft.variants()

...for Commerce specifically. Video of it in action:

https://user-images.githubusercontent.com/7570798/208551498-3219e4a7-ef8b-4bd0-b624-5bad50ff9302.mov

To ensure it shows up, you can manually regenerate the autocompletes via CLI:

php craft autocomplete/regenerate

If you still don't see it show up, please go to Preferences -> Symfony and ensure Enable Plugin for this Project is enabled, and then click on the CLEAR INDEX button.

Screen Shot 2022-12-19 at 2 37 45 PM
TomDeSmet commented 1 year ago

I finally got it working, thanks! But I also noticed it does not work on the EAP version of PhPStorm unfortunately.

On a side note: maybe you could add commerce.discounts as well?

khalwat commented 1 year ago

discounts already works -- commerce. isn't a namespace that exists anymore though, at least not with Commerce 3.x

What version of Commerce are you using?

TomDeSmet commented 1 year ago

Commerce 4.2.4

Then maybe I was testing the discount when I was still on EAP version.