Пример #1
0
 /**
  * Public function that creates a single instance
  * 
  * @param object $parent
  * @return ShopItemSizesHandler
  */
 public static function getInstance($parent)
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self($parent);
     }
     return self::$_instance;
 }
Пример #2
0
 /**
  * Handle drawing shop item
  * 
  * @param array $tag_params
  * @param array $children
  */
 public function tag_Item($tag_params, $children)
 {
     $manager = ShopItemManager::getInstance();
     $manufacturer_manager = ShopManufacturerManager::getInstance();
     $id = null;
     $gallery = null;
     $conditions = array();
     // prepare conditions
     if (isset($tag_params['id'])) {
         $id = fix_id($tag_params['id']);
     }
     if (isset($tag_params['random']) && isset($tag_params['category'])) {
         if (is_numeric($tag_params['category'])) {
             $category_id = fix_id($tag_params['category']);
         } else {
             // specified id is actually text_id, get real one
             $category_manager = ShopCategoryManager::getInstance();
             $category = $category_manager->getSingleItem(array('id'), array('text_id' => fix_chars($tag_params['category'])));
             if (!is_object($category)) {
                 return;
             }
             $category_id = $category->id;
         }
         $membership_manager = ShopItemMembershipManager::getInstance();
         // get all associated items
         $id_list = array();
         $membership_list = $membership_manager->getItems(array('item'), array('category' => $category_id));
         if (count($membership_list) > 0) {
             foreach ($membership_list as $membership) {
                 $id_list[] = $membership->item;
             }
         }
         // get random id from the list
         if (count($id_list) > 0) {
             $id = $id_list[array_rand($id_list)];
         }
     }
     if (is_null($id)) {
         return;
     }
     // get item from database
     $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     // create template handler
     $template = $this->_parent->loadTemplate($tag_params, 'item.xml');
     $template->setMappedModule($this->name);
     // register tag handlers
     if (!is_null($gallery)) {
         $template->registerTagHandler('_image_list', $gallery, 'tag_ImageList');
     }
     $size_handler = ShopItemSizesHandler::getInstance($this->_parent);
     $template->registerTagHandler('_value_list', $size_handler, 'tag_ValueList');
     $template->registerTagHandler('_color_list', $this, 'tag_ColorList');
     // parse template
     if (is_object($item)) {
         // get gallery module
         if (class_exists('gallery')) {
             $gallery = gallery::getInstance();
         }
         if (!is_null($gallery)) {
             // get manufacturer logo
             $manufacturer_logo_url = '';
             if ($item->manufacturer != 0) {
                 $manufacturer = $manufacturer_manager->getSingleItem($manufacturer_manager->getFieldNames(), array('id' => $item->manufacturer));
                 if (is_object($manufacturer)) {
                     $manufacturer_logo_url = $gallery->getImageURL($manufacturer->logo);
                 }
             }
             // get urls for image and thumbnail
             $image_url = $gallery->getGroupThumbnailURL($item->gallery, true);
             $thumbnail_url = $gallery->getGroupThumbnailURL($item->gallery);
         } else {
             // default values if gallery is not enabled
             $image_url = '';
             $thumbnail_url = '';
             $manufacturer_logo_url = '';
         }
         $rating = 0;
         $params = array('id' => $item->id, 'uid' => $item->uid, 'name' => $item->name, 'description' => $item->description, 'gallery' => $item->gallery, 'image' => $image_url, 'thumbnail' => $thumbnail_url, 'manufacturer_logo_url' => $manufacturer_logo_url, 'size_definition' => $item->size_definition, 'colors' => $item->colors, 'author' => $item->author, 'views' => $item->views, 'price' => $item->price, 'tax' => $item->tax, 'currency' => $this->_parent->settings['default_currency'], 'weight' => $item->weight, 'votes_up' => $item->votes_up, 'votes_down' => $item->votes_down, 'rating' => $rating, 'priority' => $item->priority, 'timestamp' => $item->timestamp, 'visible' => $item->visible, 'deleted' => $item->deleted);
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     }
 }
