Skip to content

Commit

Permalink
add readme md + add trait and interface
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherhero committed Jun 18, 2021
1 parent 2089ca6 commit 7208c67
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ return [
];
```

Use trait `BitBag\SyliusElasticsearchPlugin\Model\ProductVariantTrait` in an overridden ProductVariant entity class. [see how to overwrite a sylius model](https://docs.sylius.com/en/1.9/customization/model.html)

also Use `BitBag\SyliusElasticsearchPlugin\Model\ProductVariantInterface` interface in ProductVariant entity class.
The final effect should look like the following:

```
use BitBag\SyliusElasticsearchPlugin\Model\ProductVariantInterface as BitBagElasticsearchPluginVariant;
use BitBag\SyliusElasticsearchPlugin\Model\ProductVariantTrait;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface as BaseProductVariantInterface;
class ProductVariant extends BaseProductVariant implements BaseProductVariantInterface, BitBagElasticsearchPluginVariant
{
use ProductVariantTrait;
...
}
```

Import required config in your `config/packages/_sylius.yaml` file:
```yaml
# config/packages/_sylius.yaml
Expand Down
58 changes: 58 additions & 0 deletions UPGRADE-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,61 @@

* `Lakion\Behat\MinkDebugExtension` was replaced by `FriendsOfBehat\MinkDebugExtension`

* If the configuration `src/Resources/config/services/event_listener.xml` has been overwritten then the following configuration must be used:
```
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="bitbag_sylius_elasticsearch_plugin.event_listener.resource_index" class="BitBag\SyliusElasticsearchPlugin\EventListener\ResourceIndexListener">
<argument type="service" id="bitbag.sylius_elasticsearch_plugin.refresher.resource" />
<argument type="collection">
<argument type="collection">
<argument key="model">%sylius.model.product_attribute.class%</argument>
<argument key="serviceId">fos_elastica.object_persister.bitbag_attribute_taxons.default</argument>
</argument>
<argument type="collection">
<argument key="model">%sylius.model.product_option.class%</argument>
<argument key="serviceId">fos_elastica.object_persister.bitbag_option_taxons.default</argument>
</argument>
<argument type="collection">
<argument key="getParentMethod">getProduct</argument>
<argument key="model">%sylius.model.product.class%</argument>
<argument key="serviceId">fos_elastica.object_persister.bitbag_shop_product.default</argument>
</argument>
</argument>
<tag name="kernel.event_listener" event="sylius.product_attribute.post_create" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.product_attribute.post_update" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.option.post_create" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.option.post_update" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.product.post_create" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.product.post_update" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.product_variant.post_create" method="updateIndex" />
<tag name="kernel.event_listener" event="sylius.product_variant.post_update" method="updateIndex" />
</service>
<service id="bitbag_sylius_elasticsearch_plugin.event_listener.order_products" class="BitBag\SyliusElasticsearchPlugin\EventListener\OrderProductsListener" public="true">
<argument type="service" id="bitbag.sylius_elasticsearch_plugin.refresher.resource" />
<argument type="string">fos_elastica.object_persister.bitbag_shop_product.default</argument>
<tag name="kernel.event_listener" event="sylius.order.post_complete" method="updateOrderProducts" />
</service>
</services>
</container>
```
* Trait `BitBag\SyliusElasticsearchPlugin\Model\ProductVariantTrait` should be used in an overridden ProductVariant entity class. [see how to overwrite a sylius model](https://docs.sylius.com/en/1.9/customization/model.html)
* Use `BitBag\SyliusElasticsearchPlugin\Model\ProductVariantInterface` interface in ProductVariant entity class.
The final effect should look like the following:
```
use BitBag\SyliusElasticsearchPlugin\Model\ProductVariantInterface as BitBagElasticsearchPluginVariant;
use BitBag\SyliusElasticsearchPlugin\Model\ProductVariantTrait;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface as BaseProductVariantInterface;
class ProductVariant extends BaseProductVariant implements BaseProductVariantInterface, BitBagElasticsearchPluginVariant
{
use ProductVariantTrait;
...
}
```
19 changes: 19 additions & 0 deletions src/Model/ProductVariantInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusElasticsearchPlugin\Model;

use Sylius\Component\Core\Model\ProductInterface;

interface ProductVariantInterface
{
public function getProduct(): ProductInterface;
}
25 changes: 25 additions & 0 deletions src/Model/ProductVariantTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusElasticsearchPlugin\Model;

use Sylius\Component\Core\Model\ProductInterface;

trait ProductVariantTrait
{
public function getProduct(): ProductInterface
{
$product = parent::getProduct();
$product->addVariant($this);

return $product;
}
}

0 comments on commit 7208c67

Please sign in to comment.