Add a status field (enabled/disabled) to stores

Created on 4 November 2017, over 7 years ago
Updated 3 October 2023, almost 2 years ago

Hello,

I started to create a market place on my site and I would like to moderate the stores.
That is to say that when a user creates a store, I do not want it to appear on the site and in the search engines (google, ...).
It must be unpublished or disabled.

If his shop is valid, I activate or publish it and change the role of the user to "Store Owner".

When a node is not published, it is inaccessible. We should do the same with the stores.
If a store is disabled, it must also disable the affected products.

To enable or disable a store, you must add rules.

- If the store contains products, it can not be disabled. You must display a message "To disable this store, you must first disable the associated products."

- If a deactivated product is associated with a disabled store and I want to activate this product. You must display a message "To activate this product, you must first activate the associated store".

If the conditions are not met, the enable / disable check box is not clickable and the warning message is displayed.

I think this feature should be part of Drupal Commerce ..

Stores must have the status "Posted" or "Unpublished".

With a new permission "See all stores" and "See unpublished stores that I own".

When the "Content Moderation" module is stable, it can take into account the stores.

This would be useful for the "Commerce multistore".

✨ Feature request
Status

Needs work

Version

2.16

Component

Store

Created by

🇫🇷France zenimagine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update almost 2 years ago
    Not currently mergeable.
  • @neha-mahajan opened merge request.
  • 🇮🇳India Sivaji_Ganesh_Jojodae Chennai

    We are requiring this feature in our project. Would like to see this added shortly.

  • 🇪🇸Spain willeaton

    From what I can see, this patch does nothing more than create the field, anyone can do that via the entity system. What we need is to make sure that the commerce module takes this into account in all the important places (checkout, order creation, store_domain resolvers etc

    I think this feature makes a lot of sense. You create a store, you have orders associated to a store, then you close it. Is there another way of approaching this?

  • 🇮🇱Israel jsacksick

    From what I can see, this patch does nothing more than create the field, anyone can do that via the entity system. What we need is to make sure that the commerce module takes this into account in all the important places (checkout, order creation, store_domain resolvers etc

    Because we use the EntityAccessControlHandler and implement the EntityPublishedInterface, we also get access control "for free".

    See:

          if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) {
            if ($account->id() != $entity->getOwnerId()) {
              // There's no permission for viewing other user's unpublished entity.
              return AccessResult::neutral()->cachePerUser();
            }
    
            $permissions = [
              "view own unpublished {$entity->getEntityTypeId()}",
            ];
            $result = AccessResult::allowedIfHasPermissions($account, $permissions)->cachePerUser();
          }
    

    We probably need tests coverage and need to think which code needs to change...
    We should try by opening a merge request.

  • 🇮🇱Israel jsacksick

    jsacksick → changed the visibility of the branch 2921000-add-a-status to hidden.

  • 🇮🇱Israel jsacksick

    jsacksick → changed the visibility of the branch 3.x to hidden.

  • 🇮🇱Israel jsacksick

    I'm going to remove some of the code from the patch, especially this:

    +    if ($store->status->value != $value) {
    +      $fields = $this->entityFieldManager->getFieldDefinitions('commerce_store', $this->entity->id());
    +      $fields['status']->getConfig($this->entity->id())->setDefaultValue($value)->save();
    +      $this->entityFieldManager->clearCachedFieldDefinitions();
    +    }

    We might need a bundleFieldDefinitions() implementation from the Store entity class to properly handle the default status value for bundles.
    For now, I'll ignore this.

  • 🇮🇱Israel jsacksick

    So, I expanded the checkout access logic to ensure access is allowed if the order belongs to a published store. I made changes to the cart provider to flag a cart as non eligible if it belongs to a disabled store.

    The product form still allows assigning a product to disabled stores... But perhaps we should keep that? As this technically allows preparing products for a store that will be enabled in the future?

    Let's see what the tests say now.

  • Pipeline finished with Skipped
    about 11 hours ago
    #545207
  • Pipeline finished with Skipped
    about 11 hours ago
    #545208
  • 🇮🇱Israel jsacksick

    Ok, I had started working on denying view access to products belonging to unpublished stores, but I changed my mind after discussing with @rszrama because:

    A store might be "closed" for business but a product page still be a relevant link to remain active

    .

    Will go ahead and merge the MR as is for now.

Production build 0.71.5 2024