diff --git a/src/CoreShop/Behat/Context/Setup/ProductContext.php b/src/CoreShop/Behat/Context/Setup/ProductContext.php index 85d16c261a..9b46e587a9 100644 --- a/src/CoreShop/Behat/Context/Setup/ProductContext.php +++ b/src/CoreShop/Behat/Context/Setup/ProductContext.php @@ -118,7 +118,7 @@ public function theSiteHasAProductPricedAt(string $productName, int $price = 100 */ public function theProductIsPriced(ProductInterface $product, int $price, StoreInterface $store): void { - $product->setStores(array_merge($product->getStores(), [$store->getId()])); + $product->setStores(array_merge($product->getStores() ?? [], [$store->getId()])); $product->setStoreValuesOfType('price', $price, $store); $this->saveProduct($product); diff --git a/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php b/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php index 7205bb89bc..e28b51251a 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php +++ b/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php @@ -258,9 +258,9 @@ protected function validateCategory(Request $request, CategoryInterface $categor throw new NotFoundHttpException('category not found'); } - if (!in_array($this->getContext()->getStore()->getId(), array_values($category->getStores()))) { + if (!in_array($this->getContext()->getStore()->getId(), array_values($category->getStores() ?? []))) { throw new NotFoundHttpException( - sprintf(sprintf('store (id %s) not available in category', $this->getContext()->getStore()->getId())), + sprintf('store (id %s) not available in category', $this->getContext()->getStore()->getId()), ); } } diff --git a/src/CoreShop/Bundle/FrontendBundle/Controller/ProductController.php b/src/CoreShop/Bundle/FrontendBundle/Controller/ProductController.php index 6b9d38703f..7c42e7852a 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Controller/ProductController.php +++ b/src/CoreShop/Bundle/FrontendBundle/Controller/ProductController.php @@ -82,7 +82,7 @@ protected function validateProduct(Request $request, ProductInterface $product): throw new NotFoundHttpException('product not found'); } - if (!in_array($this->container->get(StoreContextInterface::class)->getStore()->getId(), $product->getStores())) { + if (!in_array($this->container->get(StoreContextInterface::class)->getStore()->getId(), $product->getStores() ?? [])) { throw new NotFoundHttpException('product not found'); } } diff --git a/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Multiselect.php b/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Multiselect.php index 4848687a73..32c119487c 100644 --- a/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Multiselect.php +++ b/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Multiselect.php @@ -48,10 +48,24 @@ public function preGetData($object, $params = []) $data = $object->getObjectVar($this->getName()); - if (null === $data) { - $data = []; - } - + // Don't convert null to empty array to allow Pimcore's inheritance to work + // null means "not set" and will inherit from parent + // empty array means "explicitly set to no values" and won't inherit return $data; } + + /** + * Checks if data is empty. Returns true only for null, not for empty arrays. + * This allows differentiating between "not set" (null) and "explicitly empty" ([]). + * + * @param array|null $data + * + * @return bool + */ + public function isEmpty($data): bool + { + // Only null is considered empty (will inherit from parent) + // Empty array [] is NOT empty (explicitly set to no values, won't inherit) + return null === $data; + } }