Exemplo n.º 1
0
 /**
  * Calculates the value of this card against the data in a cart
  *
  * @param \Shop\Models\Carts $cart
  * @return number
  */
 public function cartValue(\Shop\Models\Carts $cart)
 {
     $value = $this->balance();
     // exclude the giftcard total from the following comparison
     $cart_total = $cart->subtotal() - $cart->discountTotal() - $cart->creditTotal() + $cart->taxTotal() + $cart->shippingTotal();
     if ($cart_total < $value) {
         $value = $cart_total;
     }
     if ($value < 0) {
         $value = 0;
     }
     return $value;
 }
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;
 }