示例#1
0
 public function setQuantity($qty)
 {
     if (is_numeric($qty) && $qty >= 0) {
         $qty = ceil($qty);
         $product = new Cart66Product($this->_productId);
         if ($product->isSubscription() || $product->isMembershipProduct()) {
             // Subscriptions may only have a quantity of 1
             $qty = 1;
         } elseif ($product->is_user_price == 1) {
             $qty = 1;
         } else {
             if ($product->maxQuantity > 0) {
                 // Only limit quantity when max is set to a value greater than zero
                 if ($product->maxQuantity < $qty) {
                     $qty = $product->maxQuantity;
                 }
             }
             if ($product->minQuantity > 0) {
                 // Only limit quantity when min is set to a value greater than zero
                 if ($product->minQuantity > $qty) {
                     $qty = $product->minQuantity;
                 }
             }
             if ($product->gravity_form_id > 0) {
                 // Set quantity to zero because this is a gravity forms product with no entries
                 if (count($this->_formEntryIds) == 0) {
                     $qty = 0;
                 } else {
                     if ($product->gravity_form_qty_id > 0) {
                         // update gravity form entry for quanity to keep cart and gform in sync
                         $gr = new Cart66GravityReader();
                         $entryId = $this->_formEntryIds[0];
                         $qtyFieldId = $product->gravity_form_qty_id;
                         $gr->updateQuantity($entryId, $qtyFieldId, $qty);
                     }
                 }
             }
         }
         $this->_quantity = $qty;
     }
 }