You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-21Lines changed: 39 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ For Laravel 5.1~:
19
19
```composer require "darryldecode/cart:~2.0"```
20
20
21
21
For Laravel 5.5 or 5.6~:
22
-
```composer require "darryldecode/cart:~3.0"```
22
+
```composer require "darryldecode/cart:~4.0"```
23
23
24
24
## CONFIGURATION
25
25
@@ -344,19 +344,21 @@ First let's add a condition on a Cart Bases:
344
344
There are also several ways of adding a condition on a cart:
345
345
NOTE:
346
346
347
-
When adding a condition on a cart bases, the 'target' should have value of 'subtotal'.
348
-
And when adding a condition on an item, the 'target' should be 'item'.
347
+
When adding a condition on a cart bases, the 'target' should have value of 'subtotal' or 'total'.
348
+
If the target is "subtotal" then this condition will be applied to subtotal.
349
+
If the target is "total" then this condition will be applied to total.
349
350
The order of operation also during calculation will vary on the order you have added the conditions.
350
351
351
-
Also, when adding conditions, the 'value' field will be the bases of calculation.
352
+
Also, when adding conditions, the 'value' field will be the bases of calculation. You can change this order
353
+
by adding 'order' parameter in CartCondition.
352
354
353
355
```php
354
356
355
357
// add single condition on a cart bases
356
358
$condition = new \Darryldecode\Cart\CartCondition(array(
357
359
'name' => 'VAT 12.5%',
358
360
'type' => 'tax',
359
-
'target' => 'subtotal',
361
+
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
360
362
'value' => '12.5%',
361
363
'attributes' => array( // attributes field is optional
362
364
'description' => 'Value added tax',
@@ -371,23 +373,38 @@ Cart::session($userId)->condition($condition); // for a speicifc user's cart
371
373
$condition1 = new \Darryldecode\Cart\CartCondition(array(
372
374
'name' => 'VAT 12.5%',
373
375
'type' => 'tax',
374
-
'target' => 'subtotal',
376
+
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
375
377
'value' => '12.5%',
376
378
'order' => 2
377
379
));
378
380
$condition2 = new \Darryldecode\Cart\CartCondition(array(
379
381
'name' => 'Express Shipping $15',
380
382
'type' => 'shipping',
381
-
'target' => 'subtotal',
383
+
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
382
384
'value' => '+15',
383
385
'order' => 1
384
386
));
385
387
Cart::condition($condition1);
386
388
Cart::condition($condition2);
387
389
388
-
// The property 'Order' lets you add different conditions through for example a shopping process with multiple
390
+
// Note that after adding conditions that are targeted to be applied on subtotal, the result on getTotal()
391
+
// will also be affected as getTotal() depends in getSubTotal() which is the subtotal.
392
+
393
+
// add condition to only apply on totals, not in subtotal
394
+
$condition = new \Darryldecode\Cart\CartCondition(array(
395
+
'name' => 'Express Shipping $15',
396
+
'type' => 'shipping',
397
+
'target' => 'total', // this condition will be applied to cart's total when getTotal() is called.
398
+
'value' => '+15',
399
+
'order' => 1 // the order of calculation of cart base conditions. The bigger the later to be applied.
400
+
));
401
+
Cart::condition($condition);
402
+
403
+
// The property 'order' lets you control the sequence of conditions when calculated. Also it lets you add different conditions through for example a shopping process with multiple
389
404
// pages and still be able to set an order to apply the conditions. If no order is defined defaults to 0
390
405
406
+
// NOTE!! On current version, 'order' parameter is only applicable for conditions for cart bases. It does not support on per item conditions.
0 commit comments