Exemplo n.º 1
0
 /**
  * Determines if this coupon is valid for a cart
  *
  * @param \Shop\Models\Carts $cart
  * @throws \Exception
  */
 public function cartValid(\Shop\Models\Carts $cart)
 {
     // Does the cart already have a gift card used?
     if (!empty($cart->giftcards)) {
         throw new \Exception('Only one gift card allowed per cart');
     }
     // Does the cart have a total > 0?
     if ($cart->total() <= (double) 0) {
         throw new \Exception('Cart total must be greater than 0 to use a gift card');
     }
     // Does the card have available balance?
     if ($this->balance() <= (double) 0) {
         throw new \Exception('This gift card does not have an available balance');
     }
     /**
      * if we made it this far, the cart is valid for this card
      */
     $this->__is_validated = true;
     return $this;
 }
Exemplo n.º 2
0
 public function mergeWithCart(\Shop\Models\Carts $cart)
 {
     $cart_array = $cart->cast();
     unset($cart_array['_id']);
     unset($cart_array['type']);
     unset($cart_array['metadata']);
     unset($cart_array['name']);
     $this->bind($cart_array);
     $this->number = $this->createNumber();
     $this->grand_total = $cart->total();
     $this->sub_total = $cart->subtotal();
     $this->tax_total = $cart->taxTotal();
     $this->shipping_total = $cart->shippingTotal();
     $this->discount_total = $cart->discountTotal();
     $this->shipping_discount_total = $cart->shippingDiscountTotal();
     $this->credit_total = $cart->creditTotal();
     $this->giftcard_total = $cart->giftCardTotal();
     $user = (new \Users\Models\Users())->load(array('_id' => $this->user_id));
     $this->customer = $user->cast();
     $this->customer_name = $user->fullName();
     $real_email = $user->email(true);
     if ($real_email != $this->user_email) {
         $this->user_email = $real_email;
     }
     // $order->is_guest = $cart->isGuest(); ? or is that from the checkout object?
     // $order->ip_address = $cart->ipAddress(); ? or is that from the checkout object?
     $this->comments = $cart->{'checkout.order_comments'};
     // Shipping fields
     $this->shipping_required = $cart->shippingRequired();
     if ($shipping_method = $cart->shippingMethod()) {
         $this->shipping_method = $shipping_method->cast();
     }
     $this->shipping_address = $cart->{'checkout.shipping_address'};
     // TODO Payment/Billing fields
     $this->billing_address = $cart->{'checkout.billing_address'};
     $this->payment_required = $cart->paymentRequired();
     return $this;
 }