- Issue created by @alexberendei
- 🇷🇴Romania alexberendei
Changed the loadDefault function inside MarketplaceStorage.php to:
public function loadDefault(AccountInterface $user = NULL) { $default = NULL; if ($uid = $this->getCurrentUserId($user)) { $config = $this->configFactory->get('commerce_marketplace.settings'); $uuid = $config->get("owners.{$uid}.default_store"); $query = \Drupal::entityTypeManager()->getStorage('commerce_store')->getQuery(); $ids = $query->condition('uid', $uid)->accessCheck(TRUE)->execute(); } elseif ($defaultStore = parent::loadDefault()) { $uuid = $defaultStore->uuid(); $query = \Drupal::entityTypeManager()->getStorage('commerce_store')->getQuery(); $ids = $query->accessCheck(TRUE)->execute(); } if (!empty($ids)) { $stores = $this->loadMultiple($ids); if ($uuid) { foreach ($stores as $store) { if ($store->uuid() == $uuid) { $default = $store; break; } } } else { $default = end($stores); } } else { $stores = $this->loadMultiple(); } if (!$default && isset($store)) { // This is the case when previously assigned default store was // deleted, so we need to return at least the last found store. $default = $store; $default->enforceIsNew(); if (count($stores) > 1) { $this->messenger()->addWarning($this->t('No one default store is assigned yet. Note that it is recommended to have one explicitly assigned otherwise the last found store will be dimmed as the default. This may lead to unexpected behaviour.'), FALSE); } } elseif (!$default && $stores) { // As a last resort let's return the first store in the list. $default = reset($stores); } return $default; }
- 🇷🇴Romania alexberendei
On /store/add, the same error appear pointing to loadMultiple
#2 /app/web/modules/contrib/commerce_marketplace/src/MarketplaceStorage.php(70): Drupal\commerce_marketplace\MarketplaceStorage->loadMultiple()I've changed the loadMultiple function, in order to work, to :
public function loadMultiple(array $ids = NULL, AccountInterface $user = NULL) { $stores = []; // If $ids are provided, load the entities directly. if ($ids) { $stores = parent::loadMultiple($ids); } else { // If $ids are not provided, build the entity query. $query = \Drupal::entityTypeManager()->getStorage('commerce_store')->getQuery(); // Add condition based on the user, if provided. if ($user) { $query->condition('uid', $user->id()); } // Execute the query and load the entities. $ids = $query->accessCheck(TRUE)->execute(); $stores = parent::loadMultiple($ids); } return $stores; }
- First commit to issue fork.
- Merge request !5Update file MarketplaceStorage.php for access check issue → (Open) created by Harpreet_singh_saluja
- Status changed to Needs review
8 months ago 10:26am 8 May 2024 - 🇮🇳India Harpreet_singh_saluja
Hii @farhadhf and all maintainers I have created MR for the above issue, Please review this
Thanks !! - 🇷🇴Romania alexberendei
Thank you @Harpreet_singh_saluja , I have another place where this error also happens:
on /admin/commerce/config/store
Operations: #0 /app/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(80): Drupal\Core\Entity\Query\Sql\Query->prepare()
#1 /app/web/modules/contrib/commerce_marketplace/src/Plugin/Field/FieldFormatter/MarketplaceTypeLabelFormatter.php(94): Drupal\Core\Entity\Query\Sql\Query->execute()I've replaced this (94) line:
$used = count($this->storage->getQuery()->condition('uid', $uid)->condition('type', $store_type)->execute());
To this:
$query = $this->storage->getQuery(); $query->condition('uid', $uid); $query->condition('type', $store_type); // Explicitly set whether the query should be access checked $query->accessCheck(FALSE); // or TRUE if access checking is needed $used = count($query->execute());
- 🇮🇳India Harpreet_singh_saluja
created a child issue for that and created merge request there too. @alexberendei thanks for point it
- 🇩🇪Germany fsnet
Access checks are already adressed in 🐛 For D10 version: Update accessCheck Needs review . Since the other issue is older and adresses all occurences we should write a MR for 🐛 For D10 version: Update accessCheck Needs review and close this issue as duplicate.