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

New dashboard page to quickly update stock quantities? #738

Closed mlocati closed 1 year ago

mlocati commented 1 year ago

I'm planning to build a website for a friend of mine. She has a physical store, and she wants to start selling online too. For that reason, she needs to update the available quantities for products when she sells something in the physical shop.

At the moment, updating the available quantity is rather overcomplicated for someone that only needs to do that.

Would you accept a PR that adds a new dashboard page only for that purpose? Of course, I can create a separated package, but I was wondering if it's a requirement that others too may have...

Mesuva commented 1 year ago

I've had others comment on the potential of being able to edit product fields, like the price, or the availability, from the product list screen.

That makes some sense to me, but it may also work a little better on its own dashboard page, where it would be specifically designed for bulk editing.

Perhaps it makes sense at this stage to still build it as a seperate package, where it can be selectively installed if needed (and also more easily modified at for different purposes). Down the track, if it make sense to do so it wouldn't be difficult to just add it to the main store package.

mlocati commented 1 year ago

I agree.

Should I publish that package under the https://github.com/concretecms-community-store umbrella? Otherwise I'd publish it under https://github.com/concrete5-community

Mesuva commented 1 year ago

I reckon under https://github.com/concretecms-community-store

mlocati commented 1 year ago

Yeah, much better. What about the package handle? community_store_quickquantities would work?

Mesuva commented 1 year ago

Perhaps something a bit more generic, like community_store_bulk_product_updating, since I could imagine that the same page could be useful for updating different product information, not just quantities. (but I understand you'd just be building it for quantities yourself)

mlocati commented 1 year ago

like community_store_bulk_product_updating

:+1:

If you create that repo and give write access to me, I'll create it asap

mlocati commented 1 year ago

I've pushed some code to https://github.com/concretecms-community-store/community_store_bulk_product_updating

@Mesuva I'm not very familiar with Communiy Store: do you think that the criterias I wrote here and here are ok?

Mesuva commented 1 year ago

@mlocati Both those sections look good to me, at a glance at least - that join looks how I'd expect.

Also cool to see vuejs in your add-on, I think that's the first time I've spotted someone else using it with Concrete.

mlocati commented 1 year ago

Thank for confirming, Ryan!

Yep, I use vue whenever possible (I use jQuery only for ajax requests nowadays :wink:)

mlocati commented 1 year ago

@Mesuva I'm done with https://github.com/concretecms-community-store/community_store_bulk_product_updating

If you can/want to take a look at it, please let me know. Otherwise I'll update its README with some instructions, and publish version 1.0.0

Mesuva commented 1 year ago

@mlocati I've taken a quick look at the add-on. Just a couple of questions:

mlocati commented 1 year ago

when I first visit the page, do I have to perform a search, or should I expect products to start listing?

Yep: that's what users read when they visit the page: immagine

is there some criteria for products to be listed here? (I'm not getting any listed, even with a search, but I have active products with quantities)

Yep, but you need to enter some search criteria and hit the magnifying class icon.

I'm getting the attached error as well

Whoops: I tested the code only for products that have mandatory variants. In this case, the page only lets you see and update the quantities of the variants, and it doesn't display the "base" products. I've fixed this issue (and I've also addressed another v8↔️v9 incompatibility).

Mesuva commented 1 year ago

This is working well for me now.

I'm wondering if something like this is more useful if you don't have to do a search query first - it would just show all products, and you could work your way through them all without having to known what to search for.

mlocati commented 1 year ago

Well, if people have thousands of products/product variations, that would be a huge page... Maybe we could show all the products if there are less than a predefined number (eg 200)?

Mesuva commented 1 year ago

Is it not paginated?

mlocati commented 1 year ago

Nope

mlocati commented 1 year ago

Adding pagination is rather cumbersome.

The records are fetched by this query, which basically retrieves the products, product options, product variations, and product variation options in just one query.

That's done to avoid hundreds of queries (it's faster to retrieve all product data in just one query, instead of executing a query for every product).

The downside of this is that we can't easily add pagination: how may records should the results be limited to, provided that a single product may span multiple rows returned by that query?

mlocati commented 1 year ago

Just for reference, here's that big query (I've simplified it a bit):

SELECT
    StoreProducts.*,
    CommunityStoreProductOptions.*,
    CommunityStoreProductVariations.*,
    CommunityStoreProductVariationOptionItems.*,
    CommunityStoreProductOptionItems.*
FROM
    StoreProducts
    LEFT JOIN CommunityStoreProductOptions
        ON StoreProducts.pID = CommunityStoreProductOptions.pID
    LEFT JOIN CommunityStoreProductVariations
        ON StoreProducts.pID = CommunityStoreProductVariations.pID
    LEFT JOIN CommunityStoreProductVariationOptionItems
        ON CommunityStoreProductVariations.pvID = CommunityStoreProductVariationOptionItems.pvID
    LEFT JOIN CommunityStoreProductOptionItems
        ON CommunityStoreProductVariationOptionItems.poiID = CommunityStoreProductOptionItems.poiID
    LEFT JOIN CommunityStoreProductVariations AS CommunityStoreProductVariationsWhere
        ON StoreProducts.pID = CommunityStoreProductVariationsWhere.pID
        AND (StoreProducts.pVariations = 1
        AND (CommunityStoreProductVariationsWhere.pvDisabled IS NULL OR CommunityStoreProductVariationsWhere.pvDisabled = 0))
WHERE
    StoreProducts.pActive = 1
    AND (StoreProducts.pDateAvailableStart IS NULL OR StoreProducts.pDateAvailableStart < '2023-02-20 19:59:40')
    AND (StoreProducts.pDateAvailableEnd IS NULL OR StoreProducts.pDateAvailableEnd > '2023-02-20 19:59:40')
    AND (
        (
            StoreProducts.pName LIKE '%search%'
            OR StoreProducts.pSKU LIKE '%search%'
            OR StoreProducts.pBarcode LIKE '%search%'
            OR StoreProducts.pDesc LIKE '%search%'
            OR CommunityStoreProductVariationsWhere.pvSKU LIKE '%search%'
            OR CommunityStoreProductVariationsWhere.pvBarcode LIKE '%search%'
        )
        AND
        (
            StoreProducts.pName LIKE '%me%'
            OR StoreProducts.pSKU LIKE '%me%'
            OR StoreProducts.pBarcode LIKE '%me%'
            OR StoreProducts.pDesc LIKE '%me%'
            OR CommunityStoreProductVariationsWhere.pvSKU LIKE '%me%'
            OR CommunityStoreProductVariationsWhere.pvBarcode LIKE '%me%'
        )
    )
ORDER BY
    StoreProducts.pName ASC,
    StoreProducts.pSKU ASC,
    CommunityStoreProductOptions.poSort ASC,
    CommunityStoreProductVariations.pvSort ASC
mlocati commented 1 year ago

It has been rather hard, but I've updated that package: it now supports pagination.

mlocati commented 1 year ago

Done.