Пример #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
 /**
  * check if all items in the basket can be delivered
  * requires basket full detail
  */
 public function checkDeliveryRestrictions(&$basket, $country_id)
 {
     if (!is_numeric($country_id) || $country_id == 0) {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_delivery_carrier_zone.php';
     $DeliveryZone = new ecommerce_delivery_carrier_zone();
     $delivery_zone_id = $DeliveryZone->getZoneIdByCountry($country_id);
     $products = array();
     foreach ($basket['items'] as &$item) {
         $zones = $item['product']['variety']['limit_to_delivery_zones'];
         if (!empty($zones)) {
             $zones = explode(",", $zones);
             if (is_array($zones)) {
                 if (!in_array($delivery_zone_id, $zones)) {
                     $products[] = $item['product']['name'];
                 }
             }
         }
     }
     if (count($products) > 0) {
         if (!Zend_Registry::isRegistered('ecommerce_delivery:not_deliverable_products_message')) {
             msg("Sorry, we're not able to deliver the following products to your country: " . implode(" ,", $products), 'error');
             Zend_Registry::set('ecommerce_delivery:not_deliverable_products_message', true);
         }
         return false;
     }
     return true;
 }