angel / products
本包的最新版本(v1.0.5)没有提供许可信息。
Angel CMS的用于产品的模块。
v1.0.5
2015-07-22 00:27 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.1.*
- stripe/stripe-php: ~1.9
This package is not auto-updated.
Last update: 2024-09-24 01:38:13 UTC
README
这是一个用于Laravel 4 Angel CMS的电子商务模块。
该模块与Stripe直接兼容,但你可以轻松扩展以使用其他支付网关。
安装
将以下要求添加到你的 composer.json 文件中
"require": { ... "angel/products": "1.0.*" },
运行 composer update 安装包。
将以下服务提供者添加到你的 app/config/app.php 文件中的 providers 数组
'Angel\Products\ProductsServiceProvider'
运行以下命令
php artisan migrate --package="angel/products" # Run the migrations php artisan asset:publish # Publish the assets php artisan config:publish angel/products # Publish the config
打开你的 app/config/packages/angel/core/config.php 并将产品和订单路由添加到 menu 数组中
'menu' => array( 'Pages' => 'pages', 'Menus' => 'menus', 'Products' => 'products', // <--- Add this line 'Orders' => 'orders', // <--- Add this line 'Users' => 'users', 'Settings' => 'settings' ),
...并将可链接的菜单模型添加到 linkable_models 数组中
'linkable_models' => array( 'Page' => 'pages', 'Product' => 'products', // <--- Add this line 'ProductCategory' => 'products/categories' // <--- Add this line )
打开你的 app/config/packages/angel/products/config.php 并设置你的Stripe API密钥
'stripe' => array( 'test' => array( 'secret' => 'xxxxxxxxxxxxxx', 'publishable' => 'xxxxxxxxxxxxxx' ), 'live' => array( 'secret' => 'xxxxxxxxxxxxxx', 'publishable' => 'xxxxxxxxxxxxxx' ) )
购物车使用
购物车类 在会话中存储基于所选选项的产品变体。
添加产品
$Product = App::make('Product'); $Cart = App::make('Cart'); // Grab the user's desired product from the database. $product = $Product::with('options')->findOrFail(Input::get('product_id')); // Mark the selected option items by their IDs. $product->markSelectedOptions(Input::get('options')); // Add the product to the cart in the user's desired quantity, saving the unique key for accessing it later. $key = $Cart->add($product, Input::get('quantity'));
添加带自定义选项的产品
$Product = App::make('Product'); $Cart = App::make('Cart'); // Grab the user's desired product from the database. $product = $Product::findOrFail(Input::get('product_id')); $product->addCustomOptions(array( 'Size' => array( 'name' => 'Large', 'price' => 4.50 ), 'Color' => array( 'name' => 'Green', 'price' => -2.50, 'image' => 'assets/images/green-shirt.jpg' ) )); // Add the product to the cart in the user's desired quantity, saving the unique key for accessing it later. $key = $Cart->add($product, Input::get('quantity'));
检索键
如果你需要获取产品的键(例如,从购物车中删除该产品),可以这样做
// Retrieve the key. $key = $Cart->key($product); // Use the key however you wish. $Cart->remove($key);
删除产品
$Cart->remove($key);
调整产品数量
$Cart->quantity($key, 5);
检索产品
$details = $Cart->get($key); // $details then looks like this: array( 'product' => {String, JSON encoded product}, 'price' => {Float, price per unit}, 'qty' => {Int, quantity of units} );
遍历产品
foreach (Session::get('cart') as $key=>$details) { $product = json_decode($details['product']); $price = $details['price']; $qty = $details['qty']; $total = $Cart->totalForKey($key); }
获取总计
// The total for all products in the cart. echo $Cart->total(); // The total for a specific product variation by key. echo $Cart->totalForKey($key); // The total number of items in the cart. (Variations x their quantity) echo $Cart->count();