From d902ac9534d6456fb086f509abd1b86d6d880119 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Tue, 28 Jan 2020 18:05:21 +0100 Subject: [PATCH 1/2] [CoreExtensions] fix issue caused by https://github.com/pimcore/pimcore/pull/5507 and sort of fixed with https://github.com/pimcore/pimcore/pull/5588 --- .../CoreBundle/CoreExtension/StoreValues.php | 20 +++++++++++++++- .../MoneyBundle/CoreExtension/Money.php | 20 +++++++++++++++- .../ProductSpecificPriceRules.php | 20 +++++++++++++++- .../CoreExtension/ProductUnitDefinition.php | 23 ++++++++++++++++++- .../CoreExtension/ProductUnitDefinitions.php | 22 +++++++++++++++++- .../ProductQuantityPriceRules.php | 22 +++++++++++++++++- .../ResourceBundle/CoreExtension/Select.php | 19 ++++++++++++++- .../CustomRecyclingMarshalInterface.php | 23 +++++++++++++++++++ 8 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 src/CoreShop/Component/Pimcore/BCLayer/CustomRecyclingMarshalInterface.php diff --git a/src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php b/src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php index e970a55462..dc9e759f50 100644 --- a/src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php +++ b/src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php @@ -19,6 +19,7 @@ use CoreShop\Component\Core\Model\ProductStoreValuesInterface; use CoreShop\Component\Core\Model\StoreInterface; use CoreShop\Component\Core\Repository\ProductStoreValuesRepositoryInterface; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\Product\Model\ProductUnitDefinitionsInterface; use CoreShop\Component\Resource\Factory\FactoryInterface; use CoreShop\Component\Resource\Factory\RepositoryFactoryInterface; @@ -30,7 +31,8 @@ class StoreValues extends Model\DataObject\ClassDefinition\Data implements Model\DataObject\ClassDefinition\Data\CustomResourcePersistingInterface, - Model\DataObject\ClassDefinition\Data\CustomVersionMarshalInterface + Model\DataObject\ClassDefinition\Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { use TempEntityManagerTrait; @@ -461,6 +463,22 @@ public function unmarshalVersion($object, $data) return $entities; } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * {@inheritdoc} */ diff --git a/src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php b/src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php index 16f55d3171..bda111d445 100644 --- a/src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php +++ b/src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php @@ -12,13 +12,15 @@ namespace CoreShop\Bundle\MoneyBundle\CoreExtension; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use Pimcore\Model; use Pimcore\Model\DataObject\ClassDefinition\Data; class Money extends Model\DataObject\ClassDefinition\Data implements Data\ResourcePersistenceAwareInterface, Data\QueryResourcePersistenceAwareInterface, - Data\CustomVersionMarshalInterface + Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { /** * Static type of this element. @@ -164,6 +166,22 @@ public function unmarshalVersion($object, $data) return $this->getDataFromEditmode($data, $object); } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * {@inheritdoc} */ diff --git a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductSpecificPriceRules.php b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductSpecificPriceRules.php index 589c0d41b1..eb48f05861 100644 --- a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductSpecificPriceRules.php +++ b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductSpecificPriceRules.php @@ -15,6 +15,7 @@ use CoreShop\Bundle\ProductBundle\Form\Type\ProductSpecificPriceRuleType; use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait; use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\Product\Model\ProductInterface; use CoreShop\Component\Product\Model\ProductSpecificPriceRuleInterface; use CoreShop\Component\Product\Repository\ProductSpecificPriceRuleRepositoryInterface; @@ -28,7 +29,8 @@ class ProductSpecificPriceRules extends Data implements Data\CustomResourcePersistingInterface, - Data\CustomVersionMarshalInterface + Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { use TempEntityManagerTrait; @@ -163,6 +165,22 @@ public function unmarshalVersion($object, $data) return $entities; } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * @param array $data * @param null $object diff --git a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinition.php b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinition.php index d7c170f3bf..55598240bf 100644 --- a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinition.php +++ b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinition.php @@ -12,13 +12,18 @@ namespace CoreShop\Bundle\ProductBundle\CoreExtension; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\Product\Model\ProductUnitDefinitionInterface; use CoreShop\Component\Resource\Model\ResourceInterface; use CoreShop\Component\Resource\Repository\RepositoryInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; -class ProductUnitDefinition extends Data implements Data\ResourcePersistenceAwareInterface, Data\QueryResourcePersistenceAwareInterface, Data\CustomVersionMarshalInterface +class ProductUnitDefinition extends Data implements + Data\ResourcePersistenceAwareInterface, + Data\QueryResourcePersistenceAwareInterface, + Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { /** * Static type of this element. @@ -164,6 +169,22 @@ public function unmarshalVersion($object, $data) return $this->getDataFromEditmode($data, $object); } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * {@inheritdoc} */ diff --git a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinitions.php b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinitions.php index 6b8d962209..e5ae02e9f4 100644 --- a/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinitions.php +++ b/src/CoreShop/Bundle/ProductBundle/CoreExtension/ProductUnitDefinitions.php @@ -15,6 +15,7 @@ use CoreShop\Bundle\ProductBundle\Form\Type\Unit\ProductUnitDefinitionsType; use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait; use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\Product\Model\ProductInterface; use CoreShop\Component\Product\Model\ProductUnitDefinitionInterface; use CoreShop\Component\Product\Model\ProductUnitDefinitionsInterface; @@ -28,7 +29,10 @@ use Pimcore\Model\DataObject\LazyLoadedFieldsInterface; use Webmozart\Assert\Assert; -class ProductUnitDefinitions extends Data implements Data\CustomResourcePersistingInterface, Data\CustomVersionMarshalInterface +class ProductUnitDefinitions extends Data implements + Data\CustomResourcePersistingInterface, + Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { use TempEntityManagerTrait; @@ -210,6 +214,22 @@ public function unmarshalVersion($object, $data) return $entityData; } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * {@inheritdoc} */ diff --git a/src/CoreShop/Bundle/ProductQuantityPriceRulesBundle/CoreExtension/ProductQuantityPriceRules.php b/src/CoreShop/Bundle/ProductQuantityPriceRulesBundle/CoreExtension/ProductQuantityPriceRules.php index 0267e3edcb..4c4fb9c412 100644 --- a/src/CoreShop/Bundle/ProductQuantityPriceRulesBundle/CoreExtension/ProductQuantityPriceRules.php +++ b/src/CoreShop/Bundle/ProductQuantityPriceRulesBundle/CoreExtension/ProductQuantityPriceRules.php @@ -16,6 +16,7 @@ use CoreShop\Bundle\ProductQuantityPriceRulesBundle\Form\Type\ProductQuantityPriceRuleType; use CoreShop\Bundle\ResourceBundle\CoreExtension\TempEntityManagerTrait; use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityMerger; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\ProductQuantityPriceRules\Events; use CoreShop\Component\ProductQuantityPriceRules\Model\ProductQuantityPriceRuleInterface; use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangeInterface; @@ -31,7 +32,10 @@ use Webmozart\Assert\Assert; use function League\Uri\merge_query; -class ProductQuantityPriceRules extends Data implements Data\CustomResourcePersistingInterface, Data\CustomVersionMarshalInterface +class ProductQuantityPriceRules extends Data implements + Data\CustomResourcePersistingInterface, + Data\CustomVersionMarshalInterface, + CustomRecyclingMarshalInterface { use TempEntityManagerTrait; @@ -160,6 +164,22 @@ public function unmarshalVersion($object, $data) return $entities; } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * @param mixed $data * @param null $object diff --git a/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Select.php b/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Select.php index 2a36f02958..67dff61b92 100644 --- a/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Select.php +++ b/src/CoreShop/Bundle/ResourceBundle/CoreExtension/Select.php @@ -12,12 +12,13 @@ namespace CoreShop\Bundle\ResourceBundle\CoreExtension; +use CoreShop\Component\Pimcore\BCLayer\CustomRecyclingMarshalInterface; use CoreShop\Component\Resource\Model\ResourceInterface; use CoreShop\Component\Resource\Repository\RepositoryInterface; use Pimcore\Model; use Pimcore\Model\DataObject\ClassDefinition\Data; -abstract class Select extends Data\Select implements Data\CustomVersionMarshalInterface +abstract class Select extends Data\Select implements Data\CustomVersionMarshalInterface, CustomRecyclingMarshalInterface { /** * @var bool @@ -58,6 +59,22 @@ public function unmarshalVersion($object, $data) return $this->getRepository()->find($data); } + /** + * {@inheritdoc} + */ + public function marshalRecycleData($object, $data) + { + return $this->marshalVersion($object, $data); + } + + /** + * {@inheritdoc} + */ + public function unmarshalRecycleData($object, $data) + { + return $this->unmarshalVersion($object, $data); + } + /** * {@inheritdoc} */ diff --git a/src/CoreShop/Component/Pimcore/BCLayer/CustomRecyclingMarshalInterface.php b/src/CoreShop/Component/Pimcore/BCLayer/CustomRecyclingMarshalInterface.php new file mode 100644 index 0000000000..018990a75c --- /dev/null +++ b/src/CoreShop/Component/Pimcore/BCLayer/CustomRecyclingMarshalInterface.php @@ -0,0 +1,23 @@ + Date: Thu, 6 Feb 2020 14:02:41 +0100 Subject: [PATCH 2/2] [Behat] add tests for recycling bin --- features/recycle_bin/store_values.feature | 22 +++++ .../Context/Domain/RecycleBinContext.php | 43 +++++++++ .../Behat/Context/Setup/RecycleBinContext.php | 92 +++++++++++++++++++ .../config/services/contexts/domain.yml | 7 ++ .../config/services/contexts/setup.yml | 7 ++ .../Behat/Resources/config/suites.yml | 1 + .../config/suites/domain/recycle_bin.yml | 45 +++++++++ 7 files changed, 217 insertions(+) create mode 100644 features/recycle_bin/store_values.feature create mode 100644 src/CoreShop/Behat/Context/Domain/RecycleBinContext.php create mode 100644 src/CoreShop/Behat/Context/Setup/RecycleBinContext.php create mode 100644 src/CoreShop/Behat/Resources/config/suites/domain/recycle_bin.yml diff --git a/features/recycle_bin/store_values.feature b/features/recycle_bin/store_values.feature new file mode 100644 index 0000000000..30ac380b8e --- /dev/null +++ b/features/recycle_bin/store_values.feature @@ -0,0 +1,22 @@ +@recycle_bin @recycle_bin_store_values +Feature: In order to support Pimcore Recycle Bin, we have to serialize Store Values and merge them back + + Background: + Given the site operates on a store in "Austria" + And the site has a country "Germany" with currency "EUR" + And the site has a store "Germany" with country "Germany" and currency "EUR" + And the site operates on locale "en" + And the site has a product "Shoe" priced at 100 + And the products price is 100 for store "Austria" + And the products price is 200 for store "Germany" + + Scenario: Change Prices + Given I recycle the product + Then the recycled product does not exist anymore + Given I restore the recycled product + + Then I am in store "Austria" + And the product should be priced at "100" + + Then I am in store "Germany" + And the product should be priced at "200" diff --git a/src/CoreShop/Behat/Context/Domain/RecycleBinContext.php b/src/CoreShop/Behat/Context/Domain/RecycleBinContext.php new file mode 100644 index 0000000000..c336b410c2 --- /dev/null +++ b/src/CoreShop/Behat/Context/Domain/RecycleBinContext.php @@ -0,0 +1,43 @@ +sharedStorage = $sharedStorage; + } + + /** + * @Then /^the recycled (product) does not exist anymore$/ + */ + public function theRecycledProductDoesNotExistAnymore(Concrete $concrete) + { + Assert::null(DataObject::getById($concrete->getId(), true)); + } +} diff --git a/src/CoreShop/Behat/Context/Setup/RecycleBinContext.php b/src/CoreShop/Behat/Context/Setup/RecycleBinContext.php new file mode 100644 index 0000000000..faae9fe989 --- /dev/null +++ b/src/CoreShop/Behat/Context/Setup/RecycleBinContext.php @@ -0,0 +1,92 @@ +sharedStorage = $sharedStorage; + } + + /** + * @Then /^I recycle the (product "[^"]+")$/ + * @Then /^I recycle the (product)$/ + */ + public function IAddTheObjectToTheBin(Concrete $concrete) + { + /** + * @var Item $item + */ + $item = new Item(); + $item->setElement($concrete); + $item->save(); + + $concrete->delete(); + + $this->sharedStorage->set( + 'data_object_recycle_' . $concrete->getId(), + $item->getId() + ); + } + + /** + * @Then /^I restore the recycled (product "[^"]+")$/ + * @Then /^I restore the recycled (product)$/ + */ + public function iRestoreTheRecycledProduct(Concrete $concrete) + { + $key = 'data_object_recycle_' . $concrete->getId(); + + /** + * @var Item $item + */ + $item = Item::getById($this->sharedStorage->get($key)); + + Assert::isInstanceOf($item, Item::class); + + $item->restore(); + + $product = DataObject::getById($concrete->getId(), true); + + + Assert::isInstanceOf($product, ProductInterface::class); + + //Force reload of restored product + $this->sharedStorage->set('product', $product); + } +} diff --git a/src/CoreShop/Behat/Resources/config/services/contexts/domain.yml b/src/CoreShop/Behat/Resources/config/services/contexts/domain.yml index 5d24f0f9a3..934ee9e872 100644 --- a/src/CoreShop/Behat/Resources/config/services/contexts/domain.yml +++ b/src/CoreShop/Behat/Resources/config/services/contexts/domain.yml @@ -255,3 +255,10 @@ services: - '@knp_menu.menu_provider' tags: - { name: fob.context_service } + + coreshop.behat.context.domain.recycle_bin: + class: CoreShop\Behat\Context\Domain\RecycleBinContext + arguments: + - '@coreshop.behat.shared_storage' + tags: + - { name: fob.context_service } diff --git a/src/CoreShop/Behat/Resources/config/services/contexts/setup.yml b/src/CoreShop/Behat/Resources/config/services/contexts/setup.yml index 40598eb9fe..cdc3ec11f7 100644 --- a/src/CoreShop/Behat/Resources/config/services/contexts/setup.yml +++ b/src/CoreShop/Behat/Resources/config/services/contexts/setup.yml @@ -327,3 +327,10 @@ services: - '@coreshop.behat.shared_storage' tags: - { name: fob.context_service } + + coreshop.behat.context.setup.recycle_bin: + class: CoreShop\Behat\Context\Setup\RecycleBinContext + arguments: + - '@coreshop.behat.shared_storage' + tags: + - { name: fob.context_service } diff --git a/src/CoreShop/Behat/Resources/config/suites.yml b/src/CoreShop/Behat/Resources/config/suites.yml index c79655f9e7..b92f0c85f0 100644 --- a/src/CoreShop/Behat/Resources/config/suites.yml +++ b/src/CoreShop/Behat/Resources/config/suites.yml @@ -19,3 +19,4 @@ imports: - suites/domain/product_quantity_price_rules.yml - suites/domain/menu.yml - suites/domain/version.yml + - suites/domain/recycle_bin.yml diff --git a/src/CoreShop/Behat/Resources/config/suites/domain/recycle_bin.yml b/src/CoreShop/Behat/Resources/config/suites/domain/recycle_bin.yml new file mode 100644 index 0000000000..6ae1e4d222 --- /dev/null +++ b/src/CoreShop/Behat/Resources/config/suites/domain/recycle_bin.yml @@ -0,0 +1,45 @@ +default: + suites: + domain_product: + contexts: + - coreshop.behat.context.hook.pimcore_setup + - coreshop.behat.context.hook.coreshop_setup + + - coreshop.behat.context.hook.doctrine_orm + - coreshop.behat.context.hook.pimcore_dao + + - coreshop.behat.context.transform.shared_storage + - coreshop.behat.context.transform.product + - coreshop.behat.context.transform.product_price_rule + - coreshop.behat.context.transform.product_specific_price_rule + - coreshop.behat.context.transform.category + - coreshop.behat.context.transform.country + - coreshop.behat.context.transform.currency + - coreshop.behat.context.transform.customer + - coreshop.behat.context.transform.customer_group + - coreshop.behat.context.transform.zone + - coreshop.behat.context.transform.store + - coreshop.behat.context.transform.tax_rate + - coreshop.behat.context.transform.tax_rule_group + - coreshop.behat.context.transform.product_unit + + - coreshop.behat.context.setup.product + - coreshop.behat.context.setup.locale + - coreshop.behat.context.setup.product_price_rule + - coreshop.behat.context.setup.product_specific_price_rule + - coreshop.behat.context.setup.store + - coreshop.behat.context.setup.category + - coreshop.behat.context.setup.country + - coreshop.behat.context.setup.currency + - coreshop.behat.context.setup.customer + - coreshop.behat.context.setup.customer_group + - coreshop.behat.context.setup.zone + - coreshop.behat.context.setup.tax_rate + - coreshop.behat.context.setup.tax_rule_group + - coreshop.behat.context.setup.product_unit + - coreshop.behat.context.setup.recycle_bin + + - coreshop.behat.context.domain.product + - coreshop.behat.context.domain.recycle_bin + filters: + tags: "@recycle_bin"