A simple shoppingcart implementation for Phalcon.

Overview

Phalcon Shopping Cart

A simple shoppingcart implementation for Phalcon.

Installation

Install the package through Composer.

Run the Composer require command from the Terminal:

composer require sinbadxiii/phalcon-cart

How use

Add in services

$di->set(
      'cart',
      function () use ($di) {
          return new Sinbadxiii\Phalcon\Cart\CartShopping(
              $di->getSession()
          );
      }
  );

or creating with name instance

$di->set(
      'compare',
      function () use ($di) {
          return new Sinbadxiii\Phalcon\Cart\CartShopping(
              $di->getSession(), 'compare'
          );
      }
  );
#add()
$this->cart->add('1', 'Product Name 1', 1, 100.99);

#update()
$rowId = '5d12249fdca4cb0fff77f49bbffc128c';
$this->cart->update($rowId, 10);

#remove()
$rowId = '5d12249fdca4cb0fff77f49bbffc128c';
$this->cart->remove($rowId);

#content()
$this->cart->content();

#destroy()
$this->cart->destroy();

#total() with Tax
$this->cart->total();

#total() without Tax
$this->cart->subtotal();

#count()
$this->cart->count();

#countTotal()
$this->cart->countTotal();

Instances

The packages supports multiple instances of the cart. The way this works is like this:

You can set the current instance of the cart by calling $this->cart->instance('newInstance'). From this moment, the active instance of the cart will be newInstance, so when you add, remove or get the content of the cart, you're work with the newInstance instance of the cart. If you want to switch instances, you just call $this->cart->instance('otherInstance') again, and you're working with the otherInstance again.

So a little example:

$this->cart->instance('shop')->add('100', 'Product #1', 1, 100.00);

// Get the content of the 'shop' cart
$this->cart->content();

$this->cart->instance('wishlist')->add('200', 'Product #2', 1, 20.00);

// Get the content of the 'wishlist' cart
$this->cart->content();

// If you want to get the content of the 'shopping' cart again
$this->cart->instance('shop')->content();

// And the count of the 'wishlist' cart again
$this->cart->instance('wishlist')->count();

N.B. Keep in mind that the cart stays in the last set instance for as long as you don't set a different one during script execution.

N.B.2 The default cart instance is called default, so when you're not using instances, $this->cart->content(); is the same as $this->cart->instance('shop')->content().

You might also like...
Implementation of an API application using the Phalcon Framework

phalcon-api Sample API using Phalcon Implementation of an API application using the Phalcon Framework https://phalcon.io Installation Clone the projec

A PHP implementation of the GraphQL specification based on the JavaScript reference implementation

GraphQL This is a PHP implementation of the GraphQL specification based on the JavaScript reference implementation. Related projects DateTime scalar R

⚡ Micro API using Phalcon Framework

Micro App (Rest API) ⚡ Micro API using Phalcon PHP Framework. PHPDocs I. Requirements A Laptop 😉 Docker (docker-compose*) Makefile (cli) II. Installa

Vagrant configuration for PHP7, Phalcon 3.x and Zephir development.

Phalcon VM 2.0.1 Phalcon VM is an open source Vagrant configuration which contains wide range of tools required in modern web development. Like a Swis

Phalcon 3, PHP7, Docker sample starter application

Phalcon Docker Nginx starter app Docker image based on: Ubuntu 16.04 Phalcon 3 PHP 7 Nginx + PHP FPM Supervisord Dependencies Docker. For installation

 Phalcon Demo Application
Phalcon Demo Application

Phalcon Demo Application We use modified Phalcon INVO Application to demonstrate basics of Codeception testing. We expect to implement as many feature

Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Phalcon official Forum

Phosphorum 3 Phosphorum is an engine for building flexible, clear and fast forums. You can adapt it to your own needs or improve it if you want. Pleas

Phalcon PHP Meta tags Service

About Phalcon meta tags plugin for PhalconPHP. This plugin allows you to easily and flexibly customize the meta tags of your view. If this plugin help

Phalcon Routering for Yaml

