コード例 #1
0
 /**
  * add to basket
  *
  * @param int basket_id
  * @param int product_variety_id
  * @param int quantity
  * @param array other_data
  * @return bool
  * @access public
  */
 function addToBasket($basket_id, $product_variety_id, $quantity = 1, $other_data = array(), $price_id = false)
 {
     // get product info
     require_once 'models/ecommerce/ecommerce_product.php';
     $Product = new ecommerce_product();
     $product_data = $Product->getProductDetailByVarietyId($product_variety_id);
     if (!is_numeric($price_id)) {
         $price_id = $product_data['variety']['price']['id'];
     }
     $product_type_id = $product_data['variety']['product_type_id'];
     // limit to delivery zone (if delivery address is set already)
     if (!empty($product_data['variety']['limit_to_delivery_zones']) && is_numeric($_SESSION['client']['customer']['delivery_address_id'])) {
         $zones = explode(",", $product_data['variety']['limit_to_delivery_zones']);
         if (is_array($zones)) {
             require_once 'models/ecommerce/ecommerce_delivery_carrier_zone.php';
             $DeliveryZone = new ecommerce_delivery_carrier_zone();
             $delivery_zone_id = $DeliveryZone->getZoneIdByAddress($_SESSION['client']['customer']['delivery_address_id']);
             if (!in_array($delivery_zone_id, $zones)) {
                 msg("Sorry, we cannot deliver {$product_data['name']} to your country. Please see the product page for delivery options and/or change your delivery address in order to proceed.", 'error');
                 return false;
             }
         }
     }
     // get detail for current basket
     $basket = $this->getFullDetail($basket_id);
     foreach ($basket['items'] as $item) {
         //if the same variety_id, price_id and other_data, than do an update instead
         if ($item['product_variety_id'] == $product_variety_id && $item['price_id'] == $price_id && $item['other_data'] == $other_data) {
             if ($this->updateBasketContent($basket_id, $item['id'], $item['quantity'] + $quantity)) {
                 msg("ecommerce_basket.addToBasket: Item in basket has been updated", 'ok', 2);
                 return true;
             } else {
                 msg("Current item {$item['id']} was found in basket {$basket_id}, but cannot update.", 'error', 1);
                 return false;
             }
         }
     }
     /**
      * or insert as a new item
      */
     $basket_content_data = array('basket_id' => $basket_id, 'product_variety_id' => $product_variety_id, 'quantity' => $quantity, 'price_id' => $price_id, 'other_data' => $other_data, 'product_type_id' => $product_type_id);
     if ($this->insertItemIntoBasketContent($basket_content_data)) {
         return true;
     } else {
         return false;
     }
 }
コード例 #2
0
 /**
  * isAvailableItem
  */
 public function isAvailableItem($data)
 {
     //get product detail
     require_once 'models/ecommerce/ecommerce_product.php';
     $EcommerceProduct = new ecommerce_product();
     $product_detail = $EcommerceProduct->getProductDetailByVarietyId($data['product_variety_id'], $data['price_id']);
     if (!$this->conf['allow_out_of_stock_item']) {
         //check stock is available
         if ($product_detail['variety']['stock'] < $data['quantity']) {
             msg("{$product_detail['variety']['sku']} is out of stock.", 'error');
             return false;
         }
     }
     if (!$this->conf['allow_unpublished_product_variety_item']) {
         //check product variety is published
         if ($product_detail['variety']['publish'] == 0) {
             msg("{$product_detail['variety']['sku']} is not available.", 'error');
             return false;
         }
     }
     if (!$this->conf['allow_unpublished_product_item']) {
         //check product is published
         if ($product_detail['publish'] == 0) {
             msg("Product ID {$product_detail['id']} is not available.", 'error');
             return false;
         }
     }
     return true;
 }