add readme md + add trait and interface

This commit is contained in:
christopherhero
2021-06-18 05:09:31 +02:00
parent 2089ca6e72
commit 7208c67d41
4 changed files with 121 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
...
}
```

View File

@@ -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 hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Model;
use Sylius\Component\Core\Model\ProductInterface;
interface ProductVariantInterface
{
public function getProduct(): ProductInterface;
}

View File

@@ -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 hello@bitbag.io.
*/
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;
}
}