concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Add a configurable option to automatically update quantities of products with variations #813

Closed mlocati closed 10 months ago

mlocati commented 10 months ago

This PR adds the following options at /dashboard/store/settings#settings-products:

immagine

If that option is enabled and a product has variations, users won't see this details when editing it:

immagine

those two fields will be automatically populated (and kept up-to-date) by listening to the Doctrine preFlush event. That listener (which will be called whenever we are writing something to the database), will check all the loaded entities, and update (if required) the two pQty / pQtyUnlim fields for the products (see the new AutoUpdaterQuantitiesFromVariations class).

In order to automatically update those two fields, users can also use:

Fix #763

mlocati commented 10 months ago

PS: I've updated the Doctrine event listener: now it only calculates the new fields only in case of changes (instead of processing all the loaded products and variations)

Mesuva commented 10 months ago

Wow, this look impressive. I've read your notes on the issue about this, and I agree that the variation quantities and the total quantities should be linked. Otherwise it's just confusing as to why there are two quantities.

I'll merge this, and will do a bit of testing this week.

mlocati commented 10 months ago

I'll merge this, and will do a bit of testing this week.

I've used this query in my tests when editing a product in the dashboard:

SET @pID = 1;
SELECT 'Product' AS What, pQty AS Qty, pQtyUnlim AS Unlimited, null as Disabled FROM CommunityStoreProducts WHERE pID = @pID
UNION ALL
SELECT CONCAT('Variation ', pvID), pvQty, pvQtyUnlim, pvDisabled FROM CommunityStoreProductVariations WHERE pID=@pID

You may want to reuse it to check the stored data :wink: