kbcart/zf3-kbcart

实用的简单ZF3购物车

0.0.1 2018-06-19 07:27 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:24:28 UTC


README

基于zend frame work 3的简单购物车KbCart

这是一个简单的zf3购物车。根据您网站路由提供的信息,使用其功能。在这个版本中我没有使用hydrator,而是简单地使用数组到数组的转换,没有任何附加的内容。我从Aleksander Cyrkulewski那里获得了基本想法,他使用了hydrator。我使用了zend-config xml文件的创建和删除,并将内容收集到一个数组中,直接从数组中获取数据。在这里,用户可以按照我的方法指定所需的所有子类别,并在她的/他的网站购物车视图中反映出来。不要忘记,您需要使用zend-config和zend-crypt来使用此模块。

Zend Framework 2和3

此模块既可用于zf2,也可用于zf3

安装

使用composer进行安装 composer。在您的composer.json中添加此项目。

"require": {
    "kbcart/zf3-kbcart": "@dev"
}

安装后

配置

  • config/application.config.php中的modules数组下添加模块,插入kbcart
  • 将名为kbcart.global.php的文件复制到config/autoload/
  • 您可以根据应用程序参数修改此文件。

示例

在展示示例之前,以下解释可能会对您有所帮助:假设您有一个商店,每个商品位于一个页面,点击它将顾客带到该商品的详细页面。顾客选择所需数量的商品,所有内容都在路由中反映出来。为了有类别和子类别,这些数据必须作为选项或参数在路由中反映(直接或通过获取面包屑),然后在该表单的路由中固定参数选项。协议必须是这样的:$this->url('routename', [], ['query'=>['category':'category-subcategory-...']]). 在相关动作控制器中:$this->kbcart();

插入

您可以将任何数量的商品添加到购物车中。购物车中的每个条目都将具有唯一的令牌以进行操作。在相关控制器中包含:use Zend\Config\Config; use Zend\Config\Writer\Xml;

在控制器操作中

$kbcart = $this->kbcart();

 $config = new Config([], true);
 GET $category from query as explained above. e.g:
 $category='books-physic-newton';
 $config->$category=[];
 you MUST do exactly according below, the same order and words:
 the values below is obtained by route, remember no money sign like Euro or dollar sign for price, just float numbers.
 $config->$category->itemid="1";
 $config->$category->name="principa";
 $config->$category->price="19.19";
 $config->$category->quantity="1";
 
 $writer = new Xml();
 
 a temporary file will be created, if two or more users apply for the same item at the same time,
 randome functions prevent from being created the same file for different customers.
 
  srand(time());
  $num=rand(1, 1000);
 
 $writer->toFile(__DIR__.'/../kbcart_'.$num.'.xml',$config);
 $kbcart->insert(__DIR__.'/../kbcart_'.$num.'.xml');
 
 The created file shall be deleted automatically after insert into your cart.
 Also you can use var_dump($this->kbcart()->cart) to check the content of basket.

删除

In cart view template page, when you assign the session array to the form(s) route there, token will be assigned 
as a param or query and could be obtained from route.
$token : '4b848870240fd2e976ee59831b34314f7cfbb05b';
$this->kbcart()->remove($token);

更新

In cart view template page, when you assign the session array to the form(s) route there, token will be assigned 
as a param or query and could be obtained from route.
$token : '4b848870240fd2e976ee59831b34314f7cfbb05b';
$this->kbcart()->update($token, $amount);

销毁

完全删除Kb Cart。

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

购物车

查看购物车中的所有内容

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

总计

In each update, insert or delete of an item shall be calculated automatically,
to view it: $kbcart = $this->kbcart()->cart();
echo $kbcart['cartval'];

将购物车传递到视图模板

return new ViewModel(['cart'=>$this->kbcart()->cart()]);
    

KbCart

提供的购物车相当实用,具有itemid,可以从数据库或文件访问到该商品的所有数据,无需通过其他选项(如折扣等)使购物车更复杂。越简单越实用。对于插入:在动作控制器中首先检查购物车及其商品。假设顾客两次选择了相同的商品,如果没有,则应使用插入。

主要功能

开发者

Kian William Nowrouzian - mezmer121@gmail.com