/** * Public function that creates a single instance */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Handle item size values tag * * @param array $tag_params * @param array $childen */ public function tag_ValueList($tag_params, $children) { $manager = ShopItemSizeValuesManager::getInstance(); $conditions = array(); // create conditions if (isset($tag_params['definition'])) { $conditions['definition'] = fix_id($tag_params['definition']); } // get items from database $items = $manager->getItems($manager->getFieldNames(), $conditions); // create template $template = $this->_parent->loadTemplate($tag_params, 'values_list_item.xml'); $template->setMappedModule($this->name); // parse template if (count($items) > 0) { foreach ($items as $item) { $params = array('id' => $item->id, 'value' => $item->value, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_item_size_values_change', 370, $this->_parent->getLanguageConstant('title_size_value_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'sizes'), array('sub_action', 'value_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_item_size_values_delete', 400, $this->_parent->getLanguageConstant('title_size_value_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'sizes'), array('sub_action', 'value_delete'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Show shopping card in form of JSON object */ private function json_ShowCart() { $manager = ShopItemManager::getInstance(); $values_manager = ShopItemSizeValuesManager::getInstance(); $gallery = class_exists('gallery') ? gallery::getInstance() : null; $cart = isset($_SESSION['shopping_cart']) ? $_SESSION['shopping_cart'] : array(); $result = array(); // get shopping cart from session $result['cart'] = array(); $result['size_values'] = array(); $result['count'] = count($result['cart']); $result['currency'] = $this->getDefaultCurrency(); if (isset($_SESSION['transaction'])) { $result['shipping'] = $_SESSION['transaction']['shipping']; $result['handling'] = $_SESSION['transaction']['handling']; } else { $result['shipping'] = 0; $result['handling'] = 0; } // colect ids from session $ids = array_keys($cart); // get items from database and prepare result $items = $manager->getItems($manager->getFieldNames(), array('uid' => $ids)); $values = $values_manager->getItems($values_manager->getFieldNames(), array()); if (count($items) > 0) { foreach ($items as $item) { // get item image url $thumbnail_url = !is_null($gallery) ? $gallery->getGroupThumbnailURL($item->gallery) : ''; $uid = $item->uid; if (array_key_exists($uid, $cart) && count($cart[$uid]['variations']) > 0) { foreach ($cart[$uid]['variations'] as $variation_id => $properties) { $new_properties = $properties; unset($new_properties['count']); $result['cart'][] = array('name' => $item->name, 'weight' => $item->weight, 'price' => $item->price, 'tax' => $item->tax, 'image' => $thumbnail_url, 'uid' => $item->uid, 'variation_id' => $variation_id, 'count' => $properties['count'], 'properties' => $new_properties); } } } } if (count($values) > 0) { foreach ($values as $value) { $result['size_values'][$value->id] = array('definition' => $value->definition, 'value' => $value->value); } } print json_encode($result); }