Пример #3
0
 /**
  * Transfers control to module functions
  *
  * @param array $params
  * @param array $children
  */
 public function transferControl($params, $children)
 {
     // global control actions
     if (isset($params['action'])) {
         switch ($params['action']) {
             case 'show_item':
                 $handler = ShopItemHandler::getInstance($this);
                 $handler->tag_Item($params, $children);
                 break;
             case 'show_item_list':
                 $handler = ShopItemHandler::getInstance($this);
                 $handler->tag_ItemList($params, $children);
                 break;
             case 'show_category':
                 $handler = ShopCategoryHandler::getInstance($this);
                 $handler->tag_Category($params, $children);
                 break;
             case 'show_category_list':
                 $handler = ShopCategoryHandler::getInstance($this);
                 $handler->tag_CategoryList($params, $children);
                 break;
             case 'show_completed_message':
                 $this->tag_CompletedMessage($params, $children);
                 break;
             case 'show_canceled_message':
                 $this->tag_CanceledMessage($params, $children);
                 break;
             case 'show_checkout_form':
                 $this->tag_CheckoutForm($params, $children);
                 break;
             case 'show_payment_methods':
                 $this->tag_PaymentMethodsList($params, $children);
                 break;
             case 'show_recurring_plan':
                 $this->tag_RecurringPlan($params, $children);
                 break;
             case 'configure_search':
                 $this->configureSearch($params, $children);
                 break;
             case 'checkout':
                 $this->showCheckout();
                 break;
             case 'checkout_completed':
                 $this->showCheckoutCompleted();
                 break;
             case 'checkout_canceled':
                 $this->showCheckoutCanceled();
                 break;
             case 'show_checkout_items':
                 $this->tag_CheckoutItems($params, $children);
                 break;
             case 'set_item_as_cart':
                 $this->setItemAsCart($params, $children);
                 break;
             case 'set_cart_from_template':
                 $this->setCartFromTemplate($params, $children);
                 break;
             case 'set_recurring_plan':
                 $this->setRecurringPlan($params, $children);
                 break;
             case 'cancel_recurring_plan':
                 $this->cancelRecurringPlan($params, $children);
                 break;
             case 'include_scripts':
                 $this->includeScripts($params, $children);
                 break;
             case 'json_get_item':
                 $handler = ShopItemHandler::getInstance($this);
                 $handler->json_GetItem();
                 break;
             case 'json_get_currency':
                 $this->json_GetCurrency();
                 break;
             case 'json_get_account_info':
                 $this->json_GetAccountInfo();
                 break;
             case 'json_get_account_exists':
                 $this->json_GetAccountExists();
                 break;
             case 'json_get_payment_methods':
                 $this->json_GetPaymentMethods();
                 break;
             case 'json_add_item_to_shopping_cart':
                 $this->json_AddItemToCart();
                 break;
             case 'json_remove_item_from_shopping_cart':
                 $this->json_RemoveItemFromCart();
                 break;
             case 'json_change_item_quantity':
                 $this->json_ChangeItemQuantity();
                 break;
             case 'json_clear_shopping_cart':
                 $this->json_ClearCart();
                 break;
             case 'json_get_shopping_cart':
                 $this->json_ShowCart();
                 break;
             case 'json_update_transaction_status':
                 $handler = ShopTransactionsHandler::getInstance($this);
                 $handler->json_UpdateTransactionStatus();
                 break;
             case 'json_get_shopping_cart_summary':
                 $this->json_GetShoppingCartSummary();
                 break;
             case 'json_save_remark':
                 $this->json_SaveRemark();
                 break;
             default:
                 break;
         }
     }
     // global control actions
     if (isset($params['backend_action'])) {
         $action = $params['backend_action'];
         switch ($action) {
             case 'items':
                 $handler = ShopItemHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'currencies':
                 $handler = ShopCurrenciesHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'categories':
                 $handler = ShopCategoryHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'sizes':
                 $handler = ShopItemSizesHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'transactions':
                 $handler = ShopTransactionsHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'manufacturers':
                 $handler = ShopManufacturerHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'special_offers':
                 break;
             case 'warehouses':
                 $handler = ShopWarehouseHandler::getInstance($this);
                 $handler->transferControl($params, $children);
                 break;
             case 'stocks':
                 break;
             case 'settings':
                 $this->showSettings();
                 break;
             case 'settings_save':
                 $this->saveSettings();
                 break;
             default:
                 break;
         }
     }
 }