Phalcon Router for Yaml Version PHP: 7.0.x, 7.1.x, 7.2.x Phalcon: 3.x Composer { "require": { "ienaga/phalcon-router-for-yaml": "2.*"

Phalcon PHP REST API Package, still in beta, please submit issues or pull requests

PhREST API A Phalcon REST API package, based on Apigees guidelines as found in http://apigee.com/about/content/web-api-design Please see the skeleton

A composer package designed to help you create a JSON:API in Phalcon
A composer package designed to help you create a JSON:API in Phalcon

phalcon-json-api-package A composer package designed to help you create a JSON:API in Phalcon What happens when a PHP developer wants to create an API

Setupify is a Phalcon provisioning and development tool.
Setupify is a Phalcon provisioning and development tool.

Setupify Provisioning Tool WARNING: Setupify is currently in a state of experimentation. Use tag release. Setupify is a collection of bash scripts for

RedisPlugin for Phalcon

RedisPlugin for Phalcon (The correspondence of MySQL sharding.) Composer { "require": { "ienaga/phalcon-redis-plugin": "3.*" } } Versio

Easy Repository pattern for PHP Phalcon framework.

Phalcon Repositories Introduction Phalcon Repositories lets you easily build repositories for your Phalcon models, for both SQL and Mongo drivers. PHP

Phalcon devtools

Yarak yarak - (Falconry) a state of prime fitness in a falcon Laravel inspired Phalcon devtools Database migrations that rollback step-by-step, reset

Incubator adapters/functionality for the Phalcon PHP Framework

Phalcon Incubator This is a repository to publish/share/experiment with new adapters, prototypes or functionality that can potentially be incorporated

PHP Profiler & Developer Toolbar (built for Phalcon)
PHP Profiler & Developer Toolbar (built for Phalcon)

Prophiler - A PHP Profiler & Developer Toolbar built for Phalcon Demo The demo website has been moved to a separate repository: https://github.com/fab

A powerful debug and profilers tool for the Phalcon Framework
A powerful debug and profilers tool for the Phalcon Framework

Phalcon Debugbar Integrates PHP Debug Bar with Phalcon Framework. 中文说明 Features Normal request capturing Ajax request capturing Redirect request chain

Owner
Sergey Mukhin
Sergey Mukhin
A simple shopping cart implementation for Laravel

LaravelShoppingcart This is a fork of Crinsane's LaravelShoppingcart extended with minor features compatible with Laravel 8+. An example integration c

Patrick 453 Jan 2, 2023
PHP implementation of Fowler's Money pattern.

Money PHP library to make working with money safer, easier, and fun! "If I had a dime for every time I've seen someone use FLOAT to store currency, I'

Money PHP 4.2k Jan 2, 2023
Example of Pre-Loader Implementation for Magento 2

Example of preloader Implements optimistic preloader for configurable product data without taking into account simple product status for: Price of con

EcomDev B.V. 10 Dec 12, 2021
Shopping Cart Implementation for Laravel Framework

Shopping Cart Implementation for Laravel Framework

darryl fernandez 1.2k Jan 4, 2023
Simple E-Comerce build use Laravel 5.6 require php version 5.6 or 7.4

Simple E-Comerce build use Laravel 5.6 require php version 5.6 or 7.4

Rangga Darmajati 3 Oct 7, 2021
Benefit PHP Shopping Cart Class (Simple Lightweight)

Benefit-PHP-Shopping-Cart-Class Benefit PHP Shopping Cart Class (Simple Lightweight) Table of Contents Initialization Get All Get Item Get Item Child

Osman Cakmak 8 Sep 6, 2022
Simple Ecommerce Platform on Symfony - E-Learning

Simple Ecommerce Platform on Symfony - E-Learning

Vincent Manuceau 1 May 8, 2022
Build a simple ecommerce website with Laravel.

Simple Ecommerce Build a simple ecommerce website with Laravel. Explore the docs » View Demo · Report Bug · Request Feature Table of Contents Getting

Rif 0 Jul 1, 2022
Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hosted at PackageCloud.

Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hos

The Phalcon PHP Framework 26 Oct 7, 2022
A Phalcon paginator adapter for Phalcon Collections

Phalcon Collection Paginator A Phalcon paginator adapter for Phalcon Collections Why create this? Being familiar with the various Pagination data adap

Angel S. Moreno 2 Oct 7, 2022