unodepiera / phalcon_cart
该软件包最新版本(dev-master)没有提供许可证信息。
一个允许多个实例使用PHP Phalcon工作的购物车
dev-master
2014-04-21 09:02 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-24 07:27:15 UTC
README
Phalcon购物车提供完整的购物车系统,允许您创建多个实例,以独立管理我们需要的所有区域。
如果处理购物车时出现问题,类将日志存储到app/logs/shoppingCart.log中,以获取更多信息。
购物车与Phalcon会话一起工作,如果您愿意,可以使用会话适配器来管理数据库中的购物车,更多信息。
使用Composer安装
创建一个新的文件composer.json,打开并添加以下代码
```json { "require": { "unodepiera/phalcon_cart": "dev-master" }, "minimum-stability": "dev" } ```使用composer update更新您的包或使用composer install进行安装。
现在打开app/config/loader.php并替换代码。
```php$loader = new \Phalcon\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(
array(
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->libraryDir
)
);
//register the new class ShoppingCart
$loader->registerClasses(
array(
"ShoppingCart" => "../vendor/unodepiera/phalcon_cart/ShoppingCart.php",
)
);
$loader->register();
<h1>Installation without Composer</h1>
<p>
Download file ShoppingCart.php and create a new directory library in app dir.
Save file into library dir and open app/config/loader.php, now update this file.
</p>
```php
$loader = new \Phalcon\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(
array(
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->libraryDir//register dir library dir
)
);
$loader->register();
Phalcon Cart示例使用
首先创建一个新的实例
```php $this->cart = new ShoppingCart("myShop"); ```插入简单产品
```php $product = array( "id" => 3, "name" => "Pasta de dientes", "price" => 1.80, "qty" => 2, "description" => "Pasta de dientes......" );if($this->cart->add($product) != false)
{
echo "<pre>";
var_dump($this->cart->getContent());
}
<h2>Insert multiple products</h2>
```php
$products = array(
array(
"id" => 1,
"name" => "Almendras",
"price" => 2.5,
"qty" => 8,
"description" => "Almendras saladas"
),
array(
"id" => 2,
"name" => "Galletas pou",
"price" => 2.7,
"qty" => 5,
"description" => "Galletas del amigo pou"
),
array(
"id" => 3,
"name" => "Pasta de dientes",
"price" => 1.80,
"qty" => 8,
"description" => "Pasta de dientes......"
)
);
if($this->cart->addMulti($products) != false)
{
echo "<pre>";
var_dump($this->cart->getContent());
}
更新一个产品
```php $product = array( "id" => 3, "name" => "Pasta de dientes", "price" => 1.80, "qty" => 12, "description" => "Pasta de dientes......" );if($this->cart->update($product) != false)
{
echo "<pre>";
var_dump($this->cart->getContent());
}
<h2>Update multiple products</h2>
```php
$products = array(
array(
"id" => 1,
"name" => "Almendras",
"price" => 2.5,
"qty" => 1,
"description" => "Almendras saladas"
),
array(
"id" => 2,
"name" => "Galletas pou",
"price" => 2.7,
"qty" => 1,
"description" => "Galletas del amigo pou"
),
array(
"id" => 3,
"name" => "Pasta de dientes",
"price" => 1.80,
"qty" => 1,
"description" => "Pasta de dientes......"
)
);
if($this->cart->updateMulti($products) != false)
{
echo "<pre>";
var_dump($this->cart->getContent());
}
检查并打印选项
检查产品是否有选项并打印,需要其rowId
```php if($this->cart->hasOptions("0e043c0cd48de80fa4f6ed23a15d6d10") != false) { echo ""; var_dump($this->cart->getOptions("0e043c0cd48de80fa4f6ed23a15d6d10")); } ```Get total price cart
```php echo $this->cart->getTotal(); ```Get total items cart
```php echo $this->cart->getTotalItems(); ```Remove a product
You just need to pass a rowid that there
```php if($this->cart->removeProduct("0e043c0cd48de80fa4f6ed23a15d6d10") != false) { echo ""; var_dump($this->cart->getContent()); } ```Remove a cart
You just need that there
```php if($this->cart->destroy() != false) { echo ""; var_dump($this->cart->getContent()); } ```Get cart content
```php var_dump($this->cart->getContent()); ```Visit me