Ejemplo n.º 1
0
 /**
  * Perform manufacturer removal
  */
 private function deleteManufacturer_Commit()
 {
     $id = fix_id($_REQUEST['id']);
     $manager = ShopManufacturerManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     $manager->deleteData(array('id' => $id));
     $item_manager->updateData(array('manufacturer' => 0), array('manufacturer' => $id));
     $template = new TemplateHandler('message.xml', $this->path . 'templates/');
     $template->setMappedModule($this->name);
     $params = array('message' => $this->_parent->getLanguageConstant("message_manufacturer_deleted"), 'button' => $this->_parent->getLanguageConstant("close"), 'action' => window_Close('shop_manufacturer_delete') . ";" . window_ReloadContent('shop_manufacturers'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
Ejemplo n.º 2
0
 /**
  * Show page for printing all attached cards with selected text.
  */
 private function print_card()
 {
     $id = fix_id($_REQUEST['transaction']);
     $manager = ShopTransactionsManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     $transaction_item_manager = ShopTransactionItemsManager::getInstance();
     // get transaction with specified id
     $transaction = $manager->getSingleItem(array('id'), array('id' => $id));
     // ensure transaction is a valid one
     if (!is_object($transaction)) {
         return;
     }
     // get items associated with transaction
     $transaction_items = $transaction_item_manager->getItems(array('item', 'description'), array('transaction' => $transaction->id));
     if (count($transaction_items) == 0) {
         return;
     }
     $id_list = array();
     $description_list = array();
     foreach ($transaction_items as $item) {
         $id_list[] = $item->item;
         $description_list[$item->item] = $item->description;
     }
     // get unique id and gallery
     $shop_items = $item_manager->getItems(array('id', 'uid', 'gallery'), array('id' => $id_list));
     if (count($shop_items) == 0) {
         return;
     }
     // prepare final list and only include items that are actually known cards
     $items = array();
     foreach ($shop_items as $item) {
         if (!array_key_exists($item->uid, $this->text_position)) {
             continue;
         }
         $position = $this->text_position[$item->uid];
         $description = unserialize($description_list[$item->id]);
         $data = array('text' => $description['text'], 'top' => $position[0] . '%', 'left' => $position[1] . '%', 'bottom' => $position[2] . '%', 'right' => $position[3] . '%', 'image' => gallery::getGroupImageById($item->gallery));
         $items[] = $data;
     }
     // prepare template
     $template = new TemplateHandler('print_card.xml', $this->path . 'templates/');
     if (count($items) > 0) {
         foreach ($items as $item) {
             $template->setLocalParams($item);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Generate unique item Id 13 characters long
  *
  * @return string
  */
 private function generateUID()
 {
     $manager = ShopItemManager::getInstance();
     // generate Id
     $uid = uniqid();
     // check if it already exists in database
     $count = $manager->sqlResult("SELECT count(*) FROM `shop_items` WHERE `uid`='{$uid}'");
     if ($count > 0) {
         // given how high entropy is we will probably
         // never end up calling function again
         $uid = $self->generateUID();
     }
     return $uid;
 }
 /**
  * Handle drawing list of delivery methods
  * @param array $tag_params
  * @param array $children
  */
 public function tag_DeliveryMethodsList($tag_params, $children)
 {
     $manager = ShopDeliveryMethodsManager::getInstance();
     $conditions = array();
     $item_id = -1;
     $selected = -1;
     if (isset($tag_params['item'])) {
         $item_id = fix_id($tag_params['item']);
     }
     if (isset($tag_params['selected'])) {
         $selected = fix_id($tag_params['selected']);
     }
     // delivery method list needs to be filtered by the items in shooping cart
     if (isset($tag_params['shopping_cart']) && $tag_params['shopping_cart'] == 1) {
         $relations_manager = ShopDeliveryItemRelationsManager::getInstance();
         $prices_manager = ShopDeliveryMethodPricesManager::getInstance();
         $items_manager = ShopItemManager::getInstance();
         $cart = isset($_SESSION['shopping_cart']) ? $_SESSION['shopping_cart'] : array();
         $uid_list = array_keys($cart);
         if (count($uid_list) == 0) {
             return;
         }
         // shopping cart contains only UIDs, we need IDs
         $id_list = array();
         $items = $items_manager->getItems(array('id'), array('uid' => $uid_list));
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $id_list[] = $item->id;
             }
         }
         // get item relations to delivery methods
         $relations = $relations_manager->getItems($relations_manager->getFieldNames(), array('item' => $id_list));
         $price_list = array();
         $price_count = array();
         if (count($relations) > 0) {
             foreach ($relations as $relation) {
                 $price_list[] = $relation->price;
                 if (!array_key_exists($relation->price, $price_count)) {
                     $price_count[$relation->price] = 0;
                 }
                 // store number of times price is used
                 $price_count[$relation->price]++;
             }
         }
         $relations = $prices_manager->getItems(array('id', 'method'), array('id' => $price_list));
         $method_count = array();
         if (count($relations) > 0) {
             foreach ($relations as $relation) {
                 $key = $relation->method;
                 if (!array_key_exists($key, $method_count)) {
                     $method_count[$key] = 0;
                 }
                 // increase method usage count with number of price usages
                 $method_count[$key] += $price_count[$relation->id];
             }
         }
         // We compare number of items with method associated with
         // that item. Methods that have number same as number of items
         // are supported and we include them in list.
         $border_count = count($id_list);
         $valid_methods = array();
         if (count($method_count) > 0) {
             foreach ($method_count as $id => $count) {
                 if ($count == $border_count) {
                     $valid_methods[] = $id;
                 }
             }
         }
         if (count($valid_methods) > 0) {
             $conditions['id'] = $valid_methods;
         } else {
             $conditions['id'] = -1;
         }
         // filter by location
         $shop_location = isset($this->_parent->settings['shop_location']) ? $this->_parent->settings['shop_location'] : '';
         if (!empty($shop_location)) {
             $same_country = $shop_location == $_SESSION['buyer']['country'];
             if ($same_country) {
                 $conditions['domestic'] = 1;
             } else {
                 $conditions['international'] = 1;
             }
         }
     }
     // get template
     $template = $this->_parent->loadTemplate($tag_params, 'delivery_methods_list_item.xml');
     $template->registerTagHandler('_price_list', $this, 'tag_DeliveryPricesList');
     // get items from database
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = array('id' => $item->id, 'name' => $item->name, 'international' => $item->international, 'international_char' => $item->international ? CHAR_CHECKED : CHAR_UNCHECKED, 'domestic' => $item->domestic, 'domestic_char' => $item->domestic ? CHAR_CHECKED : CHAR_UNCHECKED, 'item' => $item_id, 'selected' => $selected == $item->id ? 1 : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_delivery_method_change', 370, $this->_parent->getLanguageConstant('title_delivery_method_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delivery_methods'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_delivery_method_delete', 400, $this->_parent->getLanguageConstant('title_delivery_method_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delivery_methods'), array('sub_action', 'delete'), array('id', $item->id)))), 'item_prices' => url_MakeHyperlink($this->_parent->getLanguageConstant('prices'), window_Open('shop_delivery_method_prices', 370, $this->_parent->getLanguageConstant('title_delivery_method_prices'), true, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delivery_methods'), array('sub_action', 'prices'), array('id', $item->id)))));
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Handle request for JSON object
  */
 public function json_GetItem()
 {
     $uid = isset($_REQUEST['uid']) ? fix_chars($_REQUEST['uid']) : null;
     $manager = ShopItemManager::getInstance();
     // prepare result
     $result = array('error' => false, 'error_message' => '', 'item' => array());
     if (!is_null($uid)) {
         // create conditions
         $conditions = array('uid' => $uid, 'deleted' => 0, 'visible' => 1);
         $item = $manager->getSingleItem($manager->getFieldNames(), $conditions);
         if (is_object($item)) {
             // get item image url
             $thumbnail_url = null;
             if (class_exists('gallery')) {
                 $gallery = gallery::getInstance();
                 $thumbnail_url = $gallery->getGroupThumbnailURL($item->gallery);
             }
             $rating = 0;
             $result['item'] = array('id' => $item->id, 'uid' => $item->uid, 'name' => $item->name, 'description' => $item->description, 'gallery' => $item->gallery, 'views' => $item->views, 'price' => $item->price, 'tax' => $item->tax, 'weight' => $item->weight, 'votes_up' => $item->votes_up, 'votes_down' => $item->votes_down, 'rating' => $rating, 'priority' => $item->priority, 'timestamp' => $item->timestamp, 'thumbnail' => $thumbnail_url);
         } else {
             // there was a problem with reading item from database
             $result['error'] = true;
             $result['error_message'] = $this->_parent->getLanguageConstant('message_error_getting_item');
         }
     } else {
         // invalid ID was specified
         $result['error'] = true;
         $result['error_message'] = $this->_parent->getLanguageConstant('message_error_invalid_id');
     }
     // create JSON object and print it
     define('_OMIT_STATS', 1);
     print json_encode($result);
 }
Ejemplo n.º 6
0
 /**
  * Handle drawing list of items in transaction
  */
 public function tag_TransactionItemList($tag_params, $children)
 {
     $manager = ShopTransactionItemsManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     $transaction_manager = ShopTransactionsManager::getInstance();
     $currency_manager = ShopCurrenciesManager::getInstance();
     $id = null;
     if (isset($tag_params['id'])) {
         // get id from tag params
         $id = fix_id($tag_params['id']);
     } else {
         if (isset($_REQUEST['id'])) {
             // get id from request params
             $id = fix_id($_REQUEST['id']);
         }
     }
     // if we don't have transaction Id, get out
     if (is_null($id)) {
         return;
     }
     $currency_id = $transaction_manager->getItemValue('currency', array('id' => $id));
     $currency = $currency_manager->getItemValue('currency', array('id' => $currency_id));
     // get items from database
     $items = array();
     $raw_items = $manager->getItems($manager->getFieldNames(), array('transaction' => $id));
     if (count($raw_items) > 0) {
         foreach ($raw_items as $item) {
             $items[$item->item] = array('id' => $item->id, 'price' => $item->price, 'tax' => $item->tax, 'amount' => $item->amount, 'description' => $item->description, 'uid' => '', 'name' => '', 'gallery' => '', 'manufacturer' => '', 'author' => '', 'views' => '', 'weight' => '', 'votes_up' => '', 'votes_down' => '', 'timestamp' => '', 'priority' => '', 'visible' => '', 'deleted' => '', 'total' => ($item->price + $item->price * ($item->tax / 100)) * $item->amount, 'currency' => $currency);
         }
     }
     // get the rest of item details from database
     $id_list = array_keys($items);
     $raw_items = $item_manager->getItems($item_manager->getFieldNames(), array('id' => $id_list));
     if (count($raw_items) > 0) {
         foreach ($raw_items as $item) {
             $id = $item->id;
             $items[$id]['uid'] = $item->uid;
             $items[$id]['name'] = $item->name;
             $items[$id]['gallery'] = $item->gallery;
             $items[$id]['manufacturer'] = $item->manufacturer;
             $items[$id]['author'] = $item->author;
             $items[$id]['views'] = $item->views;
             $items[$id]['weight'] = $item->weight;
             $items[$id]['votes_up'] = $item->votes_up;
             $items[$id]['votes_down'] = $item->votes_down;
             $items[$id]['timestamp'] = $item->timestamp;
             $items[$id]['priority'] = $item->priority;
             $items[$id]['visible'] = $item->visible;
             $items[$id]['deleted'] = $item->deleted;
         }
     }
     if (count($items) > 0) {
         $template = $this->_parent->loadTemplate($tag_params, 'transaction_details_item.xml');
         foreach ($items as $id => $params) {
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Handle drawing checkout items
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CheckoutItems($tag_params, $children)
 {
     global $language;
     $manager = ShopItemManager::getInstance();
     $cart = isset($_SESSION['shopping_cart']) ? $_SESSION['shopping_cart'] : array();
     $ids = array_keys($cart);
     // get items from database
     $items = $manager->getItems($manager->getFieldNames(), array('uid' => $ids));
     $items_by_uid = array();
     $items_for_checkout = array();
     // parse items from database
     foreach ($items as $item) {
         $db_item = array('name' => $item->name, 'price' => $item->price, 'tax' => $item->tax, 'weight' => $item->weight);
         $items_by_uid[$item->uid] = $db_item;
     }
     // prepare items for checkout
     foreach ($cart as $uid => $item) {
         if (count($item['variations']) > 0) {
             foreach ($item['variations'] as $variation_id => $data) {
                 // add items to checkout list
                 $properties = $data;
                 foreach ($this->excluded_properties as $key) {
                     if (isset($properties[$key])) {
                         unset($properties[$key]);
                     }
                 }
                 $new_item = $items_by_uid[$uid];
                 $new_item['count'] = $data['count'];
                 $new_item['description'] = implode(', ', array_values($properties));
                 $new_item['total'] = number_format($new_item['price'] * (1 + $new_item['tax'] / 100) * $new_item['count'], 2);
                 $new_item['tax'] = number_format($new_item['price'], 2);
                 $new_item['price'] = number_format($new_item['tax'], 2);
                 $new_item['weight'] = number_format($new_item['weight'], 2);
                 // add item to the list
                 $items_for_checkout[] = $new_item;
             }
         }
     }
     // load template
     $template = $this->loadTemplate($tag_params, 'checkout_form_item.xml');
     // parse template
     if (count($items_for_checkout) > 0) {
         foreach ($items_for_checkout as $params) {
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }