From 255db9048b8e2a57ae8da868049a43e290bad29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20B=C5=82oszyk?= Date: Thu, 14 May 2020 18:19:11 +0200 Subject: [PATCH] Fix working with mssql --- .../DependencyInjection/SonataProductExtension.php | 2 +- src/ProductBundle/Entity/ProductCategoryManager.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ProductBundle/DependencyInjection/SonataProductExtension.php b/src/ProductBundle/DependencyInjection/SonataProductExtension.php index 47cd50aad..01d97be45 100644 --- a/src/ProductBundle/DependencyInjection/SonataProductExtension.php +++ b/src/ProductBundle/DependencyInjection/SonataProductExtension.php @@ -312,6 +312,7 @@ public function registerDoctrineMapping(array $config): void 'targetEntity' => $config['class']['product'], 'cascade' => [ 'persist', + 'remove', ], 'mappedBy' => null, 'inversedBy' => 'variations', @@ -319,7 +320,6 @@ public function registerDoctrineMapping(array $config): void [ 'name' => 'parent_id', 'referencedColumnName' => 'id', - 'onDelete' => 'CASCADE', ], ], 'orphanRemoval' => false, diff --git a/src/ProductBundle/Entity/ProductCategoryManager.php b/src/ProductBundle/Entity/ProductCategoryManager.php index d530b8a00..d60aa69ba 100644 --- a/src/ProductBundle/Entity/ProductCategoryManager.php +++ b/src/ProductBundle/Entity/ProductCategoryManager.php @@ -96,9 +96,9 @@ public function getProductCount(CategoryInterface $category, $limit = 1000) LEFT JOIN %s p ON pc.product_id = p.id LEFT JOIN %s c ON pc.category_id = c.id LEFT JOIN %s p2 ON p.id = p2.parent_id - WHERE p.enabled = :enabled - AND (p2.enabled = :enabled OR p2.enabled IS NULL) - AND (c.enabled = :enabled OR c.enabled IS NULL) + WHERE p.enabled = :productEnabled + AND (p2.enabled = :parentEnabled OR p2.enabled IS NULL) + AND (c.enabled = :categoryEnabled OR c.enabled IS NULL) AND p.parent_id IS NULL AND pc.category_id = :categoryId LIMIT %d @@ -107,7 +107,9 @@ public function getProductCount(CategoryInterface $category, $limit = 1000) $sql = sprintf($sql, $metadata->table['name'], $productMetadata->table['name'], $categoryMetadata->table['name'], $productMetadata->table['name'], $limit); $statement = $this->getConnection()->prepare($sql); - $statement->bindValue('enabled', 1); + $statement->bindValue('productEnabled', 1); + $statement->bindValue('parentEnabled', 1); + $statement->bindValue('categoryEnabled', 1); $statement->bindValue('categoryId', $category->getId()); $statement->execute();