Coder Social home page Coder Social logo

zendcart's Introduction

Total Downloads ZendCart

Version 1.0

This model allows you to manage a shopping cart for e-commerce in an easy, simple and fast.

Installation

For the installation uses composer composer.

php composer.phar require  zendcart/zendcart:dev-master

Add this project in your composer.json:

"require": {
    "zendcart/zendcart": "dev-master"
}

Post Installation

Configuration:

  • Add the module of config/application.config.php under the array modules, insert ZendCart
  • Create a file named zendcart.global.php under config/autoload/.
  • Add the following lines to the file you just created:
<?php
return array(
    'zendcart' => array(
        'vat'  => 21
    ),
);

Example

Insert

$product = array(
    'id'      => 'cod_123abc',
    'qty'     => 1,
    'price'   => 39.95,
    'name'    => 'T-Shirt',
    'options' => array('Size' => 'M', 'Color' => 'Black')
);
$this->ZendCart()->insert($product);

Update

$product = array(
    'token' => '4b848870240fd2e976ee59831b34314f7cfbb05b',
    'qty'   => 2
);
$this->ZendCart()->update($product);

Remove

$product = array(
    'token' => '4b848870240fd2e976ee59831b34314f7cfbb05b',
);
$this->ZendCart()->remove($product);

Destroy

$this->ZendCart()->destroy();

Cart

$this->ZendCart()->cart();

Total

$this->ZendCart()->total();

Total Items

$this->ZendCart()->total_items();

Items Options

$this->ZendCart()->item_options('4b848870240fd2e976ee59831b34314f7cfbb05b');

Example in view

Controller

return new ViewModel(array(
    'items' => $this->ZendCart()->cart(),
    'total_items' => $this->ZendCart()->total_items(),
    'total' => $this->ZendCart()->total(),
));

View

<?php if($total_items > 0): ?>
<h3>Products in cart (<?php echo $total_items; ?>):</h3>
<table style="width: 900px;" border="1">
<tr>
  <th>Qty</th>
  <th>Name</th>
  <th>Item Price</th>
  <th>Sub-Total</th>
</tr>
<?php foreach($items as $key):?>
<tr>
    <td style="text-align: center;"><?php echo $key['qty']; ?></td>
	<td style="text-align: center;">
	<?php echo $key['name']; ?>
		<?php if($key['options'] != 0):?>
			Options:
			<?php foreach($key['options'] as $options => $value):?>
				<?php echo $options.' '.$value;?>
			<?php endforeach;?>
		<?php endif;?>
	</td>
	<td style="text-align: center;"><?php echo $key['price']; ?></td>
	<td style="text-align: center;"><?php echo $key['sub_total']; ?></td>
</tr>
<?php endforeach;?>
<tr>
  <td colspan="2"></td>
  <td style="text-align: center;"><strong>Sub Total</strong></td>
  <td style="text-align: center;"> <?php echo $total['sub-total'];?></td>
</tr>
<tr>
  <td colspan="2"></td>
  <td style="text-align: center;"><strong>Vat</strong></td>
  <td style="text-align: center;"> <?php echo $total['vat'];?></td>
</tr>
<tr>
  <td colspan="2"></td>
  <td style="text-align: center;"><strong>Total</strong></td>
  <td style="text-align: center;"> <?php echo $total['total'];?></td>
</tr>

<?php else: ?>
<h4>The Shopping Cart Empty</h4>
<?php endif;?>

Function Reference

Function Description
$this->ZendCart()->insert();Add a product to cart.
$this->ZendCart()->update();Update the quantity of a product.
$this->ZendCart()->remove();Delete the item from the cart.
$this->ZendCart()->destroy();Delete all items from the cart.
$this->ZendCart()->cart();Extracts all items from the cart.
$this->ZendCart()->total();Counts the total number of items in cart
$this->ZendCart()->total_items();Counts the total number of items in cart
$this->ZendCart()->item_options();Returns the an array of options, for a particular product token.
Config VatSet your vat in zendcart.global.php

Contributors

zendcart's People

Contributors

cvsolutions avatar stefanorg avatar vikey89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

zendcart's Issues

CartEvent

Fatal error: Uncaught Error: Class 'Zendcart\Event\CartEvent' not found in /var/www/html/cartpulse/vendor/zendcart/zendcart/src/Zendcart/Controller/Plugin/ZendCart.php:261 Stack trace: #0 /var/www/html/cartpulse/module/Application/src/Application/Controllers/CartController.php(38): ZendCart\Controller\Plugin\ZendCart->insert(Array) #1 /var/www/html/cartpulse/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): Application\Controllers\CartController->indexAction() #2 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) #3 /var/www/html/cartpulse/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #4 /var/www/html/cartpulse/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #5 /var/www/html/cartpulse/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php( in /var/www/html/cartpulse/vendor/zendcart/zendcart/src/Zendcart/Controller/Plugin/ZendCart.php on line 261

Invalid factory

Dopo aver creato una ZendSkeletonApplication pulita, ho aggiunto tramite composer il modulo ZendCart, provando ad utilizzarlo nel controller ricevo il seguente errore:

"While attempting to create zendcart(alias: ZendCart) an invalid factory was registered for this instance type."

lo stack trace:
#0 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(597): Zend\ServiceManager\AbstractPluginManager->createFromFactory('zendcart', 'ZendCart')
#1 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(556): Zend\ServiceManager\ServiceManager->doCreate('ZendCart', 'zendcart')
#2 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(480): Zend\ServiceManager\ServiceManager->create(Array)
#3 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('ZendCart', true)
#4 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/PluginManager.php(82): Zend\ServiceManager\AbstractPluginManager->get('ZendCart', NULL, true)
#5 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(285): Zend\Mvc\Controller\PluginManager->get('ZendCart', NULL)
#6 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(300): Zend\Mvc\Controller\AbstractController->plugin('ZendCart')
#7 /home/NO/stefano.corallo/lavoro/example/sandbox/module/Application/src/Application/Controller/IndexController.php(19): Zend\Mvc\Controller\AbstractController->__call('ZendCart', Array)
#8 /home/NO/stefano.corallo/lavoro/example/sandbox/module/Application/src/Application/Controller/IndexController.php(19): Application\Controller\IndexController->ZendCart()
#9 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Application\Controller\IndexController->indexAction()
#10 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#11 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#12 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#15 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#16 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#17 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#18 /home/NO/stefano.corallo/lavoro/example/sandbox/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#19 /home/NO/stefano.corallo/lavoro/example/sandbox/public/index.php(12): Zend\Mvc\Application->run()
#20 {main}

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.