定制 danujafernando/cart 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danujafernando/cart

Composer 安装命令:

composer require danujafernando/cart

包简介

This is the cart package

README 文档

README

Issues Stars License Total Downloads

A simple laravel shopping cart package

INSTALLATION

Install the package through Composer.

composer require danujafernando/cart

CONFIGURATION

1.Publish config file

php artisan vendor:publish --tag='cart-config'

2.Migrate tables

php artisan migrate

Usage Example

1.Add items to cart

    $product_id = 2;
    $user_id = 1;
    // If user_id is null or zero then it takes session value Session::get('_token');
    // it will be help for user add to cart items before he log in
    $quantity = 3;
    $unit_price = 15.00;
    $attributes = [
        [
            'name' => 'Color',
            'value' => 'Red',
            'price' => '2.00'
        ]
    ]; 
    Cart::add($product_id, $user_id, $quantity, $unit_price, $attributes);

2.Check your attribute array is validate or not

    $attributes = [
        [
            'name' => 'Color',
            'value' => 'Blue',
            'price' => '3.00'
        ],
        [
            'name' => 'Size',
            'value' => 'XL',
            'price' => '5.00'
        ]
    ];
    Cart::validateAttribute($attributes);

    // return value is true.

    $attributes = [
        [
            'name' => 'Color',
            'price' => '3.00'
        ],
        [
            'name' => 'Size',
            'value' => 'XL',
            'price' => '5.00'
        ]
    ];
    Cart::validateAttribute($attributes);

    // return value is false because the value is missing from first attribute.

IMPORTANT NOTE!

By default attribute array need name, value and price. if you want to change it your can do it using config/cart.php file

'product_attributes_keys' => [ 'name', 'value', 'price']

3.Cart items assign to user after logged in

     // before user log in, Session::get('_token') value store another name
     /*
     *  $previous_session_id = Session::get('_token');
     *  Session::put('previous_session_id', $previous_session_id);
     *  This should be run showLoginForm() in your Logincontroller
     */

    // After user logged in 
    /*
    *  $previous_session_id = Session::get('previous_session_id');
    *  This should be run authenticated() in your Logincontroller
    */
    Cart::assignCartToLoggedUser($user_id, $previous_session_id);

4.Retrieve cart items

    $user_id = 3;
    $carts = Cart::getCart($user_id);

5.Update cart item quantity

    $cart_id = 3;
    $quantity = 2;
    Cart::updateCartQuantity($cart_id, $quantity);

6.Update cart item price

    $cart_id = 3;
    $unit_price = 29.99;
    Cart::updateCartUnitPrice($cart_id, $unit_price);

7.Update cart item attributes

    //you have to pass full attributes array 
    Cart::updateCartAttribute($cart_id, $attributes);

8.Delete full cart items

    $user_id = 2;
    // this function will be delete all items by user_id
    Cart::deleteCart($user_id);

9.Delete a cart item

    $cart_id = 30;
    Cart::removeCartItem($user_id);

10.Get cart total.

    $user_id = 2;
    get_subtotal($user_id);

License

The Laravel Shopping Cart is open-sourced software licensed under the MIT license

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固