Giter Site home page Giter Site logo

yproximite / syliuscustomoptionsplugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brille24/syliuscustomoptionsplugin

0.0 0.0 0.0 2.86 MB

A Sylius plugin that adds customer options

License: MIT License

JavaScript 0.80% PHP 86.04% Twig 6.80% Gherkin 6.36%

syliuscustomoptionsplugin's Introduction

Customer Options

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

Installation

  • Run composer require brille24/sylius-customer-options-plugin.

  • Register the Plugin in your config/bundles.php:

return [
    //...
    Brille24\SyliusCustomerOptionsPlugin\Brille24SyliusCustomerOptionsPlugin::class => ['all' => true],
];
  • Add the config.yml to your local config/packages/_sylius.yaml:
imports:
    ...
    - { resource: "@Brille24SyliusCustomerOptionsPlugin/Resources/config/app/config.yml" }
  • Add the routing.yml to your local config/routes.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_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.

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();
    }
    // ...
}
  • 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
bin/console sylius:fixtures:load
  • Finally, update the database and update the translations:
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.

syliuscustomoptionsplugin's People

Contributors

jakobtolkemit avatar mamazu avatar pamil avatar lchrusciel avatar bitbager avatar pjedrzejewski avatar zales0123 avatar stefandoorn avatar bartoszpietrzak1994 avatar t-n-y avatar sylfrid avatar antiseptikk avatar marek-pietrzak-tg avatar lsmith77 avatar prometee avatar loocos avatar seizan8 avatar ancarda avatar mrmadhat avatar dieterholvoet avatar jeromin avatar radnok avatar firstred avatar rvanginneken avatar shochdoerfer avatar teohhanhui avatar xaviermarchegay avatar adamterepora avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.