Example #1
0
 /**
  * Add product to cart.
  *
  * @param App\Models\Product  $product
  * @return Cartalyst\Cart\Collections\ItemCollection
  */
 protected function addToCart($product)
 {
     // Set the global conditions order
     $this->cart->setConditionsOrder(['discount', 'other', 'tax', 'shipping', 'coupon']);
     // Set the items conditions order
     $this->cart->setItemsConditionsOrder(['discount', 'other', 'tax', 'shipping']);
     // Item conditions
     $condition1 = $this->createCondition('VAT (17.5%)', 'tax', 'subtotal', ['value' => '17.50%']);
     $condition2 = $this->createCondition('VAT (23%)', 'tax', 'subtotal', ['value' => '23%']);
     $condition3 = $this->createCondition('Discount (7.5%)', 'discount', 'subtotal', ['value' => '-7.5%']);
     $condition4 = $this->createCondition('Item Based Shipping', 'shipping', 'subtotal', ['value' => '20.00']);
     // Add the item to the cart
     $item = $this->cart->add(['id' => $product->id, 'name' => $product->name, 'price' => $product->price, 'quantity' => 1, 'conditions' => [$condition1, $condition2, $condition3, $condition4]]);
     // Global conditions
     $condition1 = $this->createCondition('Global Tax (12.5%)', 'tax', 'subtotal', ['value' => '12.50%']);
     $condition2 = $this->createCondition('Global discount (5%)', 'tax', 'subtotal', ['value' => '-5%']);
     $condition3 = $this->createCondition('Global Shipping', 'shipping', 'subtotal', ['value' => '20.00%']);
     // Set the global conditions
     $this->cart->condition([$condition1, $condition2, $condition3]);
     return $item;
 }
 /**
  * Add product to wishlist.
  *
  * @param App\Models\Product  $product
  * @return Cartalyst\Cart\Collections\ItemCollection
  */
 protected function addToWishlist($product)
 {
     return $this->wishlist->add(['id' => $product->id, 'name' => $product->name, 'price' => $product->price, 'quantity' => 1]);
 }