nhanchaukp/codeigniter4-cart-library

CodeIgniter 3 购物车模块的基本移植版本,适用于 CodeIgniter 4。

1.0.0 2022-09-12 03:33 UTC

This package is auto-updated.

Last update: 2024-09-12 10:59:05 UTC


README

这是一个可由 composer 安装的 CodeIgniter 4 模块,几乎是 Codeigniter 3 购物车库类的直接移植。当然,它已经被适度更新,并与框架的新版本保持一致。

这意味着它不仅仅是一个你可以在项目中使用的 ,这个库已经更新了命名空间,重构以符合 CodeIgniter 风格指南,并且还构建了使用 CodeIgniter 4 的服务容器,以便在应用程序中共享购物车实例。

更详细的文档可以在 这里 找到。请注意,文档是为 CodeIgniter 3 库编写的,但库的基本原理和工作方式仍然是相同的。最显著的变化是如何使用它(请参阅下文),以及为了返回购物车中的总商品数量,你现在需要调用 $cart->totalItems() 而不是 $this->cart->total_items()

请注意,此包没有测试,因为它只是从现有的 Codeigniter 库移植过来的,并且工作方式相同。

安装

  • 使用 composer 安装 composer require nhanchaukp/codeigniter4-cart-library
  • app/Config/Autoload.php 中的 $psr4 数组中添加它
$psr4 = [
   'CodeIgniterCart' => ROOTPATH . 'vendor/nhanchaukp/codeigniter4-cart-library/src'

   // OTHER PSR4 ENTRIES
];

用法

// Call the cart service
$cart = \Config\Services::cart();

// Insert an array of values
$cart->insert(array(
   'id'      => 'sku_1234ABCD',
   'qty'     => 1,
   'price'   => '19.56',
   'name'    => 'T-Shirt',
   'options' => array('Size' => 'L', 'Color' => 'Red')
));

// Update an array of values
$cart->update(array(
   'rowid'   => '4166b0e7fc8446e81e16883e9a812db8',
   'id'      => 'sku_1234ABCD',
   'qty'     => 3,
   'price'   => '24.89',
   'name'    => 'T-Shirt',
   'options' => array('Size' => 'L', 'Color' => 'Red')
));

// Get the total items. Formerly known as total_items()
$cart->totalItems();

// Find item
$cart->find($key, $value);
Ex: $cart->find('id', 'sku_1234ABCD');

// Format Vietnamese dong
$cart->formatVnd($number);

// Remove an item using its `rowid`
$cart->remove('4166b0e7fc8446e81e16883e9a812db8');
  
// Clear the shopping cart
$cart->destroy();

// Get the cart contents as an array
$cart->contents();

许可协议

MIT 许可协议

版权所有 (c) 2021 Jason Napolitano

特此授予任何获得此软件及其相关文档副本(“软件”)的个人免费使用该软件的权利,不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,以及允许获得软件的人以本协议规定的条件使用该软件的权利。

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵犯性的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任是根据合同、侵权或其他方式产生的,无论是在软件中、使用软件还是与软件或软件的使用或其他方式有关。