Skip to content

Commit

Permalink
Merge pull request #1254 from dpfaffenbauer/issue/recycle-bin
Browse files Browse the repository at this point in the history
[CoreExtensions] fix issue with CoreShop CoreExtensions Recycle Bin
  • Loading branch information
dpfaffenbauer authored Feb 17, 2020
2 parents aba7e0c + 4c8f16b commit c37cecb
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 7 deletions.
22 changes: 22 additions & 0 deletions features/recycle_bin/store_values.feature
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 43 additions & 0 deletions src/CoreShop/Behat/Context/Domain/RecycleBinContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Behat\Context\Domain;

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Concrete;
use Webmozart\Assert\Assert;

final class RecycleBinContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;

/**
* @param SharedStorageInterface $sharedStorage
*/
public function __construct(SharedStorageInterface $sharedStorage)
{
$this->sharedStorage = $sharedStorage;
}

/**
* @Then /^the recycled (product) does not exist anymore$/
*/
public function theRecycledProductDoesNotExistAnymore(Concrete $concrete)
{
Assert::null(DataObject::getById($concrete->getId(), true));
}
}
92 changes: 92 additions & 0 deletions src/CoreShop/Behat/Context/Setup/RecycleBinContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Address\Model\ZoneInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Pimcore\DataObject\VersionHelper;
use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\Element\Recyclebin\Item;
use Pimcore\Model\User;
use Pimcore\Model\Version;
use Webmozart\Assert\Assert;

final class RecycleBinContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;

/**
* @param SharedStorageInterface $sharedStorage
*/
public function __construct(
SharedStorageInterface $sharedStorage
) {
$this->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
1 change: 1 addition & 0 deletions src/CoreShop/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 45 additions & 0 deletions src/CoreShop/Behat/Resources/config/suites/domain/recycle_bin.yml
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 19 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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}
*/
Expand Down
20 changes: 19 additions & 1 deletion src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,8 @@

class ProductSpecificPriceRules extends Data implements
Data\CustomResourcePersistingInterface,
Data\CustomVersionMarshalInterface
Data\CustomVersionMarshalInterface,
CustomRecyclingMarshalInterface
{
use TempEntityManagerTrait;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
*/
Expand Down
Loading

0 comments on commit c37cecb

Please sign in to comment.