Brille24 / SyliusCustomOptionsPlugin

A Sylius plugin that adds customer options
MIT License
46 stars 34 forks source link
cart customization price sylius

Customer Options

With this plugin the customer can add additional info to the product like so: Price import forms Price import forms

Installation

return [
    //...
    Brille24\SyliusCustomerOptionsPlugin\Brille24SyliusCustomerOptionsPlugin::class => ['all' => true],
];

sylius_shop_ajax_cart_add_item: path: ajax/cart/add methods: [POST] defaults: _controller: sylius.controller.order_item::addAction _format: json _sylius: factory: method: createForProductWithCustomerOption arguments: [expr:notFoundOnNull(service('sylius.repository.product').find($productId))] form: type: Sylius\Bundle\CoreBundle\Form\Type\Order\AddToCartType options: product: expr:notFoundOnNull(service('sylius.repository.product').find($productId)) redirect: route: sylius_shop_cart_summary parameters: {} flash: sylius.cart.add_item

sylius_shop_partial_cart_add_item: path: cart/add-item methods: [GET] defaults: _controller: sylius.controller.order_item::addAction _sylius: template: $template factory: method: createForProductWithCustomerOption arguments: [expr:notFoundOnNull(service('sylius.repository.product').find($productId))] form: type: Sylius\Bundle\CoreBundle\Form\Type\Order\AddToCartType options: product: expr:notFoundOnNull(service('sylius.repository.product').find($productId)) redirect: route: sylius_shop_cart_summary parameters: {}


* Copy the template overrides from the plugin directory

From: [shop_dir]/vendor/brille24/sylius-customer-options-plugin/test/Application/templates To: [shop_dir]/templates


In order to use the customer options, you need to override the product and order item.
```php
use Brille24\SyliusCustomerOptionsPlugin\Entity\ProductInterface;
use Brille24\SyliusCustomerOptionsPlugin\Traits\ProductCustomerOptionCapableTrait;
use Sylius\Component\Core\Model\Product as BaseProduct;

class Product extends BaseProduct implements ProductInterface {
    use ProductCustomerOptionCapableTrait {
        __construct as protected customerOptionCapableConstructor;
    }

     public function __construct()
    {
        parent::__construct();

        $this->customerOptionCapableConstructor();
    }
    // ...
}
use Brille24\SyliusCustomerOptionsPlugin\Entity\OrderItemInterface;
use Brille24\SyliusCustomerOptionsPlugin\Traits\OrderItemCustomerOptionCapableTrait;
use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;

class OrderItem extends BaseOrderItem implements OrderItemInterface
{
    use OrderItemCustomerOptionCapableTrait {
        __construct as protected customerOptionCapableConstructor;
    }

    public function __construct()
    {
        parent::__construct();

        $this->customerOptionCapableConstructor();
    }
    // ...
}

Things to consider

Developing

When developing it is recommended to use git hooks for this just copy the docs/pre-commit to .git/hooks/pre-commit and make it executable. Then you will check your codestyle before committing.

Usage

Documentation on how to use the plugin can be found here.