this package very esay to use operation cart or withList and moved Products between in this package can use three type opreation
1.opreation Cart or WitchList with Product Model
2. opreation Cart or WitchList with Cart Item Collection
3. opreation Cart or Witch List with Index of Collection
in first add this two line in app
composer require heesapp/product-cart
//in provider in config/app.php add this line
Heesapp\Productcart\ProductCartServiceProvider::class,
// in aliases within config/app.php add this line
'Cart'=> Heesapp\Productcart\Facades\Cart::class,
1.this Package can work with to session or Database by Driver attribute value in config file productcart.php 2.the configuration can migration an Cart Table and Cart Items Table by one command and migration the witch List Table
to generate the config file using this command
php artisan ProductCart:Config
Driver config the package use a session Driver or Database Deiver can change between session and database Driver by this commands the defalut Driver is a Database Driver
this command a default driver is database driver can use this command
php artisan ProductCart:Driver
or using command
php artisan ProductCart:Driver --driver=database
if you will use the Database Driver can be generate the migration files by this command
if use only Cart run This Command can migration the Items Table to use with Witch List and Cart
php artisan ProductCart:CartTables
if use WitchList can run this command
php artisan ProductCart:WitchListTable
if you work as session can only run this command
php artisan ProductCart:Driver --driver=session
1.shipping charges: default value is a 10 setting a shipping charges to customer the default value is a 0 and order amount = subtotal-discount for example:
100 product each product 3$
* the subtotal = 100*3$ =300$;
* the discount = 5% of total subtotal
* net total = subtotal - subtotal*(5/100)
* net total price after discount = 300$ - 300$*(5/100) =285
*if net total larger than threshold value of shipping charges and by add the shipping charges
* if defalut value = 10 and net total > shipping charges threshold
*net total + shipping charges = total price before add tax value
- shipping charges threshold :threshold value of shipping value threshold value specify the minimum orders to shipping charges if 100 order the shipping charges value = 0 , more than the shipping charge increment
3.tax precentage :default value is a 3 setting the tax value
example:
* total price = 285$ if add tax = 6%
* the total price = 285 + 285 *(6/100) = 302.1$
4.round off default value = .05
example
* setting round off of total price such as
* 99.95$+.05 =100$
* 99.85$ +.05 = 99.90$
this opreation is :
1.add product to Cart
2.move to WitchList
3.Clear Cart
4.Incremment Item quantity
5.Decremment Item quantity
6.Remove Item From Cart
7.Print Cart
8.Apply Discount
this opreations work with three type method for example:
1.add Cart by Proudct Model
2.add Cart by Cart Items collection from database or session
3.add Cart by Index
in first be add this trait to Product model
.............
use Heesapp\Productcart\Traits\Cartable;
.............
class Product extends Model {
use Cartable ;
.....
}
can add item to cart by id of model addTo cart the arg of method id of model and quantity value the default quantity value = 1 and this method return $cart is to Array with Cart Items
......
$product = Product::where('id', $id)->first();
//with default quantity value
$cart = Product::addToCart($product->id);
//with change quantity value
$cart = Product::addToCart($product->id , 5);
.....
can remove item from cart by id of model return is cart array with items after removed
.....
$product = Product::where('id', $id)->first();
$cart = Product::removeFromCart($product->id);
......
can iecrement item quantity in the cart by id of model return is cart array with items after incremented
.....
$product = Product::where('id', $id)->first();
//with default quantity
$cart = Product::IncrementQuntity($product->id);
//with change quntity (increment quantity by 5)
$cart = Product::IncrementQuntity($product->id , 5);
......
can decrement item quantity in the cart by id of model return is cart array with items after decremented
.....
$product = Product::where('id', $id)->first();
//with default quantity
$cart = Product::DecrementQuntity($product->id);
//with change quntity (decrement quantity by 5)
$cart = Product::DecrementQuntity($product->id ,5);
......
if you user mastik to add the product to cart and in preduce the order detect this product can remove or can move to witchList by model id
.....
$product = Product::where('id', $id)->first();
$cart = Product::moveToWitchList($product->id);
......
can use ProductCart() without use Cartable trait
helper method ProductCart()
1.add item by model only avalibale
2.remove item by model or by database collection or index
3.Increment of quantity by model or by database collection or by index
4.decrement of quntity by by model or by database collection or index
5.move to witchList by by model or by database collection or index
6.Apply discount by presantge or value
7. print cart by two mtehod
....
//with default quantity
$product = Product::where('id', $id)->first();
ProductCart()->addCart($product);
//with quantity value
$product = Product::where('id', $id)->first();
ProductCart()->addCart($product,5);
....
.....
$product = Product::where('id', $id)->first();
ProductCart()->removeMItem($product);
.....
....
//with defalut quantity
$product = Product::where('id', $id)->first();
ProductCart()->IncrementItem($product);
// with quantity value =5
$product = Product::where('id', $id)->first();
ProductCart()->IncrementItem($product,5);
....
....
//with defalut quantity
$product = Product::where('id', $id)->first();
ProductCart()->DecrementItem($product);
// with quantity value =5
$product = Product::where('id', $id)->first();
ProductCart()->DecrementItem($product,5);
....
....
$product = Product::where('id', $id)->first();
ProductCart()->moveMToWitchList($product);
....
.....
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->removeXItem($Item);
.....
....
//with defalut quantity
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->IncremenXtItem($Item);
// with quantity value =5
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->IncremenXtItem($Item,5);
....
....
//with defalut quantity
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->DecremenXtItem($Item);
// with quantity value =5
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->DecremenXtItem($Item,5);
....
....
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->moveXToWitchList($Item);
....
.....
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
ProductCart()->removeXItem($Item);
.....
....
// increment first item with defalut quantity
$cartItems = ProductCart()->toArray(true)['CartItems'];
foreach ($cartItems as $key=>$items){
return ProductCart()->IncrementQuntity($key);
}
//increment first with quantity value =5
$cartItems = ProductCart()->toArray(true)['CartItems'];
foreach ($cartItems as $key=>$items){
return ProductCart()->IncrementQuntity($key , 5);
}
....
....
//with defalut quantity
$cartItems = ProductCart()->toArray(true)['CartItems'];
foreach ($cartItems as $key=>$items){
return ProductCart()->DecrementQuntity($key);
}
// with quantity value =5
$cartItems = ProductCart()->toArray(true)['CartItems'];
foreach ($cartItems as $key=>$items){
return ProductCart()->DecrementQuntity($key,5);
}
....
....
$cartItems = ProductCart()->toArray(true)['CartItems'];
foreach ($cartItems as $key=>$items){
return ProductCart()->moveToWitchList($key);
}
....
1.Apply discount by presantage
//discount = subtotal * discount_percentage /100
....
ProductCart()->ApplyDiscount(30); //30 %
....
2.Apply discount by price
php .... ProductCart()->ApplyDiscountValue(200); //200$ ....
print the total price and tax value and shipping charges and net total and tax value
ProductCart()->PrintCartData();
or
ProductCart()->data();
or
ProductCart()->toArray(); // with not print Itemes
ProductCart()->toArray(true); with print Items //
out put
with discount value
{"subtotal":"572.97","discount":"30.00","discout_percentage":0,"coupon_id":null,"shipping_charges":0,"net_total":0,"tax":"16.29",
"total":"559.26","round_off":0,"payable":"559.30"}
with discount presantage
{"subtotal":"954.95","discount":"286.49","discout_percentage":0,"coupon_id":null,"shipping_charges":0,"net_total":0,"tax":"20.05",
"total":"688.51","round_off":0,"payable":"688.60"}
ProductCart()->clearCart();
witch List the same cart with simple different the witch list work with this operation.
1.add product to Witch List
2.move to Cart by model or database collection or index
3.Clear witchList
6.Remove Item From Witch List by model or database collection or index
7.print items
can use this code
....
use Heesapp\Productcart\Traits\WitchListable;
....
class Product extends Model {
use WitchListable;
....
}
....
$product = Product::where('id', $id)->first();
$witchList = Product::addToWithList($product->id);
....
....
$product = Product::where('id', $id)->first();
$witchList = Product::removeFromWitchList($product->id);
....
....
$product = Product::where('id', $id)->first();
$witchList = Product::moveToCart($product->id);
....
use Helper method
ProductWitchList()
....
$product = Product::where('id', $id)->first();
ProductWitchList()->addWhitcList($product);
...
.....
$product = Product::where('id', $id)->first();
$witchList = ProductWitchList()->removeMWItem($product);
.....
....
$product = Product::where('id', $id)->first();
$witchList = ProductWitchList()->moveMToCart($product);
....
.....
$Item = DB::table('items_cart')->where('model_id', $product->id)->first();
$witchList = ProductWitchList()->removeXWItem($Item);
....
....
$cart_item = DB::table('items_cart')->where('id' , $id)->first();
$witchList = ProductWitchList()->moveXToCart($product);
....
....
$witchListItems = ProductWitchList()->data()['WitchListItems'];
foreach ($witchListItems as $key=>$item){
ProductWitchList()->removeWItem($key);
}
....
....
$witchListItems = ProductWitchList()->data()['WitchListItems'];
foreach ($witchListItems as $key=>$item){
ProductWitchList()->moveToCart($key);
}
....
ProductWitchList()->data();
or
ProductWitchList()->toArray();
out put
print = {"WitchListItems":[{"model_type":"App\\Product","model_id":4,"name":"Bl.dfg","price":"190.99","image":null,"quantity":"1.00","id":39},{"model_type":"App\\Product","model_id":3,"name":"sdfcdhf","price":"189.99","image":null,"quantity":"1.00","id":40},{"model_type":"App\\Product","model_id":2,"name":"dsfg","price":"1300.00","image":null,"quantity":"1.00","id":41},{"model_type":"App\\Product","model_id":1,"name":"Al.kjsa","price":"200.25","image":null,"quantity":"1.00","id":42}]}