Version 1.0
This model allows you to manage a shopping cart for e-commerce in an easy, simple and fast.
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"
}
Configuration:
- Add the module of
config/application.config.php
under the arraymodules
, insertZendCart
- Create a file named
zendcart.global.php
underconfig/autoload/
. - Add the following lines to the file you just created:
<?php
return array(
'zendcart' => array(
'vat' => 21
),
);
$product = array(
'id' => 'cod_123abc',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'M', 'Color' => 'Black')
);
$this->ZendCart()->insert($product);
$product = array(
'token' => '4b848870240fd2e976ee59831b34314f7cfbb05b',
'qty' => 2
);
$this->ZendCart()->update($product);
$product = array(
'token' => '4b848870240fd2e976ee59831b34314f7cfbb05b',
);
$this->ZendCart()->remove($product);
$this->ZendCart()->destroy();
$this->ZendCart()->cart();
$this->ZendCart()->total();
$this->ZendCart()->total_items();
$this->ZendCart()->item_options('4b848870240fd2e976ee59831b34314f7cfbb05b');
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 | 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 Vat | Set your vat in zendcart.global.php |
- Concetto Vecchio - info@cvsolutions.it