@@ -204,17 +204,24 @@ $subTotal = Cart::getTotal();
204204## Conditions
205205
206206Laravel Shopping Cart supports cart conditions.
207- Condiitons are very useful in terms of (coupons,discounts,sale,per-item sale and discounts etc.)
207+ Conditions are very useful in terms of (coupons,discounts,sale,per-item sale and discounts etc.)
208208See below carefully on how to use conditions.
209209
210210Conditions can be added on:
211- 1.) Cart
212- 2.) Item
211+
212+ 1.) Whole Cart Value bases
213+
214+ 2.) Per-Item Bases
213215
214216First let's add a condition on a Cart Bases:
215217
216- There are also several ways of adding a condtion on a cart:
217- NOTE: When adding a condition on a cart bases, the 'target' should have value of 'total'.
218+ There are also several ways of adding a condition on a cart:
219+ NOTE:
220+
221+ When adding a condition on a cart bases, the 'target' should have value of 'total'.
222+ The order of operation also during calculation will vary on the order you have added the conditions.
223+
224+ Also, when adding conditions, the 'value' field will be the bases of calculation.
218225
219226``` php
220227
@@ -244,28 +251,23 @@ $condition2 = new CartCondition(array(
244251Cart::condition($condition1);
245252Cart::condition($condition2);
246253
247- // or add multiple conditions one condition instances
248- $condition = new CartCondition(array(
249- array(
250- 'name' => 'COUPON LESS 12.5%',
251- 'type' => 'tax',
252- 'target' => 'total',
253- 'value' => '-12.5%',
254- ),
255- array(
256- 'name' => 'Express Shipping $15',
257- 'type' => 'shipping',
258- 'target' => 'total',
259- 'value' => '+15',
260- )
261- )
262- );
263- Cart::condition($condition);
254+ // or add multiple conditions as array
255+ Cart::condition([$condition1, $condition2]);
256+
257+ // To get all applied conditions on a cart, use below:
258+ $carConditions = Cart::getConditions();
259+ foreach($carConditions as $condition)
260+ {
261+ $condition->getTarget(); // the target of which the condition was applied
262+ $condition->getName(); // the name of the condition
263+ $condition->getType(); // the type
264+ $condition->getValue(); // the value of the condition
265+ }
264266```
265267
266268NOTE: All cart based conditions should be applied before calling ** Cart::getTotal()**
267269
268- Then Finaly you can call ** Cart::getTotal()** to get the Cart Total with the applied conditions.
270+ Then Finally you can call ** Cart::getTotal()** to get the Cart Total with the applied conditions.
269271``` php
270272$cartTotal = Cart::getTotal(); // the total will be calculated based on the conditions you ave provided
271273```
@@ -302,47 +304,12 @@ $product = array(
302304Cart::add($product);
303305
304306// you may also add multiple condition on an item
305- $itemConditions = new CartCondition(array(
306- array(
307- 'name' => 'SALE 5%',
308- 'type' => 'sale',
309- 'target' => 'subtotal',
310- 'value' => '-5%',
311- ),
312- array(
313- 'name' => 'Item Gift Pack 25.00',
314- 'type' => 'promo',
315- 'target' => 'subtotal',
316- 'value' => '-25',
317- ),
318- array(
319- 'name' => 'MISC',
320- 'type' => 'misc',
321- 'target' => 'subtotal',
322- 'value' => '+10',
323- )
324- ));
325-
326- $item = array(
327- 'id' => 456,
328- 'name' => 'Sample Item 1',
329- 'price' => 100,
330- 'quantity' => 1,
331- 'attributes' => array(),
332- 'conditions' => $itemConditions
333- );
334-
335- Cart::add($item);
336-
337- // This is also valid
338307$itemCondition1 = new CartCondition(array(
339- array(
340- 'name' => 'SALE 5%',
341- 'type' => 'sale',
342- 'target' => 'subtotal',
343- 'value' => '-5%',
344- )
345- ));
308+ 'name' => 'SALE 5%',
309+ 'type' => 'sale',
310+ 'target' => 'subtotal',
311+ 'value' => '-5%',
312+ ));
346313$itemCondition2 = new CartCondition(array(
347314 'name' => 'Item Gift Pack 25.00',
348315 'type' => 'promo',
@@ -370,7 +337,7 @@ Cart::add($item);
370337
371338NOTE: All cart per-item conditions should be applied before calling ** Cart::getSubTotal()**
372339
373- Then Finaly you can call ** Cart::getSubTotal()** to get the Cart sub total with the applied conditions.
340+ Then Finally you can call ** Cart::getSubTotal()** to get the Cart sub total with the applied conditions.
374341``` php
375342$cartSubTotal = Cart::getSubTotal(); // the subtotal will be calculated based on the conditions you have provided
376343```
0 commit comments