ggggino / skuskucart-bundle
This bundle aim to be a slim cart manager
Installs: 116
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 3
Open Issues: 2
Type:symfony-bundle
Requires
- php: ^5.6|^7.0
- craue/formflow-bundle: ^3.0
- payum/payum-bundle: ^2.3
- php-http/guzzle6-adapter: ^1.1
Requires (Dev)
- doctrine/annotations: ^1.2
- doctrine/common: ^2.4
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- sensio/framework-extra-bundle: ^3.0
- symfony/asset: ^3.3|^4.0
- symfony/browser-kit: ^3.3|^4.0
- symfony/cache: ^3.3|^4.0
- symfony/config: ^3.3|^4.0
- symfony/console: ^3.3|^4.0
- symfony/dom-crawler: ^3.3|^4.0
- symfony/form: ^3.3|^4.0
- symfony/http-kernel: ^3.3|^4.0
- symfony/phpunit-bridge: ^3.3|^4.0
- symfony/property-access: ^3.3|^4.0
- symfony/stopwatch: ^3.3|^4.0
- symfony/symfony: 3.3.*
- symfony/templating: ^3.3|^4.0
- symfony/twig-bundle: ^3.3|^4.0
- symfony/validator: ^3.3|^4.0
README
Highly customizable cart management bundle for Symfony. The archievement of this cart manager is to do something like:
Add this thing to a cart
License
Installation
1 Add bundle to your vendor
composer require ggggino/skuskucart-bundle
2 Register the bundle in app/AppKernel.php
$bundles = array( // ... // Multi step form new Craue\FormFlowBundle\CraueFormFlowBundle(), // Payment bundle new Payum\Bundle\PayumBundle\PayumBundle(), // Cart bundle new GGGGino\SkuskuCartBundle\GGGGinoSkuskuCartBundle(), );
3 Create at least one currency
bin/console ggggino_skusku:currency:create
4 Set default locale and currency
parameters: locale: it currency: EUR
Configuration
Bundle complete configuration
# config.yml ggggino_skuskucart: allow_anonymous_shop: false cart_mode: 'single_page' stepform: cart: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep1FormType label: Step 1 chosePayment: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep2FormType label: Step 2 payment: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep3FormType label: Step 3 templates: cart_layout: 'GGGGinoSkuskuCartBundle::cart_page.html.twig' done_layout: 'xxxBundle:xxx:xxx.html.twig'
Extra configs
# config.yml parameters: locale: it currency: EUR
Add the target entities that replace the interfaces
# config.yml doctrine: orm: resolve_target_entities: GGGGino\SkuskuCartBundle\Model\SkuskuProductInterface: GGGGino\SkuskuCartBundle\Entity\SkuskuProduct GGGGino\SkuskuCartBundle\Model\SkuskuCustomerInterface: GGGGino\SkuskuCartBundle\Entity\SkuskuUser GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyInterface: GGGGino\SkuskuCartBundle\Entity\SkuskuCurrency GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface: GGGGino\SkuskuCartBundle\Entity\SkuskuLanguage
Add the basics routes
# routing.yml skusku: resource: "@GGGGinoSkuskuCartBundle/Controller/" type: annotation
Use resolve_target_entities
to replace the interface entities with the concrete ones
doctrine: orm: resolve_target_entities: GGGGino\SkuskuCartBundle\Model\SkuskuProductInterface: AppBundle\Entity\Product GGGGino\SkuskuCartBundle\Model\SkuskuCustomerInterface: AnotherBundle\Entity\User GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyInterface: My\CustomBundle\Entity\Currency GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface: ExtraBundle\Entity\Language
Every class used must implements the right interface.
-
Currency
use GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyInterface; class Currency implements SkuskuCurrencyInterface { }
-
User
use GGGGino\SkuskuCartBundle\Model\SkuskuCustomerInterface; class User implements SkuskuCustomerInterface { }
-
Product
use GGGGino\SkuskuCartBundle\Model\SkuskuProductInterface; class Product implements SkuskuProductInterface { }
-
Language
use GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface; class Lang implements SkuskuLangInterface { }
If you want an prebuilt entity you can extend their own base class.
- Currency
use GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyBase; class Currency extends SkuskuCurrencyBase { }
Twig functions
Print the cart preview
{{ render_preview_cart() }}
Print the language choice block
{{ render_lang_cart() }}
Print the currency choice block
{{ render_currency_cart() }}
CartManager API
Cart manager
Get the cart manager instance
use GGGGino\SkuskuCartBundle\Service\CartManager; . . . $cartManager = $this->get(CartManager::class);
CartManager::persistCart(SkuskuCart $cart)
Add the cart to EntityManager
use GGGGino\SkuskuCartBundle\Model\SkuskuCart; . . . /** @var SkuskuCart $finalCart */ $finalCart = ... $cartManager->persistCart($finalCart);
CartManager::flushCart(SkuskuCart $cart);
Flush the cart
$cartManager->flushCart($finalCart);
CartManager::addProductToCart(SkuskuProductInterface $product, int $quantity)
Add some product to the cart
$quantity = 20; $cartManager->addProductToCart($product, $quantity);
CartManager::createNewCart(SkuskuCustomerInterface $customer = null)
Create new Cart from a given customer, if the customer is not passed is taken from the session
$cartManager->createNewCart($customer);
CartManager::createNewOrderFromCart(SkuskuCart $cart)
Build a new Order from a given cart. Used for example when the payment gone good
$cartManager->createNewOrderFromCart($cart);
Cart page
/cart
Commands
bin/console ggggino_skusku:cart:clear
Clear all the skuskutables
bin/console ggggino_skusku:currency:create
Create a row of the given entity - DEV
bin/console ggggino_skusku:doctor:db
Check if the installation procedure was successful
Configuration details
You can decide if even the anonymous user can shop
# config.yml ggggino_skuskucart: allow_anonymous_shop: false
Chose between use the default steps and create new ones, remember that for the "cart|chosePayment|payment" you can only override configs
# config.yml ggggino_skuskucart: stepform: cart: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep1FormType label: Step 1 chosePayment: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep2FormType label: Step 2 payment: form_type: GGGGino\SkuskuCartBundle\Form\CartFlowType\CartStep3FormType label: Step 3
If you need more customization in the formstep you can override it. Your CartFlow needs only to inherit
# config.yml ggggino_skuskucart: stepform_class: GGGGino\SkuskuCartBundle\Form\CartFlow
If you need to change the templates
# config.yml ggggino_skuskucart: templates: cart_layout: 'GGGGinoSkuskuCartBundle::cart_page.html.twig' done_layout: 'xxxBundle:xxx:xxx.html.twig'
Events
Templates
TODO
- API for creating cart
- Ordering stepform items
Test taken from: https://github.com/nelmio/NelmioApiDocBundle