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".

Issue fork commerce-2921000

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zenimagine created an issue. See original summary.

zenimagine’s picture

Title: Ability to moderate stores » Add published / unpublished store
zenimagine’s picture

Issue summary: View changes
bojanz’s picture

Sure, why not.

rob c’s picture

Status: Active » Needs review
StatusFileSize
new6.78 KB

Might need a bit more work, let's see.

Status: Needs review » Needs work
rob c’s picture

Status: Needs work » Needs review
StatusFileSize
new9.68 KB

New patch in PR at https://github.com/drupalcommerce/commerce/pull/829

To prevent a similar situation to the 'default' widget description, let's debate the following before this gets committed:

Do you:
A. Publish / Unpublish a store
or
B. Enable / Disable a store

Published is really a 'node'-thing i believe. And it's actually called status in the database (the field).

If we go with B the PR needs a tweak.

TODO: a description might not hurt for the status field?

rob c’s picture

zenimagine’s picture

I think we should use the terms enable / disable.

Are revisions possible for the shops ?

This will make it possible to moderate the shops with the future module "Moderation" (indispensable for a marketplace).

rob c’s picture

Status: Needs review » Needs work

I think we should use the terms enable / disable.

Ok, i'll update the PR.

Are revisions possible for the shops ?

Not at this time. You might want to create a new issue for this, and not sure what the maintainers think about revisionable stores. (@bojanz what do you think about revisions for stores and the direction of the current PR)

zenimagine’s picture

Can we create revisions with the stores ?

zenimagine’s picture

"Workflows" and "Content Moderation" modules are now in stable version with Drupal 8.5

Can we moderate the stores ?

mglaman’s picture

Priority: Major » Normal

I like "Enable / Disable a store"

This is good if you're bringing a new store online and adding products, but need to reference that store -- and that store can't show up in a store selector, for instance.

Can we moderate the stores ?

Only if we made them support revisions. But I'm not sure the benefit there? In a marketplace I would assume the "store" entity acts like a settings page, not a piece of content.

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new7.39 KB

Here is a rerolled patch. We no longer need specific actions as core provides them. This also copies the Promotion format for "Status" as a radio of enabled or disabled.

mglaman’s picture

StatusFileSize
new8.81 KB

Forgot an upgrade path!

The last submitted patch, 14: 2921000-14.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 15: 2921000-15.patch, failed testing. View results

bojanz’s picture

Title: Add published / unpublished store » Add a status field (enabled/disabled) to stores
Priority: Normal » Major

Retitling.

It's obvious from the discussion above that it makes more sense for a store to be enabled/disabled than published/unpublished.
This is already the case for Promotion, Coupon, ShippingMethod, PriceList, PriceListItem.

As a result of that, we should not be using EntityPublishedInterface and EntityPublishedTrait (just like the other entity types listed above don't).
It might make sense to introduce our own interface/trait, now that it's a common pattern.

The listed entities also don't have a per-bundle setting ("Enable new stores of this type by default"), we always default to TRUE instead, but that's cause they don't use bundle entities at all. Do we still want that feature, or was it just copied from core?

EDIT: Opened #3004026: Add EntityEnabledInterface and EntityEnabledTrait.

bojanz’s picture

Closed #3004026: Add EntityEnabledInterface and EntityEnabledTrait:

We have decided not to do this.

Lots of code assumes EntityPublishedInterface (Entity API access/query access, Search API filters, Views, Content Moderation, etc). It is not feasible to reimplement all of it. We'll have to accept that content entities always implement EntityPublishedInterface, even if their UI labels don't match the code terminology. After all, we already do it with bundles/types and labels/names/titles.

This means that the current patch is close to done. We are missing update code for adding the "published" entity key though.

As for this:

The listed entities also don't have a per-bundle setting ("Enable new stores of this type by default"), we always default to TRUE instead, but that's cause they don't use bundle entities at all. Do we still want that feature, or was it just copied from core?

Doesn't hurt to keep it, we have it on product types too.

anpolimus’s picture

At one of my projects, I've added state_machine for the organization of moderation workflow.
After last updates, all views are throwing exception with: The "commerce_store" entity type did not define a "published" key in
I've added published key to the store entity and it is fixed my problem.
I see from description that this issue is connected to my problem and fix.
How I can help you to fix finish patch here?

anpolimus’s picture

StatusFileSize
new8.77 KB

Rerolled patch against the latest version.

anpolimus’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 21: 2921000-16.patch, failed testing. View results

zenimagine’s picture

Hi, the patch #21 is no longer applicable on the DEV version

dstorozhuk’s picture

Version: 8.x-2.x-dev » 8.x-2.16
StatusFileSize
new8.89 KB

Update patch.

zenimagine’s picture

@dstorozhuk Great, thank you patch #25 works.

But some functionality (conditions) is missing:

If the store is unpublished, the associated products must be unpublished automatically (or manually with a warning message "To unpublish the store, you must either unpublish the associated products or dissociate them from the store).

If the store is unpublished and the products are associated with more than one store, then the products must have remained unpublished.

mglaman’s picture

If the store is unpublished, the associated products must be unpublished automatically (or manually with a warning message "To unpublish the store, you must either unpublish the associated products or dissociate them from the store).

If the store is unpublished and the products are associated with more than one store, then the products must have remained unpublished.

That's a lot. The products don't need to be unpublished, with the purchased_entity constraint it should just not be "add to cartable" because it has no valid stores. Using event subscribers/hooks you can add a more robust reaction.

zenimagine’s picture

Since I applied the patch I have this message and all have disappeared

/admin/people/permissions

Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the Roles page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. From the Account settings page, you can make any role into an Administrator role for the site, meaning that role will be granted all new permissions automatically. You should be careful to ensure that only trusted users are given this access and level of control of your site.

thanh_uong’s picture

StatusFileSize
new9.1 KB

I rerolled this for Commerce 8.x-2.24, hope someone finds this helpful.

sivaji_ganesh_jojodae’s picture

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

willeaton’s picture

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?

jsacksick’s picture

Version: 8.x-2.16 » 3.x-dev

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.

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

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

jsacksick’s picture

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.

EDIT: Hm... I just realized this was copied from the ProductTypeForm.

jsacksick’s picture

Status: Needs work » Needs review

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.

jsacksick’s picture

I wonder if we need a hook_entity_access() implementation to restrict access to products belonging to a store that is unpublished; At the same time, if a product belongs to multiple stores, perhaps we should still allow access.

Tempted to merge the current MR and implement additional access logic in followup issues. This should be a good starting point.

  • jsacksick committed d01774ea on 3.x
    Issue #2921000 by jsacksick, Rob C, mglaman, anpolimus, dstorozhuk,...
jsacksick’s picture

Status: Needs review » Fixed

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.