Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Brille24/SyliusCustomOptionsPlugin
A Sylius plugin that adds customer options
https://github.com/Brille24/SyliusCustomOptionsPlugin
cart customization price sylius
Last synced: 6 days ago
JSON representation
A Sylius plugin that adds customer options
- Host: GitHub
- URL: https://github.com/Brille24/SyliusCustomOptionsPlugin
- Owner: Brille24
- License: mit
- Created: 2018-03-07T15:28:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-20T11:33:52.000Z (5 months ago)
- Last Synced: 2024-10-01T22:54:32.694Z (about 1 month ago)
- Topics: cart, customization, price, sylius
- Language: PHP
- Size: 2.86 MB
- Stars: 46
- Watchers: 9
- Forks: 34
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Customer Options
With this plugin the customer can add additional info to the product like so:
![Price import forms](docs/images/customeroption_frontend.png "The customer can upload a file")
![Price import forms](docs/images/customeroption_frontend_cart.png "And it will be displayed in the cart")## Installation
* Run `composer require brille24/sylius-customer-options-plugin`.
* Register the Plugin in your `config/bundles.php`:
```php
return [
//...
Brille24\SyliusCustomerOptionsPlugin\Brille24SyliusCustomerOptionsPlugin::class => ['all' => true],
];
```
* Add the `config.yml` to your local `config/packages/_sylius.yaml`:
```yaml
imports:
...
- { resource: "@Brille24SyliusCustomerOptionsPlugin/Resources/config/app/config.yml" }
```* Add the `routing.yml` to your local `config/routes.yaml`:
```yaml
brille24_customer_options:
resource: "@Brille24SyliusCustomerOptionsPlugin/Resources/config/app/routing.yml"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_itemsylius_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();
}
// ...
}
``````php
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();
}
// ...
}
```* If you also want default data you need to copy over the `brille24_sylius_customer_options_plugin_fixtures.yaml` file from the package directory and run
```bash
bin/console sylius:fixtures:load
```* Finally, generate migrations, update the database and update the translations:
```bash
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
bin/console translation:update
```## Things to consider
* Saving files as customer defined values as the values are currently stored as a string in the database## 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](docs/usage.md).