Exemple #1
0
 /**
  * Retireve a list of currencies from the database.
  * This function is used in the backend for the currency listing, therefore no asking if enabled or not
  * @author Max Milbers
  * @return object List of currency objects
  */
 function getCurrenciesList($search, $vendorId = 1)
 {
     $where = array();
     $user = JFactory::getUser();
     $shared = '';
     if (vmAccess::manager()) {
         $shared = 'OR `shared`="1"';
     }
     $vendorId = vmAccess::isSuperVendor();
     if ($vendorId) {
         $where[] = '(`virtuemart_vendor_id` = "' . (int) $vendorId . '" ' . $shared . ')';
     }
     if (empty($search)) {
         $search = vRequest::getString('search', false);
     }
     // add filters
     if ($search) {
         $db = JFactory::getDBO();
         $search = '"%' . $db->escape($search, true) . '%"';
         $where[] = '`currency_name` LIKE ' . $search . ' OR `currency_code_2` LIKE ' . $search . ' OR `currency_code_3` LIKE ' . $search;
     }
     $whereString = '';
     if (count($where) > 0) {
         $whereString = ' WHERE ' . implode(' AND ', $where);
     }
     $data = $this->exeSortSearchListQuery(0, '*', ' FROM `#__virtuemart_currencies`', $whereString, '', $this->_getOrdering());
     return $data;
 }
Exemple #2
0
 function display($tpl = null)
 {
     if (!class_exists('VmHTML')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
     }
     $this->vendorId = vmAccess::isSuperVendor();
     // TODO add icon for media view
     $this->SetViewTitle();
     $model = VmModel::getModel('media');
     $layoutName = vRequest::getCmd('layout', 'default');
     if ($layoutName == 'edit') {
         $this->media = $model->getFile();
         $this->addStandardEditViewCommands();
     } else {
         $virtuemart_product_id = vRequest::getInt('virtuemart_product_id');
         if (is_array($virtuemart_product_id) && count($virtuemart_product_id) > 0) {
             $virtuemart_product_id = (int) $virtuemart_product_id[0];
         } else {
             $virtuemart_product_id = (int) $virtuemart_product_id;
         }
         $cat_id = vRequest::getInt('virtuemart_category_id', 0);
         $super = vmAccess::isSuperVendor();
         if ($super == 1) {
             JToolBarHelper::custom('synchronizeMedia', 'new', 'new', vmText::_('COM_VIRTUEMART_TOOLS_SYNC_MEDIA_FILES'), false);
         }
         $this->addStandardDefaultViewCommands();
         $this->addStandardDefaultViewLists($model, null, null, 'searchMedia');
         $options = array('' => vmText::_('COM_VIRTUEMART_LIST_ALL_TYPES'), 'product' => vmText::_('COM_VIRTUEMART_PRODUCT'), 'category' => vmText::_('COM_VIRTUEMART_CATEGORY'), 'manufacturer' => vmText::_('COM_VIRTUEMART_MANUFACTURER'), 'vendor' => vmText::_('COM_VIRTUEMART_VENDOR'));
         $this->lists['search_type'] = VmHTML::selectList('search_type', vRequest::getVar('search_type'), $options, 1, '', 'onchange="this.form.submit();"');
         $options = array('' => vmText::_('COM_VIRTUEMART_LIST_ALL_ROLES'), 'file_is_displayable' => vmText::_('COM_VIRTUEMART_FORM_MEDIA_DISPLAYABLE'), 'file_is_downloadable' => vmText::_('COM_VIRTUEMART_FORM_MEDIA_DOWNLOADABLE'), 'file_is_forSale' => vmText::_('COM_VIRTUEMART_FORM_MEDIA_SET_FORSALE'));
         $this->lists['search_role'] = VmHTML::selectList('search_role', vRequest::getVar('search_role'), $options, 1, '', 'onchange="this.form.submit();"');
         $this->files = $model->getFiles(false, false, $virtuemart_product_id, $cat_id);
         $this->pagination = $model->getPagination();
     }
     parent::display($tpl);
 }
Exemple #3
0
 public static function isSuperVendor($uid = 0)
 {
     return vmAccess::isSuperVendor($uid);
 }
 public function display($tpl = null)
 {
     $vendorId = vRequest::getInt('vendorid', 1);
     $vendorModel = VmModel::getModel('vendor');
     $vendorIdUser = vmAccess::isSuperVendor();
     $vendorModel->setId($vendorId);
     $this->vendor = $vendorModel->getVendor();
     if (!class_exists('shopFunctionsF')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
     }
     if (VmConfig::get('enable_content_plugin', 0)) {
         shopFunctionsF::triggerContentPlugin($this->vendor, 'vendor', 'vendor_store_desc');
         shopFunctionsF::triggerContentPlugin($this->vendor, 'vendor', 'vendor_terms_of_service');
     }
     $app = JFactory::getApplication();
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     if (!empty($menu->id)) {
         ShopFunctionsF::setLastVisitedItemId($menu->id);
     } else {
         if ($itemId = vRequest::getInt('Itemid', false)) {
             ShopFunctionsF::setLastVisitedItemId($itemId);
         }
     }
     $document = JFactory::getDocument();
     if (!VmConfig::get('shop_is_offline', 0)) {
         if (ShopFunctionsF::isFEmanager('product.edit')) {
             $add_product_link = JURI::root() . 'index.php?option=com_virtuemart&tmpl=component&view=product&task=edit&virtuemart_product_id=0&manage=1';
             $add_product_link = $this->linkIcon($add_product_link, 'COM_VIRTUEMART_PRODUCT_FORM_NEW_PRODUCT', 'edit', false, false);
         } else {
             $add_product_link = "";
         }
         $this->assignRef('add_product_link', $add_product_link);
         $categoryModel = VmModel::getModel('category');
         $productModel = VmModel::getModel('product');
         $ratingModel = VmModel::getModel('ratings');
         $productModel->withRating = $this->showRating = $ratingModel->showRating();
         $this->products = array();
         $categoryId = vRequest::getInt('catid', 0);
         $categoryChildren = $categoryModel->getChildCategoryList($vendorId, $categoryId);
         $categoryModel->addImages($categoryChildren, 1);
         $this->assignRef('categories', $categoryChildren);
         if (!class_exists('CurrencyDisplay')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
         }
         $this->currency = CurrencyDisplay::getInstance();
         $products_per_row = VmConfig::get('homepage_products_per_row', 3);
         $featured_products_rows = VmConfig::get('featured_products_rows', 1);
         $featured_products_count = $products_per_row * $featured_products_rows;
         if (!empty($featured_products_count) and VmConfig::get('show_featured', 1)) {
             $this->products['featured'] = $productModel->getProductListing('featured', $featured_products_count);
             $productModel->addImages($this->products['featured'], 1);
         }
         $latest_products_rows = VmConfig::get('latest_products_rows');
         $latest_products_count = $products_per_row * $latest_products_rows;
         if (!empty($latest_products_count) and VmConfig::get('show_latest', 1)) {
             $this->products['latest'] = $productModel->getProductListing('latest', $latest_products_count);
             $productModel->addImages($this->products['latest'], 1);
         }
         $topTen_products_rows = VmConfig::get('topTen_products_rows');
         $topTen_products_count = $products_per_row * $topTen_products_rows;
         if (!empty($topTen_products_count) and VmConfig::get('show_topTen', 1)) {
             $this->products['topten'] = $productModel->getProductListing('topten', $topTen_products_count);
             $productModel->addImages($this->products['topten'], 1);
         }
         $recent_products_rows = VmConfig::get('recent_products_rows');
         $recent_products_count = $products_per_row * $recent_products_rows;
         if (!empty($recent_products_count) and VmConfig::get('show_recent', 1)) {
             $recent_products = $productModel->getProductListing('recent');
             if (!empty($recent_products)) {
                 $this->products['recent'] = $productModel->getProductListing('recent', $recent_products_count);
                 $productModel->addImages($this->products['recent'], 1);
             }
         }
         if ($this->products) {
             $display_stock = VmConfig::get('display_stock', 1);
             $showCustoms = VmConfig::get('show_pcustoms', 1);
             if ($display_stock or $showCustoms) {
                 if (!$showCustoms) {
                     foreach ($this->products as $pType => $productSeries) {
                         foreach ($productSeries as $i => $productItem) {
                             $this->products[$pType][$i]->stock = $productModel->getStockIndicator($productItem);
                         }
                     }
                 } else {
                     if (!class_exists('vmCustomPlugin')) {
                         require JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php';
                     }
                     foreach ($this->products as $pType => $productSeries) {
                         shopFunctionsF::sortLoadProductCustomsStockInd($this->products[$pType], $productModel);
                     }
                 }
             }
         }
         $this->showBasePrice = (vmAccess::manager() or vmAccess::isSuperVendor());
         $layout = VmConfig::get('vmlayout', 'default');
         $this->setLayout($layout);
         $productsLayout = VmConfig::get('productsublayout', 'products');
         if (empty($productsLayout)) {
             $productsLayout = 'products';
         }
         $this->productsLayout = empty($menu->query['productsublayout']) ? $productsLayout : $menu->query['productsublayout'];
         // Add feed links
         if ($this->products && (VmConfig::get('feed_featured_published', 0) == 1 or VmConfig::get('feed_topten_published', 0) == 1 or VmConfig::get('feed_latest_published', 0) == 1)) {
             $link = '&format=feed&limitstart=';
             $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
             $document->addHeadLink(JRoute::_($link . '&type=rss', FALSE), 'alternate', 'rel', $attribs);
             $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
             $document->addHeadLink(JRoute::_($link . '&type=atom', FALSE), 'alternate', 'rel', $attribs);
         }
         vmJsApi::jPrice();
     } else {
         $this->setLayout('off_line');
     }
     $error = vRequest::getInt('error', 0);
     //Todo this may not work everytime as expected, because the error must be set in the redirect links.
     if (!empty($error)) {
         $document->setTitle(vmText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND') . vmText::sprintf('COM_VIRTUEMART_HOME', $this->vendor->vendor_store_name));
     } else {
         if (empty($this->vendor->customtitle)) {
             if ($menu) {
                 $menuTitle = $menu->params->get('page_title');
                 if (empty($menuTitle)) {
                     $menuTitle = vmText::sprintf('COM_VIRTUEMART_HOME', $this->vendor->vendor_store_name);
                 }
                 $document->setTitle($menuTitle);
             } else {
                 $title = vmText::sprintf('COM_VIRTUEMART_HOME', $this->vendor->vendor_store_name);
                 $document->setTitle($title);
             }
         } else {
             $document->setTitle($this->vendor->customtitle);
         }
         if (!empty($this->vendor->metadesc)) {
             $document->setMetaData('description', $this->vendor->metadesc);
         }
         if (!empty($this->vendor->metakey)) {
             $document->setMetaData('keywords', $this->vendor->metakey);
         }
         if (!empty($this->vendor->metarobot)) {
             $document->setMetaData('robots', $this->vendor->metarobot);
         }
         if (!empty($this->vendor->metaauthor)) {
             $document->setMetaData('author', $this->vendor->metaauthor);
         }
     }
     if (!class_exists('VmTemplate')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'vmtemplate.php';
     }
     vmTemplate::setTemplate();
     parent::display($tpl);
 }
 public static function categoryListTree($selectedCategories = array(), $cid = 0, $level = 0, $disabledFields = array())
 {
     $hash = crc32(implode('.', $selectedCategories) . ':' . $cid . ':' . $level . implode('.', $disabledFields));
     if (empty(self::$categoryTree[$hash])) {
         $cache = JFactory::getCache('com_virtuemart_cats');
         $cache->setCaching(1);
         $app = JFactory::getApplication();
         $vendorId = vmAccess::isSuperVendor();
         self::$categoryTree[$hash] = $cache->call(array('ShopFunctions', 'categoryListTreeLoop'), $selectedCategories, $cid, $level, $disabledFields, $app->isSite(), $vendorId, VmConfig::$vmlang);
     }
     return self::$categoryTree[$hash];
 }
Exemple #6
0
 function display($tpl = null)
 {
     // Get the task
     $task = vRequest::getCmd('task', $this->getLayout());
     $this->assignRef('task', $task);
     // Load helpers
     if (!class_exists('CurrencyDisplay')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     if (!class_exists('VmHTML')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
     }
     if (!class_exists('VmImage')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'image.php';
     }
     $model = tmsModel::getModel();
     // Handle any publish/unpublish
     switch ($task) {
         case 'add':
         case 'edit':
             //this was in the controller for the edit tasks, we need this for the access by FE
             //$this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'views'.DS.'product'.DS.'tmpl');
             tsmConfig::loadJLang('com_tsmart_orders', TRUE);
             tsmConfig::loadJLang('com_tsmart_shoppers', TRUE);
             $model_country = tmsModel::getModel('country');
             $this->countries = $model_country->getItemList();
             $tsmart_product_id = vRequest::getInt('tsmart_product_id');
             if (is_array($tsmart_product_id) && count($tsmart_product_id) > 0) {
                 $tsmart_product_id = (int) $tsmart_product_id[0];
             } else {
                 $tsmart_product_id = (int) $tsmart_product_id;
             }
             $product = $model->getItem($tsmart_product_id);
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmserviceclass.php';
             $product->tsmart_service_class_ids = tsmserviceclass::get_list_service_class_ids_by_tour_id($tsmart_product_id);
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmgroupsize.php';
             $product->tsmart_group_size_ids = tsmGroupSize::get_list_group_size_ids_by_tour_id($tsmart_product_id);
             //$user = JFactory::getUser();
             $superVendor = vmAccess::isSuperVendor();
             if ($superVendor != 1 and $superVendor != $product->tsmart_vendor_id) {
                 vmdebug('Product view.html.php ' . $superVendor, $product->tsmart_vendor_id);
                 JFactory::getApplication()->redirect('index.php?option=com_tsmart&view=tsmart', tsmText::_('com_tsmart_ALERTNOTAUTHOR'), 'error');
             }
             if (!empty($product->product_parent_id)) {
                 $product_parent = $model->getProductSingle($product->product_parent_id, false);
             }
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmserviceclass.php';
             $this->tour_service_class = tsmserviceclass::get_list_tour_service_class();
             $customfields = tmsModel::getModel('Customfields');
             $product->allIds[] = $product->tsmart_product_id;
             if (!empty($product->product_parent_id)) {
                 $product->allIds[] = $product->product_parent_id;
             }
             $product->customfields = $customfields->getCustomEmbeddedProductCustomFields($product->allIds);
             // Get the category tree
             if (isset($product->categories)) {
                 $this->category_tree = ShopFunctions::categoryListTree($product->categories);
             } else {
                 $this->category_tree = ShopFunctions::categoryListTree();
             }
             //Fallback for categories inherited by parent to correctly calculate the prices
             if (empty($product->categories) and !empty($product_parent->categories)) {
                 $product->categories = $product_parent->categories;
             }
             //Get the shoppergoup list - Cleanshooter Custom Shopper Visibility
             if (!isset($product->shoppergroups)) {
                 $product->shoppergroups = 0;
             }
             $this->shoppergroupList = ShopFunctions::renderShopperGroupList($product->shoppergroups);
             // Load the product price
             if (!class_exists('calculationHelper')) {
                 require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
             }
             //Do we need the children? If there is a C customfield, we dont want them
             $isCustomVariant = false;
             foreach ($product->customfields as $custom) {
                 if ($custom->field_type == 'C' and $custom->tsmart_product_id == $tsmart_product_id) {
                     $isCustomVariant = true;
                     break;
                 }
             }
             if (!class_exists('tsmartModelConfig')) {
                 require VMPATH_ADMIN . '/models/config.php';
             }
             $productLayouts = tsmartModelConfig::getLayoutList('productdetails');
             $this->productLayouts = $productLayouts;
             // Load Images
             $model->addImages($product);
             if (!class_exists('VmTemplate')) {
                 require VMPATH_SITE . DS . 'helpers' . DS . 'vmtemplate.php';
             }
             $vmtemplate = VmTemplate::loadVmTemplateStyle();
             $this->imagePath = shopFunctions::getAvailabilityIconUrl($vmtemplate);
             // Load the vendors
             $vendor_model = tmsModel::getModel('vendor');
             $lists['vendors'] = '';
             if ($this->showVendors()) {
                 $lists['vendors'] = Shopfunctions::renderVendorList($product->tsmart_vendor_id);
             }
             // Load the currencies
             $currency_model = tmsModel::getModel('currency');
             $vendor_model->setId(vmAccess::isSuperVendor());
             $this->vendor = $vendor_model->getVendor();
             $currency = $currency_model->getItemList();
             $this->vendor_currency_symb = $currency->currency_symbol;
             $lists['manufacturers'] = shopFunctions::renderManufacturerList($product->tsmart_manufacturer_id, true);
             if (!empty($product->product_weight_uom)) {
                 $product_weight_uom = $product->product_weight_uom;
             } else {
                 if (!empty($product_parent)) {
                     $product_weight_uom = $product_parent->product_weight_uom;
                 } else {
                     $product_weight_uom = tsmConfig::get('weight_unit_default');
                 }
             }
             if (!empty($product->product_lwh_uom)) {
                 $product_lwh_uom = $product->product_lwh_uom;
             } else {
                 if (!empty($product_parent)) {
                     $product_lwh_uom = $product_parent->product_lwh_uom;
                 } else {
                     $product_lwh_uom = tsmConfig::get('lwh_unit_default');
                 }
             }
             if (!empty($product->product_unit)) {
                 $product_unit = $product->product_unit;
             } else {
                 if (!empty($product_parent)) {
                     $product_unit = $product_parent->product_unit;
                 } else {
                     $product_unit = tsmConfig::get('product_unit_default', 'KG');
                 }
             }
             $lists['product_weight_uom'] = ShopFunctions::renderWeightUnitList('product_weight_uom', $product_weight_uom);
             $lists['product_iso_uom'] = ShopFunctions::renderUnitIsoList('product_unit', $product_unit);
             $lists['product_lwh_uom'] = ShopFunctions::renderLWHUnitList('product_lwh_uom', $product_lwh_uom);
             if (empty($product->product_available_date)) {
                 $product->product_available_date = date("Y-m-d");
             }
             $waitinglistmodel = tmsModel::getModel('waitinglist');
             /* Load waiting list */
             if ($product->tsmart_product_id) {
                 //$waitinglist = $this->get('waitingusers', 'waitinglist');
                 $waitinglist = $waitinglistmodel->getWaitingusers($product->tsmart_product_id);
                 $this->assignRef('waitinglist', $waitinglist);
             }
             $orderstatusModel = tmsModel::getModel('orderstatus');
             $lists['OrderStatus'] = $orderstatusModel->renderOSList(array(), 'order_status', TRUE);
             // Add the tsmart_shoppergroup_ids
             $cid = JFactory::getUser()->id;
             $this->activeShoppergroups = shopfunctions::renderGuiList($cid, 'shoppergroups', 'shopper_group_name', 'category', 'vmuser_shoppergroups', 'tsmart_user_id');
             if (!empty($this->activeShoppergroups)) {
                 $shoppergroupModel = tmsModel::getModel('shoppergroup');
                 $this->activeShoppergroups = tsmText::_($shoppergroupModel->getDefault(0)->shopper_group_name);
             }
             // Load protocustom lists
             $customModel = tmsModel::getModel('custom');
             $this->fieldTypes = tsmartModelCustom::getCustomTypes();
             $customsList = $customModel->getCustomsList();
             $attribs = 'style= "width: 300px;"';
             $customlist = JHtml::_('select.genericlist', $customsList, 'customlist', $attribs, 'value', 'text', null, false, true);
             $this->assignRef('customsList', $customlist);
             if ($product->product_parent_id > 0) {
                 // Set up labels
                 $info_label = tsmText::_('com_tsmart_PRODUCT_FORM_ITEM_INFO_LBL');
                 $status_label = tsmText::_('com_tsmart_PRODUCT_FORM_ITEM_STATUS_LBL');
                 $dim_weight_label = tsmText::_('com_tsmart_PRODUCT_FORM_ITEM_DIM_WEIGHT_LBL');
                 $images_label = tsmText::_('com_tsmart_PRODUCT_FORM_ITEM_IMAGES_LBL');
                 $delete_message = tsmText::_('com_tsmart_PRODUCT_FORM_DELETE_ITEM_MSG');
             } else {
                 if ($task == 'add') {
                     $action = tsmText::_('com_tsmart_PRODUCT_FORM_NEW_PRODUCT_LBL');
                 } else {
                     $action = tsmText::_('com_tsmart_PRODUCT_FORM_UPDATE_ITEM_LBL');
                 }
                 $info_label = tsmText::_('com_tsmart_PRODUCT_FORM_PRODUCT_INFO_LBL');
                 $status_label = tsmText::_('com_tsmart_PRODUCT_FORM_PRODUCT_STATUS_LBL');
                 $dim_weight_label = tsmText::_('com_tsmart_PRODUCT_FORM_PRODUCT_DIM_WEIGHT_LBL');
                 $images_label = tsmText::_('com_tsmart_PRODUCT_FORM_PRODUCT_IMAGES_LBL');
                 $delete_message = tsmText::_('com_tsmart_PRODUCT_FORM_DELETE_PRODUCT_MSG');
             }
             //get countries
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmcountries.php';
             $countries = tsmcountries::get_countries();
             $this->assignRef('countries', $countries);
             //end get countries
             //get cities
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/vmcities.php';
             $cities = tsmcities::get_cities();
             $this->assignRef('cities', $cities);
             //end get cities
             //get tour style
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmtourstyle.php';
             $list_tour_style = tsmtourstyle::get_list_tour_style();
             $this->assignRef('list_tour_style', $list_tour_style);
             //end get toursyle
             //get tour section
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmtoursection.php';
             $list_tour_section = tsmtoursection::get_list_tour_section();
             $this->assignRef('list_tour_section', $list_tour_section);
             //end get toursyle
             //get tour physicalgrade
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmphysicalgrade.php';
             $list_physical_grade = vmphysicalgrade::get_physical_grade();
             $this->assignRef('list_physical_grade', $list_physical_grade);
             //end get physicalgrade
             //get tour_type
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmtourtype.php';
             $list_tour_type = tsmtourtype::get_list_tour_type();
             $this->assignRef('list_tour_type', $list_tour_type);
             //end get tour_type
             //get tour_type
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmserviceclass.php';
             $list_tour_service_class = tsmserviceclass::get_list_tour_service_class();
             $product->list_tour_service_class_id = tsmserviceclass::get_list_service_class_ids_by_tour_id($product->tsmart_product_id);
             $this->assignRef('list_tour_service_class', $list_tour_service_class);
             //end get tour_type
             //get activities
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/vmactivities.php';
             $product->list_activity_id = tsmactivities::get_list_activity_id_by_tour_id($product->tsmart_product_id);
             $activities = tsmactivities::get_activities();
             $this->assignRef('activities', $activities);
             //end get activities
             //get list group size
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmgroupsize.php';
             $list_group_size = tsmGroupSize::get_list_group_size();
             $product->list_group_size_id = tsmGroupSize::get_list_group_size_ids_by_tour_id($product->tsmart_product_id);
             $this->assignRef('list_group_size', $list_group_size);
             //end get list group size
             //get list country
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmcountries.php';
             $product->list_tsmart_country_id = tsmcountries::get_list_tsmart_country_id_by_tour_id($product->tsmart_product_id);
             //end get list group size
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmprice.php';
             $this->list_price_type = vmprice::get_list_price_type();
             require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmproduct.php';
             $this->list_tour_method = vmproduct::get_list_tour_method();
             $this->assignRef('product', $product);
             $this->assignRef('product_parent', $product_parent);
             /* Assign label values */
             $this->assignRef('action', $action);
             $this->assignRef('info_label', $info_label);
             $this->assignRef('status_label', $status_label);
             $this->assignRef('dim_weight_label', $dim_weight_label);
             $this->assignRef('images_label', $images_label);
             $this->assignRef('delete_message', $delete_message);
             $this->assignRef('lists', $lists);
             // Toolbar
             if ($product->product_sku) {
                 $sku = ' (' . $product->product_sku . ')';
             } else {
                 $sku = "";
             }
             //if (!empty($product->canonCatLink)) $canonLink = '&tsmart_category_id=' . $product->canonCatLink; else $canonLink = '';
             if (!empty($product->tsmart_product_id)) {
                 if (!class_exists('shopFunctionsF')) {
                     require VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
                 }
                 $menuItemID = shopFunctionsF::getMenuItemId(JFactory::getLanguage()->getTag());
                 $canonLink = '';
                 if ($product->canonCatId) {
                     $canonLink = '&tsmart_category_id=' . $product->canonCatId;
                 }
                 $text = '<a href="' . juri::root() . 'index.php?option=com_tsmart&view=productdetails&tsmart_product_id=' . $product->tsmart_product_id . $canonLink . '&Itemid=' . $menuItemID . '" target="_blank" >' . $product->product_name . $sku . '<span class="vm2-modallink"></span></a>';
                 if (JFactory::getApplication()->isSite()) {
                     $bar = JToolBar::getInstance('toolbar');
                     $bar->appendButton('Link', 'back', 'com_tsmart_LEAVE_TO_PRODUCT', juri::root() . 'index.php?option=com_tsmart&view=productdetails&tsmart_product_id=' . $product->tsmart_product_id . $canonLink . '&Itemid=' . $menuItemID);
                 }
             } else {
                 $text = $product->product_name . $sku;
             }
             $this->SetViewTitle('PRODUCT', $text);
             $this->addStandardEditViewCommandsNoValidate($product->tsmart_product_id);
             break;
         case 'massxref_cats':
         case 'massxref_cats_exe':
             $this->SetViewTitle('PRODUCT_MASSXREF');
             $showVendors = $this->showVendors();
             $this->assignRef('showVendors', $showVendors);
             $keyWord = '';
             $catmodel = tmsModel::getModel('category');
             $this->assignRef('catmodel', $catmodel);
             $this->addStandardDefaultViewCommandsNoValidate();
             $this->addStandardDefaultViewLists($catmodel, 'category_name');
             $session = JFactory::getSession();
             $reset = $session->get('reset_pag', false, 'vm');
             $limit = '';
             if ($reset) {
                 $limit = 0;
                 $session->set('reset_pag', false, 'vm');
             }
             $this->categories = $catmodel->getCategoryTree(0, 0, false, $this->lists['search'], $limit);
             $catpagination = $catmodel->getPagination();
             $this->assignRef('catpagination', $catpagination);
             $this->setLayout('massxref');
             JToolBarHelper::custom('massxref_cats_exe', 'new', 'new', tsmText::_('com_tsmart_PRODUCT_XREF_CAT_EXE'), false);
             break;
         case 'massxref_sgrps':
         case 'massxref_sgrps_exe':
             $sgrpmodel = tmsModel::getModel('shoppergroup');
             $this->addStandardDefaultViewLists($sgrpmodel);
             $shoppergroups = $sgrpmodel->getShopperGroups(false, true);
             $this->assignRef('shoppergroups', $shoppergroups);
             $sgrppagination = $sgrpmodel->getPagination();
             $this->assignRef('sgrppagination', $sgrppagination);
             $this->setLayout('massxref');
             JToolBarHelper::custom('massxref_sgrps_exe', 'new', 'new', tsmText::_('com_tsmart_PRODUCT_XREF_SGRPS_EXE'), false);
             break;
         default:
             if ($product_parent_id = vRequest::getInt('product_parent_id', false)) {
                 $product_parent = $model->getProductSingle($product_parent_id, false);
                 if ($product_parent) {
                     $title = 'PRODUCT_CHILDREN_LIST';
                     $link_to_parent = JHtml::_('link', JRoute::_('index.php?view=product&task=edit&tsmart_product_id=' . $product_parent->tsmart_product_id . '&option=com_tsmart'), $product_parent->product_name, array('title' => tsmText::_('com_tsmart_EDIT_PARENT') . ' ' . $product_parent->product_name));
                     $msg = tsmText::_('com_tsmart_PRODUCT_OF') . " " . $link_to_parent;
                 } else {
                     $title = 'PRODUCT_CHILDREN_LIST';
                     $msg = 'Parent with product_parent_id ' . $product_parent_id . ' not found';
                 }
             } else {
                 $title = 'PRODUCT';
                 $msg = "";
             }
             $this->SetViewTitle($title, $msg);
             $this->addStandardDefaultViewLists($model, 'created_on');
             if ($cI = vRequest::getInt('tsmart_category_id', false)) {
                 $app = JFactory::getApplication();
                 //$old_state = $app->getUserState('tsmart_category_id');
                 $old_state = $app->getUserState('tsmart_category_id');
                 if (empty($old_state) or $old_state != $cI) {
                     vRequest::setVar('com_tsmart.product.filter_order', 'pc.ordering');
                     $model->filter_order = 'pc.ordering';
                     $old_state = $app->setUserState('tsmart_category_id', $cI);
                 }
             }
             //Get the list of products
             $productlist = $model->getItemList();
             //The pagination must now always set AFTER the model load the listing
             $this->pagination = $model->getPagination();
             //Get the category tree
             $categoryId = $model->tsmart_category_id;
             //OSP switched to filter in model, was vRequest::getInt('tsmart_category_id');
             $category_tree = ShopFunctions::categoryListTree(array($categoryId));
             $this->assignRef('category_tree', $category_tree);
             //load service class
             //Load the product price
             if (!class_exists('calculationHelper')) {
                 require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
             }
             $vendor_model = tmsModel::getModel('vendor');
             $productreviews = tmsModel::getModel('ratings');
             $this->mfTable = $model->getTable('manufacturers');
             $this->catTable = $model->getTable('categories');
             $this->lists['vendors'] = '';
             if ($this->showVendors()) {
                 $this->lists['vendors'] = Shopfunctions::renderVendorList(vmAccess::getVendorId());
             }
             foreach ($productlist as $tsmart_product_id => $product) {
                 $product->mediaitems = count($product->tsmart_media_id);
                 $product->reviews = $productreviews->countReviewsForProduct($product->tsmart_product_id);
                 $vendor_model->setId($product->tsmart_vendor_id);
                 $vendor = $vendor_model->getVendor();
                 $currencyDisplay = CurrencyDisplay::getInstance($vendor->vendor_currency, $vendor->tsmart_vendor_id);
                 if (!empty($product->allPrices[$product->selectedPrice]['product_price']) && !empty($product->allPrices[$product->selectedPrice]['product_currency'])) {
                     $product->product_price_display = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['product_price'], (int) $product->allPrices[$product->selectedPrice]['product_currency'], 1, true);
                 } else {
                     if (!empty($product->allPrices) and count($product->allPrices) > 1) {
                         $product->product_price_display = tsmText::_('com_tsmart_MULTIPLE_PRICES');
                     } else {
                         $product->product_price_display = tsmText::_('com_tsmart_NO_PRICE_SET');
                     }
                 }
                 // Write the first 5 categories in the list
                 $product->categoriesList = '';
                 if (!empty($product->categories[0])) {
                     $product->categoriesList = shopfunctions::renderGuiList($product->categories, 'categories', 'category_name', 'category');
                 }
                 // Write the first 5 manufacturers in the list
                 $product->manuList = '';
                 if (!empty($product->tsmart_manufacturer_id[0])) {
                     $product->manuList = shopfunctions::renderGuiList($product->tsmart_manufacturer_id, 'manufacturers', 'mf_name', 'manufacturer');
                 }
             }
             $mf_model = tmsModel::getModel('manufacturer');
             $manufacturers = $mf_model->getManufacturerDropdown();
             $this->assignRef('manufacturers', $manufacturers);
             /* add Search filter in lists*/
             /* Search type */
             $options = array('' => tsmText::_('com_tsmart_LIST_EMPTY_OPTION'), 'parent' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_PARENT_PRODUCT'), 'product' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_PRODUCT'), 'price' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_PRICE'), 'withoutprice' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_WITHOUTPRICE'));
             $this->lists['search_type'] = VmHTML::selectList('search_type', vRequest::getVar('search_type'), $options);
             /* Search order */
             $options = array('bf' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_DATE_BEFORE'), 'af' => tsmText::_('com_tsmart_PRODUCT_LIST_SEARCH_BY_DATE_AFTER'));
             $this->lists['search_order'] = VmHTML::selectList('search_order', vRequest::getVar('search_order'), $options);
             // Toolbar
             /*if (vmAccess::manager('product.edit')) {
                   JToolBarHelper::custom('massxref_cats', 'new', 'new', vmText::_('com_tsmart_PRODUCT_XREF_CAT'), true);
                   JToolBarHelper::custom('massxref_sgrps', 'new', 'new', vmText::_('com_tsmart_PRODUCT_XREF_SGRPS'), true);
               }
               if (vmAccess::manager('product.create')) {
                   JToolBarHelper::custom('createchild', 'new', 'new', vmText::_('com_tsmart_PRODUCT_CHILD'), true);
                   JToolBarHelper::custom('cloneproduct', 'copy', 'copy', vmText::_('com_tsmart_PRODUCT_CLONE'), true);
               }*/
             // JToolBarHelper::custom('addrating', 'default', '', vmText::_('com_tsmart_ADD_RATING'), true);
             $view = vRequest::getCmd('view', vRequest::getCmd('controller', 'tsmart'));
             JToolBarHelper::divider();
             if (vmAccess::manager($view . '.edit.state')) {
                 JToolBarHelper::publishList();
                 JToolBarHelper::unpublishList();
             }
             if (vmAccess::manager($view . '.delete')) {
                 JToolBarHelper::spacer('10');
                 JToolBarHelper::deleteList();
             }
             $this->assignRef('productlist', $productlist);
             $this->assignRef('tsmart_category_id', $categoryId);
             $this->assignRef('model', $model);
             break;
     }
     parent::display($tpl);
 }
Exemple #7
0
 public function getSwitchUserList($superVendor = null, $adminID = false)
 {
     if (!isset($superVendor)) {
         $superVendor = vmAccess::isSuperVendor();
     }
     $result = false;
     if ($superVendor) {
         $db = JFactory::getDbo();
         $search = vRequest::getUword('usersearch', '');
         if (!empty($search)) {
             $search = ' WHERE (`name` LIKE "%' . $search . '%" OR `username` LIKE "%' . $search . '%" OR `customer_number` LIKE "%' . $search . '%")';
         } else {
             if ($superVendor != 1) {
                 $search = ' WHERE vu.tsmart_vendor_id = ' . $superVendor . ' ';
             }
         }
         $q = 'SELECT ju.`id`,`name`,`username` FROM `#__users` as ju';
         if ($superVendor != 1 or !empty($search)) {
             $q .= ' LEFT JOIN #__tsmart_vmusers AS vmu ON vmu.tsmart_user_id = ju.id';
             if ($superVendor != 1) {
                 $q .= ' LEFT JOIN #__tsmart_vendor_users AS vu ON vu.tsmart_user_id = ju.id';
                 $search .= ' AND ( vmu.user_is_vendor = 0 OR (vmu.tsmart_vendor_id) IS NULL)';
             }
         }
         $current = JFactory::getUser();
         $hiddenUserID = $adminID ? $adminID : $current->id;
         if (!empty($search)) {
             $search .= ' AND ju.id!= "' . $hiddenUserID . '" ';
         } else {
             $q .= ' WHERE ju.id!= "' . $hiddenUserID . '" ';
         }
         $q .= $search . ' ORDER BY `name` LIMIT 0,10000';
         $db->setQuery($q);
         $result = $db->loadObjectList();
         if ($result) {
             foreach ($result as $k => $user) {
                 $result[$k]->displayedName = $user->name . '&nbsp;&nbsp;( ' . $user->username . ' )';
             }
         } else {
             $result = array();
         }
         if ($adminID) {
             $user = JFactory::getUser($adminID);
             if ($current->id != $user->id) {
                 $toAdd = new stdClass();
                 $toAdd->id = $user->id;
                 $toAdd->name = $user->name;
                 $toAdd->username = $user->username;
                 $toAdd->displayedName = tsmText::sprintf('com_tsmart_RETURN_TO', $user->name, $user->username);
                 array_unshift($result, $toAdd);
             }
         }
         $toAdd = new stdClass();
         $toAdd->id = 0;
         $toAdd->name = '';
         $toAdd->username = '';
         $toAdd->displayedName = '-' . tsmText::_('com_tsmart_REGISTER') . '-';
         array_unshift($result, $toAdd);
     }
     return $result;
 }
 /**
  * Save a rating
  * @author  Max Milbers
  */
 public function saveRating($data = 0)
 {
     //Check user_rating
     $maxrating = VmConfig::get('vm_maximum_rating_scale', 5);
     $virtuemart_product_id = vRequest::getInt('virtuemart_product_id', 0);
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         $user = JFactory::getUser();
         $userId = $user->id;
         $allowReview = $this->allowReview($virtuemart_product_id);
         $allowRating = $this->allowRating($virtuemart_product_id);
     } else {
         $userId = $data['created_by'];
         $allowReview = true;
         $allowRating = true;
     }
     if (!empty($virtuemart_product_id)) {
         //if ( !empty($data['virtuemart_product_id']) && !empty($userId)){
         if (empty($data)) {
             $data = vRequest::getPost();
         }
         if ($allowRating) {
             //normalize the rating
             if ($data['vote'] < 0) {
                 $data['vote'] = 0;
             }
             if ($data['vote'] > $maxrating + 1) {
                 $data['vote'] = $maxrating;
             }
             $data['lastip'] = $_SERVER['REMOTE_ADDR'];
             $data['vote'] = (int) $data['vote'];
             $rating = $this->getRatingByProduct($data['virtuemart_product_id']);
             vmdebug('$rating', $rating);
             $vote = $this->getVoteByProduct($data['virtuemart_product_id'], $userId);
             vmdebug('$vote', $vote);
             $data['virtuemart_rating_vote_id'] = empty($vote->virtuemart_rating_vote_id) ? 0 : $vote->virtuemart_rating_vote_id;
             if (isset($data['vote'])) {
                 $votesTable = $this->getTable('rating_votes');
                 $res = $votesTable->bindChecknStore($data, TRUE);
                 if (!$res) {
                     vmError(get_class($this) . '::Error store votes ');
                 }
             }
             if (!empty($rating->rates) && empty($vote)) {
                 $data['rates'] = $rating->rates + $data['vote'];
                 $data['ratingcount'] = $rating->ratingcount + 1;
             } else {
                 if (!empty($rating->rates) && !empty($vote->vote)) {
                     $data['rates'] = $rating->rates - $vote->vote + $data['vote'];
                     $data['ratingcount'] = $rating->ratingcount;
                 } else {
                     $data['rates'] = $data['vote'];
                     $data['ratingcount'] = 1;
                 }
             }
             if (empty($data['rates']) || empty($data['ratingcount'])) {
                 $data['rating'] = 0;
             } else {
                 $data['rating'] = $data['rates'] / $data['ratingcount'];
             }
             $data['virtuemart_rating_id'] = empty($rating->virtuemart_rating_id) ? 0 : $rating->virtuemart_rating_id;
             vmdebug('saveRating $data', $data);
             $rating = $this->getTable('ratings');
             $res = $rating->bindChecknStore($data, TRUE);
             if (!$res) {
                 vmError(get_class($this) . '::Error store rating ');
             }
         }
         if ($allowReview and !empty($data['comment'])) {
             //if(!empty($data['comment'])){
             $data['comment'] = substr($data['comment'], 0, VmConfig::get('vm_reviews_maximum_comment_length', 2000));
             // no HTML TAGS but permit all alphabet
             $value = preg_replace('@<[\\/\\!]*?[^<>]*?>@si', '', $data['comment']);
             //remove all html tags
             $value = (string) preg_replace('#on[a-z](.+?)\\)#si', '', $value);
             //replace start of script onclick() onload()...
             $value = trim(str_replace('"', ' ', $value), "'");
             $data['comment'] = (string) preg_replace('#^\'#si', '', $value);
             //replace ' at start
             $data['comment'] = nl2br($data['comment']);
             // keep returns
             //set to defaut value not used (prevent hack)
             $data['review_ok'] = 0;
             $data['review_rating'] = 0;
             $data['review_editable'] = 0;
             // Check if ratings are auto-published (set to 0 prevent injected by user)
             //
             $app = JFactory::getApplication();
             if ($app->isSite()) {
                 if (VmConfig::get('reviews_autopublish', 1)) {
                     $data['published'] = 1;
                 } else {
                     $model = new VmModel();
                     $product = $model->getTable('products');
                     $product->load($data['virtuemart_product_id']);
                     $vendorId = vmAccess::isSuperVendor();
                     if (!vmAccess::manager() or $vendorId != $product->virtuemart_vendor_id) {
                         $data['published'] = 0;
                     }
                 }
             }
             $review = $this->getProductReviewForUser($data['virtuemart_product_id'], $userId);
             if (!empty($review->review_rates)) {
                 $data['review_rates'] = $review->review_rates + $data['vote'];
             } else {
                 $data['review_rates'] = $data['vote'];
             }
             if (!empty($review->review_ratingcount)) {
                 $data['review_ratingcount'] = $review->review_ratingcount + 1;
             } else {
                 $data['review_ratingcount'] = 1;
             }
             $data['review_rating'] = $data['review_rates'] / $data['review_ratingcount'];
             $data['virtuemart_rating_review_id'] = empty($review->virtuemart_rating_review_id) ? 0 : $review->virtuemart_rating_review_id;
             $reviewTable = $this->getTable('rating_reviews');
             $res = $reviewTable->bindChecknStore($data, TRUE);
             if (!$res) {
                 vmError(get_class($this) . '::Error store review ');
             }
         }
         return $data['virtuemart_rating_review_id'];
     } else {
         vmError('Cant save rating/review/vote without vote/product_id');
         return FALSE;
     }
 }
 /**
  * Collect all data to show on the template
  *
  * @author RolandD, Max Milbers
  */
 function display($tpl = null)
 {
     $show_prices = VmConfig::get('show_prices', 1);
     $this->assignRef('show_prices', $show_prices);
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     if (!empty($menu->id)) {
         ShopFunctionsF::setLastVisitedItemId($menu->id);
     } else {
         if ($itemId = vRequest::getInt('Itemid', false)) {
             ShopFunctionsF::setLastVisitedItemId($itemId);
         }
     }
     $pathway = $app->getPathway();
     $task = vRequest::getCmd('task');
     if (!class_exists('VmImage')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'image.php';
     }
     // Load the product
     //$product = $this->get('product');	//Why it is sensefull to use this construction? Imho it makes it just harder
     $product_model = VmModel::getModel('product');
     $this->assignRef('product_model', $product_model);
     $virtuemart_product_idArray = vRequest::getInt('virtuemart_product_id', 0);
     if (is_array($virtuemart_product_idArray) and count($virtuemart_product_idArray) > 0) {
         $virtuemart_product_id = (int) $virtuemart_product_idArray[0];
     } else {
         $virtuemart_product_id = (int) $virtuemart_product_idArray;
     }
     $quantityArray = vRequest::getInt('quantity', array());
     //is sanitized then
     $quantity = 1;
     if (!empty($quantityArray[0])) {
         $quantity = $quantityArray[0];
     }
     $ratingModel = VmModel::getModel('ratings');
     $product_model->withRating = $this->showRating = $ratingModel->showRating($virtuemart_product_id);
     $product = $product_model->getProduct($virtuemart_product_id, TRUE, TRUE, TRUE, $quantity);
     if (!class_exists('shopFunctionsF')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
     }
     $last_category_id = shopFunctionsF::getLastVisitedCategoryId();
     $customfieldsModel = VmModel::getModel('Customfields');
     if ($product->customfields) {
         if (!class_exists('vmCustomPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php';
         }
         $customfieldsModel->displayProductCustomfieldFE($product, $product->customfields);
     }
     if (empty($product->slug)) {
         //Todo this should be redesigned to fit better for SEO
         $app->enqueueMessage(vmText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND'));
         $categoryLink = '';
         if (!$last_category_id) {
             $last_category_id = vRequest::getInt('virtuemart_category_id', false);
         }
         if ($last_category_id) {
             $categoryLink = '&virtuemart_category_id=' . $last_category_id;
         }
         if (VmConfig::get('handle_404', 1)) {
             $app->redirect(JRoute::_('index.php?option=com_virtuemart&view=category' . $categoryLink . '&error=404', FALSE));
         } else {
             JError::raise(E_ERROR, '404', 'Not found');
         }
         return;
     }
     $isCustomVariant = false;
     if (!empty($product->customfields)) {
         foreach ($product->customfields as $k => $custom) {
             if ($custom->field_type == 'C' and $custom->virtuemart_product_id != $virtuemart_product_id) {
                 $isCustomVariant = $custom;
             }
             if (!empty($custom->layout_pos)) {
                 $product->customfieldsSorted[$custom->layout_pos][] = $custom;
             } else {
                 $product->customfieldsSorted['normal'][] = $custom;
             }
             unset($product->customfields);
         }
     }
     $product->event = new stdClass();
     $product->event->afterDisplayTitle = '';
     $product->event->beforeDisplayContent = '';
     $product->event->afterDisplayContent = '';
     if (VmConfig::get('enable_content_plugin', 0)) {
         shopFunctionsF::triggerContentPlugin($product, 'productdetails', 'product_desc');
     }
     $product_model->addImages($product);
     if (isset($product->min_order_level) && (int) $product->min_order_level > 0) {
         $this->min_order_level = $product->min_order_level;
     } else {
         $this->min_order_level = 1;
     }
     if (isset($product->step_order_level) && (int) $product->step_order_level > 0) {
         $this->step_order_level = $product->step_order_level;
     } else {
         $this->step_order_level = 1;
     }
     // Load the neighbours
     if (VmConfig::get('product_navigation', 1)) {
         $product->neighbours = $product_model->getNeighborProducts($product);
     }
     $this->assignRef('product', $product);
     if (VmConfig::get('show_manufacturers', 1) && !empty($this->product->virtuemart_manufacturer_id)) {
         $manModel = VmModel::getModel('manufacturer');
         $mans = array();
         // Gebe die Hersteller aus
         foreach ($this->product->virtuemart_manufacturer_id as $manufacturer_id) {
             $manufacturer = $manModel->getManufacturer($manufacturer_id);
             $manModel->addImages($manufacturer, 1);
             $mans[] = $manufacturer;
         }
         $this->product->manufacturers = $mans;
     }
     // Load the category
     $category_model = VmModel::getModel('category');
     shopFunctionsF::setLastVisitedCategoryId($product->virtuemart_category_id);
     if ($category_model) {
         $category = $category_model->getCategory($product->virtuemart_category_id);
         $category_model->addImages($category, 1);
         $this->assignRef('category', $category);
         //Seems we dont need this anylonger, destroyed the breadcrumb
         if ($category->parents) {
             foreach ($category->parents as $c) {
                 if (is_object($c) and isset($c->category_name)) {
                     $pathway->addItem(strip_tags(vmText::_($c->category_name)), JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $c->virtuemart_category_id, FALSE));
                 } else {
                     vmdebug('Error, parent category has no name, breadcrumb maybe broken, category', $c);
                 }
             }
         }
         $category->children = $category_model->getChildCategoryList($product->virtuemart_vendor_id, $product->virtuemart_category_id);
         $category_model->addImages($category->children, 1);
     }
     $pathway->addItem(strip_tags(html_entity_decode($product->product_name, ENT_QUOTES)));
     if (!empty($tpl)) {
         $format = $tpl;
     } else {
         $format = vRequest::getCmd('format', 'html');
     }
     if ($format == 'html') {
         // remove joomla canonical before adding it
         foreach ($document->_links as $k => $array) {
             if ($array['relation'] == 'canonical') {
                 unset($document->_links[$k]);
                 break;
             }
         }
         // Set Canonic link
         if ($isCustomVariant !== false and !empty($isCustomVariant->usecanonical) and !empty($product->product_parent_id)) {
             $parent = $product_model->getProduct($product->product_parent_id);
             $document->addHeadLink($parent->canonical, 'canonical', 'rel', '');
         } else {
             $document->addHeadLink($product->canonical, 'canonical', 'rel', '');
         }
     } else {
         if ($format == 'pdf') {
             defined('K_PATH_IMAGES') or define('K_PATH_IMAGES', VMPATH_ROOT);
         }
     }
     // Set the titles
     // $document->setTitle should be after the additem pathway
     if ($product->customtitle) {
         $document->setTitle(strip_tags(html_entity_decode($product->customtitle, ENT_QUOTES)));
     } else {
         $document->setTitle(strip_tags(html_entity_decode(($category->category_name ? vmText::_($category->category_name) . ' : ' : '') . $product->product_name, ENT_QUOTES)));
     }
     $this->allowReview = $ratingModel->allowReview($product->virtuemart_product_id);
     $this->showReview = $ratingModel->showReview($product->virtuemart_product_id);
     $this->rating_reviews = '';
     if ($this->showReview) {
         $this->review = $ratingModel->getReviewByProduct($product->virtuemart_product_id);
         $this->rating_reviews = $ratingModel->getReviews($product->virtuemart_product_id);
     }
     if ($this->showRating) {
         $this->vote = $ratingModel->getVoteByProduct($product->virtuemart_product_id);
     }
     $this->allowRating = $ratingModel->allowRating($product->virtuemart_product_id);
     $superVendor = vmAccess::isSuperVendor();
     if ($superVendor == 1 or $superVendor == $product->virtuemart_vendor_id or $superVendor) {
         $edit_link = JURI::root() . 'index.php?option=com_virtuemart&tmpl=component&manage=1&view=product&task=edit&virtuemart_product_id=' . $product->virtuemart_product_id;
         $this->edit_link = $this->linkIcon($edit_link, 'COM_VIRTUEMART_PRODUCT_FORM_EDIT_PRODUCT', 'edit', false, false);
     } else {
         $this->edit_link = "";
     }
     // Load the user details
     $this->user = JFactory::getUser();
     // More reviews link
     $uri = JURI::getInstance();
     $uri->setVar('showall', 1);
     $uristring = vmURI::getCleanUrl();
     $this->assignRef('more_reviews', $uristring);
     if ($product->metadesc) {
         $document->setDescription(strip_tags(html_entity_decode($product->metadesc, ENT_QUOTES)));
     } else {
         $document->setDescription(strip_tags(html_entity_decode($product->product_name, ENT_QUOTES)) . " " . $category->category_name . " " . strip_tags(html_entity_decode($product->product_s_desc, ENT_QUOTES)));
     }
     if ($product->metakey) {
         $document->setMetaData('keywords', $product->metakey);
     }
     if ($product->metarobot) {
         $document->setMetaData('robots', $product->metarobot);
     }
     if ($app->getCfg('MetaTitle') == '1') {
         $document->setMetaData('title', $product->product_name);
         //Maybe better product_name
     }
     if ($app->getCfg('MetaAuthor') == '1') {
         $document->setMetaData('author', $product->metaauthor);
     }
     $user = JFactory::getUser();
     $showBasePrice = (vmAccess::manager() or vmAccess::isSuperVendor());
     $this->assignRef('showBasePrice', $showBasePrice);
     $productDisplayShipments = array();
     $productDisplayPayments = array();
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     JPluginHelper::importPlugin('vmshipment');
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $returnValues = $dispatcher->trigger('plgVmOnProductDisplayShipment', array($product, &$productDisplayShipments));
     $returnValues = $dispatcher->trigger('plgVmOnProductDisplayPayment', array($product, &$productDisplayPayments));
     $this->assignRef('productDisplayPayments', $productDisplayPayments);
     $this->assignRef('productDisplayShipments', $productDisplayShipments);
     if (empty($category->category_template)) {
         $category->category_template = VmConfig::get('categorytemplate');
     }
     shopFunctionsF::setVmTemplate($this, $category->category_template, $product->product_template, $category->category_product_layout, $product->layout);
     shopFunctionsF::addProductToRecent($virtuemart_product_id);
     $currency = CurrencyDisplay::getInstance();
     $this->assignRef('currency', $currency);
     if (vRequest::getCmd('layout', 'default') == 'notify') {
         $this->setLayout('notify');
     }
     //Added by Seyi Awofadeju to catch notify layout
     VmConfig::loadJLang('com_virtuemart');
     vmJsApi::chosenDropDowns();
     //This must be loaded after the customfields are rendered (they may need to overwrite the handlers)
     if (VmConfig::get('jdynupdate', TRUE) or $app->isAdmin()) {
         vmJsApi::jDynUpdate();
     }
     if ($show_prices == '1') {
         if (!class_exists('calculationHelper')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
         }
         vmJsApi::jPrice();
     }
     parent::display($tpl);
 }
Exemple #10
0
 /**
  * @author Max Milbers
  * @param
  */
 function check()
 {
     if (!empty($this->_slugAutoName)) {
         $slugAutoName = $this->_slugAutoName;
         $slugName = $this->_slugName;
         if (in_array($slugAutoName, $this->_translatableFields)) {
             $checkTable = $this->_tbl_lang;
             vmTrace('Language table in normal check?');
         } else {
             $checkTable = $this->_tbl;
         }
         if (empty($this->{$slugName})) {
             // 				vmdebug('table check use _slugAutoName '.$slugAutoName.' '.$slugName);
             if (!empty($this->{$slugAutoName})) {
                 $this->{$slugName} = $this->{$slugAutoName};
             } else {
                 $pkey = $this->_pkey;
                 vmError('VmTable ' . $checkTable . ' Check not passed. Neither slug nor obligatory value at ' . $slugAutoName . ' for auto slug creation is given ' . $this->{$pkey});
                 return false;
             }
         }
         //if (JVM_VERSION === 1) $this->$slugName = JFilterOutput::stringURLSafe($this->$slugName);
         //else $this->$slugName = JApplication::stringURLSafe($this->$slugName);
         //pro+#'!"§$%&/()=?duct-w-| ||cu|st|omfield-|str<ing>
         //vmdebug('my slugName '.$slugName,$this->$slugName);
         $this->{$slugName} = str_replace('-', ' ', $this->{$slugName});
         $this->{$slugName} = html_entity_decode($this->{$slugName}, ENT_QUOTES);
         //$config =& JFactory::getConfig();
         //$transliterate = $config->get('unicodeslugs');
         $unicodeslugs = tsmConfig::get('transliterateSlugs', false);
         if ($unicodeslugs) {
             $lang = JFactory::getLanguage();
             $this->{$slugName} = $lang->transliterate($this->{$slugName});
         }
         // Trim white spaces at beginning and end of alias and make lowercase
         $this->{$slugName} = trim(JString::strtolower($this->{$slugName}));
         $this->{$slugName} = str_replace(array('`', '´', "'"), '', $this->{$slugName});
         $this->{$slugName} = vRequest::filterUword($this->{$slugName}, '-,_,|', '-');
         while (strpos($this->{$slugName}, '--')) {
             $this->{$slugName} = str_replace('--', '-', $this->{$slugName});
         }
         // Trim dashes at beginning and end of alias
         $this->{$slugName} = trim($this->{$slugName}, '-');
         if ($unicodeslugs) {
             $this->{$slugName} = rawurlencode($this->{$slugName});
         }
         $valid = $this->checkCreateUnique($checkTable, $slugName);
         //vmdebug('my Final slugName '.$slugName,$this->$slugName);
         if (!$valid) {
             return false;
         }
     }
     foreach ($this->_obkeys as $obkeys => $error) {
         if (empty($this->{$obkeys})) {
             $error = get_class($this) . ' ' . tsmText::sprintf('com_tsmart_STRING_ERROR_OBLIGATORY_KEY', 'com_tsmart_' . strtoupper($obkeys));
             vmError($error);
             return false;
         }
     }
     if ($this->_unique) {
         if (empty($this->_db)) {
             $this->_db = JFactory::getDBO();
         }
         foreach ($this->_unique_name as $obkeys => $error) {
             if (empty($this->{$obkeys})) {
                 $error = tsmText::sprintf('com_tsmart_STRING_ERROR_NOT_UNIQUE_NAME', 'com_tsmart_' . strtoupper($obkeys));
                 vmError('Non unique ' . $this->_unique_name . ' ' . $error);
                 return false;
             } else {
                 $valid = $this->checkCreateUnique($this->_tbl, $obkeys);
                 if (!$valid) {
                     return false;
                 }
             }
         }
     }
     if (property_exists($this, 'tsmart_vendor_id')) {
         if (empty($this->tsmart_vendor_id) and $this->_pkey == 'tsmart_vendor_id') {
             $this->tsmart_vendor_id = $this->_pvalue;
         }
         $multix = tsmConfig::get('multix', 'none');
         //Lets check if the user is admin or the mainvendor
         $tsmart_vendor_id = false;
         //Todo removed Quickn Dirty, use check in derived class
         if ($multix == 'none' and get_class($this) !== 'TableVmusers') {
             $this->tsmart_vendor_id = 1;
             return true;
         } else {
             $loggedVendorId = vmAccess::isSuperVendor();
             $user = JFactory::getUser();
             $tbl_key = $this->_tbl_key;
             $className = get_class($this);
             $admin = vmAccess::manager('managevendors');
             //Todo removed Quickn Dirty, use check in derived class
             if (strpos($this->_tbl, 'tsmart_vmusers') === FALSE) {
                 $q = 'SELECT `tsmart_vendor_id` FROM `' . $this->_tbl . '` WHERE `' . $this->_tbl_key . '`="' . $this->{$tbl_key} . '" ';
                 if (!isset(self::$_cache[md5($q)])) {
                     $this->_db->setQuery($q);
                     self::$_cache[md5($q)] = $tsmart_vendor_id = $this->_db->loadResult();
                 } else {
                     $tsmart_vendor_id = self::$_cache[md5($q)];
                 }
             } else {
                 $q = 'SELECT `tsmart_vendor_id`,`user_is_vendor` FROM `' . $this->_tbl . '` WHERE `' . $this->_tbl_key . '`="' . $this->{$tbl_key} . '" ';
                 if (!isset(self::$_cache[md5($q)])) {
                     $this->_db->setQuery($q);
                     $vmuser = $this->_db->loadRow();
                     self::$_cache[md5($q)] = $vmuser;
                 } else {
                     $vmuser = self::$_cache[md5($q)];
                 }
                 if ($vmuser and count($vmuser) === 2) {
                     $tsmart_vendor_id = $vmuser[0];
                     $user_is_vendor = $vmuser[1];
                     if ($multix == 'none') {
                         if (empty($user_is_vendor)) {
                             $this->tsmart_vendor_id = 0;
                         } else {
                             $this->tsmart_vendor_id = 1;
                         }
                         return true;
                     } else {
                         if (!$admin) {
                             $rVendorId = vmAccess::isSuperVendor($user->id);
                             $this->tsmart_vendor_id = $rVendorId;
                             return true;
                         }
                     }
                 } else {
                     //New User
                     //vmInfo('We run in multivendor mode and you did not set any vendor for '.$className.' and '.$this->_tbl);//, Set to mainvendor '.$this->tsmart_vendor_id
                 }
             }
             if (!$admin and !empty($tsmart_vendor_id) and !empty($loggedVendorId) and $loggedVendorId != $tsmart_vendor_id) {
                 //Todo removed Quickn Dirty, use check in derived class
                 //This is the case when a vendor buys products of vendor1
                 if (strpos($this->_tbl, 'tsmart_order_items') === FALSE and strpos($this->_tbl, 'tsmart_carts') === FALSE) {
                     vmdebug('Blocked storing, logged vendor ' . $loggedVendorId . ' but data belongs to ' . $tsmart_vendor_id, $this->_tbl);
                     return false;
                 } else {
                     $this->tsmart_vendor_id = $tsmart_vendor_id;
                 }
             } else {
                 if (!$admin) {
                     if ($tsmart_vendor_id) {
                         $this->tsmart_vendor_id = $tsmart_vendor_id;
                         vmdebug('Non admin is storing using loaded vendor_id');
                     } else {
                         if (empty($this->tsmart_vendor_id)) {
                             $this->tsmart_vendor_id = $loggedVendorId;
                         }
                         //No id is stored, even users are allowed to use for the storage and vendorId, no change
                     }
                 } else {
                     //Admins are allowed to do anything. We just trhow some messages
                     if (!empty($tsmart_vendor_id) and $loggedVendorId != $tsmart_vendor_id) {
                         vmdebug('Admin with vendor id ' . $loggedVendorId . ' is using for storing vendor id ' . $this->tsmart_vendor_id);
                     } else {
                         if (empty($tsmart_vendor_id) and empty($this->tsmart_vendor_id)) {
                             if (strpos($this->_tbl, 'tsmart_vendors') === FALSE and strpos($this->_tbl, 'tsmart_vmusers') === FALSE) {
                                 $this->tsmart_vendor_id = $loggedVendorId;
                                 vmdebug('Fallback to ' . $this->tsmart_vendor_id . ' for $loggedVendorId ' . $loggedVendorId . ': We run in multivendor mode and you did not set any vendor for ' . $className . ' and ' . $this->_tbl);
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
Exemple #11
0
    /**
     * Retrieve a list of files from the database. This is meant only for backend use
     *
     * @author Max Milbers
     * @param boolean $onlyPublished True to only retrieve the published files, false otherwise
     * @param boolean $noLimit True if no record count limit is used, false otherwise
     * @return object List of media objects
     */
    function getFiles($onlyPublished = false, $noLimit = false, $tsmart_product_id = null, $cat_id = null, $where = array(), $nbr = false)
    {
        $this->_noLimit = $noLimit;
        if (empty($db)) {
            $db = JFactory::getDBO();
        }
        $query = '';
        $selectFields = array();
        $joinTables = array();
        $joinedTables = '';
        $whereItems = array();
        $groupBy = '';
        $orderByTable = '';
        if (!empty($tsmart_product_id)) {
            $mainTable = '`#__tsmart_product_medias`';
            $selectFields[] = ' `#__tsmart_medias`.`tsmart_media_id` as tsmart_media_id ';
            $joinTables[] = ' LEFT JOIN `#__tsmart_medias` ON `#__tsmart_medias`.`tsmart_media_id`=`#__tsmart_product_medias`.`tsmart_media_id` and `tsmart_product_id` = "' . $tsmart_product_id . '"';
            $whereItems[] = '`tsmart_product_id` = "' . $tsmart_product_id . '"';
            if ($this->_selectedOrdering == 'ordering') {
                $orderByTable = '`#__tsmart_product_medias`.';
            } else {
                $orderByTable = '`#__tsmart_medias`.';
            }
        } else {
            if (!empty($cat_id)) {
                $mainTable = '`#__tsmart_category_medias`';
                $selectFields[] = ' `#__tsmart_medias`.`tsmart_media_id` as tsmart_media_id';
                $joinTables[] = ' LEFT JOIN `#__tsmart_medias` ON `#__tsmart_medias`.`tsmart_media_id`=`#__tsmart_category_medias`.`tsmart_media_id` and `tsmart_category_id` = "' . $cat_id . '"';
                $whereItems[] = '`tsmart_category_id` = "' . $cat_id . '"';
                if ($this->_selectedOrdering == 'ordering') {
                    $orderByTable = '`#__tsmart_category_medias`.';
                } else {
                    $orderByTable = '`#__tsmart_medias`.';
                }
            } else {
                $mainTable = '`#__tsmart_medias`';
                $selectFields[] = ' `tsmart_media_id` ';
                if (!vmAccess::manager('managevendors')) {
                    $vendorId = vmAccess::isSuperVendor();
                    $whereItems[] = '(`tsmart_vendor_id` = "' . $vendorId . '" OR `shared`="1")';
                }
            }
        }
        if ($onlyPublished) {
            $whereItems[] = '`#__tsmart_medias`.`published` = 1';
        }
        if ($search = vRequest::getString('searchMedia', false)) {
            $search = '"%' . $db->escape($search, true) . '%"';
            $where[] = ' (`file_title` LIKE ' . $search . '
								OR `file_description` LIKE ' . $search . '
								OR `file_meta` LIKE ' . $search . '
								OR `file_url` LIKE ' . $search . '
								OR `file_url_thumb` LIKE ' . $search . '
							) ';
        }
        if ($type = vRequest::getCmd('search_type')) {
            $where[] = 'file_type = "' . $type . '" ';
        }
        if ($role = vRequest::getCmd('search_role')) {
            if ($role == "file_is_downloadable") {
                $where[] = '`file_is_downloadable` = 1';
                $where[] = '`file_is_forSale` = 0';
            } elseif ($role == "file_is_forSale") {
                $where[] = '`file_is_downloadable` = 0';
                $where[] = '`file_is_forSale` = 1';
            } else {
                $where[] = '`file_is_downloadable` = 0';
                $where[] = '`file_is_forSale` = 0';
            }
        }
        if (!empty($where)) {
            $whereItems = array_merge($whereItems, $where);
        }
        if (count($whereItems) > 0) {
            $whereString = ' WHERE ' . implode(' AND ', $whereItems);
        } else {
            $whereString = ' ';
        }
        $orderBy = $this->_getOrdering($orderByTable);
        #
        if (count($selectFields) > 0) {
            $select = implode(', ', $selectFields) . ' FROM ' . $mainTable;
            //$selectFindRows = 'SELECT COUNT(*) FROM '.$mainTable;
            if (count($joinTables) > 0) {
                foreach ($joinTables as $table) {
                    $joinedTables .= $table;
                }
            }
        } else {
            vmError('No select fields given in getFiles', 'No select fields given');
            return false;
        }
        $this->_data = $this->exeSortSearchListQuery(2, $select, $joinedTables, $whereString, $groupBy, $orderBy, '', $nbr);
        if (empty($this->_data)) {
            return array();
        }
        if (!is_array($this->_data)) {
            $this->_data = explode(',', $this->_data);
        }
        $this->_data = $this->createMediaByIds($this->_data);
        return $this->_data;
    }
 /**
  * Retrieve a list of report items from the database.
  *
  * @param string $noLimit True if no record count limit is used, false otherwise
  * @return object List of order objects
  */
 function getRevenue($cache = 0)
 {
     if (!vmAccess::manager('report')) {
         return false;
     }
     $vendorId = vmAccess::isSuperVendor();
     if (vmAccess::manager('managevendors')) {
         $vendorId = vRequest::getInt('virtuemart_vendor_id', $vendorId);
     }
     $orderstates = vRequest::getVar('order_status_code', array('C', 'S'));
     $intervals = vRequest::getCmd('intervals', 'day');
     $filterorders = vRequest::getvar('filter_order', 'intervals');
     $orderdir = vRequest::getCmd('filter_order_Dir', NULL) == 'desc' ? 'desc' : '';
     $virtuemart_product_id = vRequest::getInt('virtuemart_product_id', FALSE);
     if ($cache) {
         $c = JFactory::getCache('com_virtuemart_revenue');
         $c->setCaching(1);
         $c->setLifeTime($cache);
         return $c->call(array('VirtuemartModelReport', 'getRevenueDiag'), $vendorId, $orderstates, $intervals, $filterorders, $orderdir, $virtuemart_product_id, $this->from_period, $this->until_period);
     } else {
         return $this->getRevenueSortListOrderQuery($vendorId, $orderstates, $intervals, $filterorders, $orderdir, $virtuemart_product_id);
     }
 }
Exemple #13
0
 function display($tpl = null)
 {
     // Load the helper(s)
     if (!class_exists('VmHTML')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
     }
     $model = tmsModel::getModel();
     $currentUser = JFactory::getUser();
     tsmConfig::loadJLang('com_tsmart_shoppers', TRUE);
     $task = vRequest::getCmd('task', 'edit');
     if ($task == 'editshop') {
         $isSuperOrVendor = vmAccess::isSuperVendor();
         if (empty($isSuperOrVendor)) {
             JFactory::getApplication()->redirect('index.php?option=com_tsmart', tsmText::_('JERROR_ALERTNOAUTHOR'), 'error');
         } else {
             if (!class_exists('tsmartModelVendor')) {
                 require VMPATH_ADMIN . DS . 'models' . DS . 'vendor.php';
             }
             $userId = tsmartModelVendor::getUserIdByVendorId($isSuperOrVendor);
         }
         $this->SetViewTitle('STORE');
     } else {
         if ($task == 'add') {
             $userId = 0;
         } else {
             $userId = vRequest::getVar('tsmart_user_id', 0);
             if (is_array($userId)) {
                 $userId = $userId[0];
             }
             $this->SetViewTitle('USER');
         }
     }
     $userId = $model->setId($userId);
     //$layoutName = vRequest::getCmd('layout', 'default');
     $layoutName = $this->getLayout();
     if ($layoutName == 'edit' || $layoutName == 'edit_shipto') {
         $editor = JFactory::getEditor();
         if (!class_exists('VmImage')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'image.php';
         }
         $userDetails = $model->getUser();
         if ($task == 'editshop' && $userDetails->user_is_vendor) {
             // 				$model->setCurrent();
             if (!empty($userDetails->vendor->vendor_store_name)) {
                 $this->SetViewTitle('STORE', $userDetails->vendor->vendor_store_name, 'shop_mart');
             } else {
                 $this->SetViewTitle('STORE', tsmText::_('com_tsmart_NEW_VENDOR'), 'shop_mart');
             }
             $vendorid = $userDetails->tsmart_vendor_id;
             if ($vendorid == 1) {
                 $this->checkTCPDFinstalled();
             }
         } else {
             $vendorid = 0;
             $this->SetViewTitle('USER', $userDetails->JUser->get('name'));
         }
         $_new = $userDetails->JUser->get('id') < 1;
         $this->addStandardEditViewCommands($vendorid);
         // User details
         $_contactDetails = $model->getContactDetails();
         $this->lists['canBlock'] = $currentUser->authorise('com_users', 'block user') && $userDetails->JUser->get('id') != $currentUser->get('id');
         // Can't block myself
         $this->lists['canSetMailopt'] = $currentUser->authorise('workflow', 'email_events');
         $this->lists['block'] = JHtml::_('select.booleanlist', 'block', 'class="inputbox"', $userDetails->JUser->get('block'), 'com_tsmart_YES', 'com_tsmart_NO');
         $this->lists['sendEmail'] = JHtml::_('select.booleanlist', 'sendEmail', 'class="inputbox"', $userDetails->JUser->get('sendEmail'), 'com_tsmart_YES', 'com_tsmart_NO');
         $this->lists['params'] = $userDetails->JUser->getParameters(true);
         // Shopper info
         $this->lists['shoppergroups'] = ShopFunctions::renderShopperGroupList($userDetails->shopper_groups, true, 'tsmart_shoppergroup_id');
         $this->lists['vendors'] = '';
         if ($this->showVendors()) {
             $this->lists['vendors'] = ShopFunctions::renderVendorList($userDetails->tsmart_vendor_id);
         }
         $model->setId($userDetails->JUser->get('id'));
         $this->lists['custnumber'] = $model->getCustomerNumberById();
         // Shipment address(es)
         $this->lists['shipTo'] = ShopFunctions::generateStAddressList($this, $model, 'addST');
         $new = false;
         if (vRequest::getInt('new', '0') === 1) {
             $new = true;
         }
         $tsmart_userinfo_id_BT = $model->getBTuserinfo_id($userId);
         $userFieldsArray = $model->getUserInfoInUserFields($layoutName, 'BT', $tsmart_userinfo_id_BT, false);
         $userFieldsBT = $userFieldsArray[$tsmart_userinfo_id_BT];
         // Load the required scripts
         if (count($userFieldsBT['scripts']) > 0) {
             foreach ($userFieldsBT['scripts'] as $_script => $_path) {
                 JHtml::script($_script, $_path);
             }
         }
         // Load the required stylesheets
         if (count($userFieldsBT['links']) > 0) {
             foreach ($userFieldsBT['links'] as $_link => $_path) {
                 JHtml::stylesheet($_link, $_path);
             }
         }
         $this->assignRef('userFieldsBT', $userFieldsBT);
         $this->assignRef('userInfoID', $tsmart_userinfo_id_BT);
         $addrtype = vRequest::getCmd('addrtype');
         $tsmart_userinfo_id = 0;
         if ($layoutName == 'edit_shipto' or $task == 'addST' or $addrtype == 'ST') {
             $tsmart_userinfo_id = vRequest::getString('tsmart_userinfo_id', '0', '');
             $userFieldsArray = $model->getUserInfoInUserFields($layoutName, 'ST', $tsmart_userinfo_id, false);
             if ($new) {
                 $tsmart_userinfo_id = 0;
             } else {
             }
             $userFieldsST = $userFieldsArray[$tsmart_userinfo_id];
             $this->assignRef('shipToFields', $userFieldsST);
             vmdebug('hm ST $tsmart_userinfo_id', $tsmart_userinfo_id);
         }
         $this->assignRef('shipToId', $tsmart_userinfo_id);
         $this->assignRef('new', $new);
         if (!$_new) {
             // Check for existing orders for this user
             $orders = tmsModel::getModel('orders');
             $orderList = $orders->getOrdersList($userDetails->JUser->get('id'), true);
         } else {
             $orderList = null;
         }
         if (count($orderList) > 0 || !empty($userDetails->user_is_vendor)) {
             if (!class_exists('CurrencyDisplay')) {
                 require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
             }
             $currency = CurrencyDisplay::getInstance();
             $this->assignRef('currency', $currency);
         }
         if (!empty($userDetails->user_is_vendor)) {
             $vendorM = tmsModel::getModel('vendor');
             //if(empty($userDetails->vendor->vendor_currency)){
             $vendorCurrency = $vendorM->getVendorCurrency(1);
             if ($vendorCurrency) {
                 $userDetails->vendor->vendor_currency = $vendorCurrency->vendor_currency;
                 vmdebug('No vendor currency given, fallback to main vendor', $userDetails->vendor->vendor_currency);
             }
             //}
             $vendorM->setId($userDetails->tsmart_vendor_id);
             $vendorM->addImages($userDetails->vendor);
             $this->assignRef('vendor', $userDetails->vendor);
             $currencyModel = tmsModel::getModel('currency');
             $_currencies = $currencyModel->getCurrencies();
             $this->assignRef('currencies', $_currencies);
             $configModel = tmsModel::getModel('config');
             $TCPDFFontsList = $configModel->getTCPDFFontsList();
             $this->assignRef('pdfFonts', $TCPDFFontsList);
         }
         $this->assignRef('userDetails', $userDetails);
         $this->assignRef('orderlist', $orderList);
         $this->assignRef('contactDetails', $_contactDetails);
         $this->assignRef('editor', $editor);
     } else {
         JToolBarHelper::divider();
         JToolBarHelper::custom('toggle.user_is_vendor.1', 'publish', '', 'com_tsmart_USER_ISVENDOR');
         JToolBarHelper::custom('toggle.user_is_vendor.0', 'unpublish', '', 'com_tsmart_USER_ISNOTVENDOR');
         JToolBarHelper::divider();
         JToolBarHelper::deleteList();
         JToolBarHelper::editList();
         self::showACLPref('user');
         //This is intentionally, creating new user via BE is buggy and can be done by joomla
         //JToolBarHelper::addNewX();
         $this->addStandardDefaultViewLists($model, 'ju.id');
         $userList = $model->getUserList();
         $this->assignRef('userList', $userList);
         $this->pagination = $model->getPagination();
         $shoppergroupmodel = tmsModel::getModel('shopperGroup');
         $this->defaultShopperGroup = $shoppergroupmodel->getDefault(0)->shopper_group_name;
     }
     if (!empty($this->orderlist)) {
         tsmConfig::loadJLang('com_tsmart_orders', TRUE);
     }
     parent::display($tpl);
 }
 /**
  * Store a product
  *
  * @author Max Milbers
  * @param $product reference
  * @param bool $isChild Means not that the product is child or not. It means if the product should be threated as child
  * @return bool
  */
 public function store(&$product)
 {
     vRequest::vmCheckToken();
     if (!vmAccess::manager('product.edit')) {
         vmError('You are not a vendor or administrator, storing of product cancelled');
         return FALSE;
     }
     if ($product) {
         $data = (array) $product;
     }
     $isChild = FALSE;
     if (!empty($data['isChild'])) {
         $isChild = $data['isChild'];
     }
     if (isset($data['intnotes'])) {
         $data['intnotes'] = trim($data['intnotes']);
     }
     // Setup some place holders
     $product_data = $this->getTable('products');
     if (!empty($data['virtuemart_product_id'])) {
         $product_data->load($data['virtuemart_product_id']);
     }
     if ((empty($data['virtuemart_product_id']) or empty($product_data->virtuemart_product_id)) and !vmAccess::manager('product.create')) {
         vmWarn('Insufficient permission to create product');
         return false;
     }
     if (!vmAccess::manager('product.edit.state')) {
         if (empty($data['virtuemart_product_id']) or empty($product_data->virtuemart_product_id)) {
             $data['published'] = 0;
         } else {
             $data['published'] = $product_data->published;
         }
     }
     //Set the decimals like product packaging
     foreach ($this->decimals as $decimal) {
         if (array_key_exists($decimal, $data)) {
             if (!empty($data[$decimal])) {
                 $data[$decimal] = str_replace(',', '.', $data[$decimal]);
                 //vmdebug('Store product '.$data['virtuemart_product_id'].', set $decimal '.$decimal.' = '.$data[$decimal]);
             } else {
                 $data[$decimal] = null;
                 $product_data->{$decimal} = null;
                 //vmdebug('Store product '.$data['virtuemart_product_id'].', set $decimal '.$decimal.' = null');
             }
         }
     }
     //We prevent with this line, that someone is storing a product as its own parent
     if (!empty($product_data->product_parent_id) and $product_data->product_parent_id == $data['virtuemart_product_id']) {
         $product_data->product_parent_id = 0;
     }
     $stored = $product_data->bindChecknStore($data, false);
     if (!$stored) {
         vmError('You are not an administrator or the correct vendor, storing of product cancelled');
         return FALSE;
     }
     $this->_id = $data['virtuemart_product_id'] = (int) $product_data->virtuemart_product_id;
     if (empty($this->_id)) {
         vmError('Product not stored, no id');
         return FALSE;
     }
     //We may need to change this, the reason it is not in the other list of commands for parents
     if (!$isChild) {
         $modelCustomfields = VmModel::getModel('Customfields');
         $modelCustomfields->storeProductCustomfields('product', $data, $product_data->virtuemart_product_id);
     }
     // Get old IDS
     $old_price_ids = $this->loadProductPrices($this->_id, array(0), false);
     if (isset($data['mprices']['product_price']) and count($data['mprices']['product_price']) > 0) {
         foreach ($data['mprices']['product_price'] as $k => $product_price) {
             $pricesToStore = array();
             $pricesToStore['virtuemart_product_id'] = $this->_id;
             $pricesToStore['virtuemart_product_price_id'] = (int) $data['mprices']['virtuemart_product_price_id'][$k];
             if (!$isChild) {
                 //$pricesToStore['basePrice'] = $data['mprices']['basePrice'][$k];
                 $pricesToStore['product_override_price'] = $data['mprices']['product_override_price'][$k];
                 $pricesToStore['override'] = isset($data['mprices']['override'][$k]) ? (int) $data['mprices']['override'][$k] : 0;
                 $pricesToStore['virtuemart_shoppergroup_id'] = (int) $data['mprices']['virtuemart_shoppergroup_id'][$k];
                 $pricesToStore['product_tax_id'] = (int) $data['mprices']['product_tax_id'][$k];
                 $pricesToStore['product_discount_id'] = (int) $data['mprices']['product_discount_id'][$k];
                 $pricesToStore['product_currency'] = (int) $data['mprices']['product_currency'][$k];
                 $pricesToStore['product_price_publish_up'] = $data['mprices']['product_price_publish_up'][$k];
                 $pricesToStore['product_price_publish_down'] = $data['mprices']['product_price_publish_down'][$k];
                 $pricesToStore['price_quantity_start'] = (int) $data['mprices']['price_quantity_start'][$k];
                 $pricesToStore['price_quantity_end'] = (int) $data['mprices']['price_quantity_end'][$k];
             }
             if (!$isChild and isset($data['mprices']['use_desired_price'][$k]) and $data['mprices']['use_desired_price'][$k] == "1") {
                 if (!class_exists('calculationHelper')) {
                     require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
                 }
                 $calculator = calculationHelper::getInstance();
                 $pricesToStore['salesPrice'] = $data['mprices']['salesPrice'][$k];
                 $pricesToStore['product_price'] = $data['mprices']['product_price'][$k] = $calculator->calculateCostprice($this->_id, $pricesToStore);
                 unset($data['mprices']['use_desired_price'][$k]);
             } else {
                 if (isset($data['mprices']['product_price'][$k])) {
                     $pricesToStore['product_price'] = $data['mprices']['product_price'][$k];
                 }
             }
             if ($isChild) {
                 $childPrices = $this->loadProductPrices($this->_id, array(0), false);
             }
             if ((isset($pricesToStore['product_price']) and $pricesToStore['product_price'] != '' and $pricesToStore['product_price'] !== '0') || (isset($childPrices) and count($childPrices) > 1)) {
                 if ($isChild) {
                     if (is_array($old_price_ids) and count($old_price_ids) > 1) {
                         //We do not touch multiple child prices. Because in the parent list, we see no price, the gui is
                         //missing to reflect the information properly.
                         $pricesToStore = false;
                         $old_price_ids = array();
                     } else {
                         unset($data['mprices']['product_override_price'][$k]);
                         unset($pricesToStore['product_override_price']);
                         unset($data['mprices']['override'][$k]);
                         unset($pricesToStore['override']);
                     }
                 }
                 if ($pricesToStore) {
                     $toUnset = array();
                     if (!empty($old_price_ids) and count($old_price_ids)) {
                         foreach ($old_price_ids as $key => $oldprice) {
                             if ($pricesToStore['virtuemart_product_price_id'] == $oldprice['virtuemart_product_price_id']) {
                                 $pricesToStore = array_merge($oldprice, $pricesToStore);
                                 $toUnset[] = $key;
                             }
                         }
                     }
                     $this->updateXrefAndChildTables($pricesToStore, 'product_prices', $isChild);
                     foreach ($toUnset as $key) {
                         unset($old_price_ids[$key]);
                     }
                 }
             }
         }
     }
     if (!empty($old_price_ids) and count($old_price_ids)) {
         $oldPriceIdsSql = array();
         foreach ($old_price_ids as $oldPride) {
             $oldPriceIdsSql[] = $oldPride['virtuemart_product_price_id'];
         }
         $db = JFactory::getDbo();
         // delete old unused Prices
         $db->setQuery('DELETE FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_price_id` in ("' . implode('","', $oldPriceIdsSql) . '") ');
         $db->execute();
         $err = $db->getErrorMsg();
         if (!empty($err)) {
             vmWarn('In store prodcut, deleting old price error', $err);
         }
     }
     if (!empty($data['childs'])) {
         foreach ($data['childs'] as $productId => $child) {
             if ($productId != $data['virtuemart_product_id']) {
                 if (empty($child['product_parent_id'])) {
                     $child['product_parent_id'] = $data['virtuemart_product_id'];
                 }
                 $child['virtuemart_product_id'] = $productId;
                 if (!empty($child['product_parent_id']) and $child['product_parent_id'] == $child['virtuemart_product_id']) {
                     $child['product_parent_id'] = 0;
                 }
                 $child['isChild'] = $this->_id;
                 $this->store($child);
             }
         }
     }
     if (!$isChild) {
         $data = $this->updateXrefAndChildTables($data, 'product_shoppergroups');
         $data = $this->updateXrefAndChildTables($data, 'product_manufacturers');
         if (!empty($data['categories']) && count($data['categories']) > 0) {
             if (VmConfig::get('multix', 'none') != 'none' and !vmAccess::manager('managevendors')) {
                 $vendorId = vmAccess::isSuperVendor();
                 $vM = VmModel::getModel('vendor');
                 $ven = $vM->getVendor($vendorId);
                 if ($ven->max_cats_per_product >= 0) {
                     while ($ven->max_cats_per_product < count($data['categories'])) {
                         array_pop($data['categories']);
                     }
                 }
             }
             $data['virtuemart_category_id'] = $data['categories'];
         } else {
             $data['virtuemart_category_id'] = array();
         }
         $data = $this->updateXrefAndChildTables($data, 'product_categories');
         // Update waiting list
         //TODO what is this doing?
         if (!empty($data['notify_users'])) {
             if ($data['product_in_stock'] > 0 && $data['notify_users'] == '1') {
                 $waitinglist = VmModel::getModel('Waitinglist');
                 $waitinglist->notifyList($data['virtuemart_product_id']);
             }
         }
         // Process the images
         $mediaModel = VmModel::getModel('Media');
         $mediaModel->storeMedia($data, 'product');
     }
     $cache = JFactory::getCache('com_virtuemart_cat_manus', 'callback');
     $cache->clean();
     return $product_data->virtuemart_product_id;
 }
Exemple #15
0
    public function getCategories($onlyPublished = true, $parentId = false, $childId = false, $keyword = "", $vendorId = false)
    {
        static $cats = array();
        $select = ' c.`virtuemart_category_id`, category_description, category_name, c.`ordering`, c.`published`, cx.`category_child_id`, cx.`category_parent_id`, c.`shared` ';
        $joinedTables = ' FROM `#__virtuemart_categories_' . VmConfig::$vmlang . '` l
				  JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`)
				  LEFT JOIN `#__virtuemart_category_categories` AS cx
				  ON l.`virtuemart_category_id` = cx.`category_child_id` ';
        $where = array();
        if ($onlyPublished) {
            $where[] = " c.`published` = 1 ";
        }
        if ($parentId !== false) {
            $where[] = ' cx.`category_parent_id` = ' . (int) $parentId;
        }
        if ($childId !== false) {
            $where[] = ' cx.`category_child_id` = ' . (int) $childId;
        }
        if ($vendorId === false) {
            $vendorId = vmAccess::isSuperVendor();
        }
        if ($vendorId != 1) {
            $where[] = ' (c.`virtuemart_vendor_id` = "' . (int) $vendorId . '" OR c.`shared` = "1") ';
        }
        if (!empty($keyword)) {
            $db = JFactory::getDBO();
            $keyword = '"%' . $db->escape($keyword, true) . '%"';
            //$keyword = $db->Quote($keyword, false);
            $where[] = ' ( category_name LIKE ' . $keyword . '
							   OR category_description LIKE ' . $keyword . ') ';
        }
        $whereString = '';
        if (count($where) > 0) {
            $whereString = ' WHERE ' . implode(' AND ', $where);
        } else {
            $whereString = 'WHERE 1 ';
        }
        if (trim($this->_selectedOrdering) == 'c.ordering') {
            $this->_selectedOrdering = 'c.ordering, category_name';
        }
        $ordering = $this->_getOrdering();
        $hash = md5($keyword . '.' . (int) $parentId . VmConfig::$vmlang . (int) $childId . $this->_selectedOrderingDir . (int) $vendorId . $this->_selectedOrdering);
        if (!isset($cats[$hash])) {
            $cats[$hash] = $this->_category_tree = $this->exeSortSearchListQuery(0, $select, $joinedTables, $whereString, 'GROUP BY virtuemart_category_id', $ordering);
        }
        return $cats[$hash];
    }
Exemple #16
0
 /**
  * Select the products to list on the product list page
  * @param $uid integer Optional user ID to get the orders of a single user
  * @param $_ignorePagination boolean If true, ignore the Joomla pagination (for embedded use, default false)
  */
 public function getOrdersList($uid = 0, $noLimit = false)
 {
     // 		vmdebug('getOrdersList');
     $tUserInfos = $this->getTable('userinfos');
     $this->_noLimit = $noLimit;
     $concat = array();
     if (property_exists($tUserInfos, 'company')) {
         $concat[] = 'u.company';
     }
     if (property_exists($tUserInfos, 'first_name')) {
         $concat[] = 'u.first_name';
     }
     if (property_exists($tUserInfos, 'middle_name')) {
         $concat[] = 'u.middle_name';
     }
     if (property_exists($tUserInfos, 'last_name')) {
         $concat[] = 'u.last_name';
     }
     if (!empty($concat)) {
         $concatStr = "CONCAT_WS(' '," . implode(',', $concat) . ")";
     } else {
         $concatStr = 'o.order_number';
     }
     // quorvia added phone, zip, city and shipping details and ST data
     $select = " o.*, " . $concatStr . " AS order_name " . ',u.email as order_email,
         pm.payment_name AS payment_method,
         u.company AS company,
         u.city AS city,
         u.zip AS zip,
         u.phone_1 AS phone,
         st.address_type AS st_type,
         st.company AS st_company,
         st.city AS st_city,
         st.zip AS st_zip,
         u.customer_note AS customer_note';
     $from = $this->getOrdersListQuery();
     $where = array();
     $virtuemart_vendor_id = vmAccess::isSuperVendor();
     if (vmAccess::manager('managevendors')) {
         vmdebug('Vendor is core.admin and should see all');
         $virtuemart_vendor_id = vRequest::get('virtuemart_vendor_id', $virtuemart_vendor_id);
         if ($virtuemart_vendor_id) {
             $where[] = ' o.virtuemart_vendor_id = "' . $virtuemart_vendor_id . '" ';
         }
         if (!empty($uid)) {
             $where[] = ' u.virtuemart_user_id = ' . (int) $uid . ' ';
         }
     } else {
         if (vmAccess::manager('orders')) {
             vmdebug('Vendor is manager and should only see its own orders venodorId ' . $virtuemart_vendor_id);
             if (!empty($virtuemart_vendor_id)) {
                 $where[] = ' (o.virtuemart_vendor_id = ' . $virtuemart_vendor_id . ' OR u.virtuemart_user_id = ' . (int) $uid . ') ';
                 $uid = 0;
             } else {
                 //We map here as fallback to vendor 1.
                 $where[] = ' u.virtuemart_user_id = ' . (int) $uid;
             }
         } else {
             //A normal user is only allowed to see its own orders, we map $uid to the user id
             $user = JFactory::getUser();
             $uid = (int) $user->id;
             $where = array();
         }
     }
     if (!empty($uid)) {
         $where[] = ' u.virtuemart_user_id = ' . (int) $uid . ' ';
     }
     if ($search = vRequest::getString('search', false)) {
         $db = JFactory::getDBO();
         $search = '"%' . $db->escape($search, true) . '%"';
         $search = str_replace(' ', '%', $search);
         $searchFields = array();
         $searchFields[] = 'u.first_name';
         $searchFields[] = 'u.middle_name';
         $searchFields[] = 'u.last_name';
         $searchFields[] = 'o.order_number';
         $searchFields[] = 'u.company';
         $searchFields[] = 'u.email';
         $searchFields[] = 'u.phone_1';
         $searchFields[] = 'u.address_1';
         $searchFields[] = 'u.zip';
         //quorvia addedd  ST data searches
         $searchFields[] = 'st.company';
         $searchFields[] = 'st.last_name';
         $searchFields[] = 'st.city';
         $searchFields[] = 'st.zip';
         $where[] = implode(' LIKE ' . $search . ' OR ', $searchFields) . ' LIKE ' . $search . ' ';
         //$where[] = ' ( u.first_name LIKE '.$search.' OR u.middle_name LIKE '.$search.' OR u.last_name LIKE '.$search.' OR `order_number` LIKE '.$search.')';
     }
     $order_status_code = vRequest::getString('order_status_code', false);
     if ($order_status_code and $order_status_code != -1) {
         $where[] = ' o.order_status = "' . $order_status_code . '" ';
     }
     if (count($where) > 0) {
         $whereString = ' WHERE (' . implode(' AND ', $where) . ') ';
     } else {
         $whereString = '';
     }
     if (vRequest::getCmd('view') == 'orders') {
         $ordering = $this->_getOrdering();
     } else {
         $ordering = ' order by o.modified_on DESC';
     }
     $this->_data = $this->exeSortSearchListQuery(0, $select, $from, $whereString, '', $ordering);
     if ($this->_data) {
         foreach ($this->_data as $k => $d) {
             $this->_data[$k]->order_name = htmlspecialchars(strip_tags(htmlspecialchars_decode($d->order_name)));
         }
     }
     return $this->_data;
 }
 public function display($tpl = null)
 {
     $show_prices = VmConfig::get('show_prices', 1);
     if ($show_prices == '1') {
         if (!class_exists('calculationHelper')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
         }
     }
     $this->assignRef('show_prices', $show_prices);
     if (!class_exists('shopFunctionsF')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
     }
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $pathway = $app->getPathway();
     if (!class_exists('VmImage')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'image.php';
     }
     // set search and keyword
     if ($keyword = vRequest::getString('keyword', false)) {
         //uword('keyword', false, ' ,-,+,.,_')) {
         $pathway->addItem($keyword);
         //$title .=' ('.$keyword.')';
     }
     //$search = vRequest::uword('keyword', null);
     $this->searchcustom = '';
     $this->searchCustomValues = '';
     //if (!empty($keyword)) {
     $this->getSearchCustom();
     $search = $keyword;
     /*} else {
     			$keyword ='';
     			$search = NULL;
     		}*/
     $this->assignRef('keyword', $keyword);
     $this->assignRef('search', $search);
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     if (!empty($menu->id)) {
         ShopFunctionsF::setLastVisitedItemId($menu->id);
     } else {
         if ($itemId = vRequest::getInt('Itemid', false)) {
             ShopFunctionsF::setLastVisitedItemId($itemId);
         }
     }
     $virtuemart_manufacturer_id = vRequest::getInt('virtuemart_manufacturer_id', -1);
     if ($virtuemart_manufacturer_id === -1 and !empty($menu->query['virtuemart_manufacturer_id'])) {
         $virtuemart_manufacturer_id = $menu->query['virtuemart_manufacturer_id'];
         vRequest::setVar('virtuemart_manufacturer_id', $virtuemart_manufacturer_id);
     }
     $this->categoryId = vRequest::getInt('virtuemart_category_id', -1);
     if ($this->categoryId === -1 and !empty($menu->query['virtuemart_category_id'])) {
         $this->categoryId = $menu->query['virtuemart_category_id'];
         vRequest::setVar('virtuemart_category_id', $this->categoryId);
     } else {
         if ($this->categoryId === -1 and $virtuemart_manufacturer_id === -1) {
             $this->categoryId = ShopFunctionsF::getLastVisitedCategoryId();
         }
     }
     $this->setCanonicalLink($tpl, $document, $this->categoryId, $virtuemart_manufacturer_id);
     if (($this->categoryId === -1 or $this->categoryId === 0) and $virtuemart_manufacturer_id) {
         $this->categoryId = 0;
         $catType = 'manufacturer';
         $this->setCanonicalLink($tpl, $document, $virtuemart_manufacturer_id, $catType);
     }
     $categoryModel = VmModel::getModel('category');
     $productModel = VmModel::getModel('product');
     if ($this->categoryId === -1) {
         $this->categoryId = 0;
     }
     $vendorId = 1;
     $category = $categoryModel->getCategory($this->categoryId);
     if (!isset($menu->query['showproducts'])) {
         $menu->query['showproducts'] = 1;
     }
     $this->showproducts = vRequest::getInt('showproducts', $menu->query['showproducts']);
     if (!empty($category)) {
         $vendorId = $category->virtuemart_vendor_id;
         if ($this->showproducts) {
             //if(empty($category->category_layout) or $category->category_layout != 'categories') {
             // Load the products in the given category
             $ids = $productModel->sortSearchListQuery(TRUE, $this->categoryId);
             $this->perRow = empty($category->products_per_row) ? VmConfig::get('products_per_row', 3) : $category->products_per_row;
             $this->vmPagination = $productModel->getPagination($this->perRow);
             $ratingModel = VmModel::getModel('ratings');
             $this->showRating = $ratingModel->showRating();
             $productModel->withRating = $this->showRating;
             $this->orderByList = $productModel->getOrderByList($this->categoryId);
             $this->products = $productModel->getProducts($ids);
             //$products = $productModel->getProductsInCategory($this->categoryId);
             $imgAmount = VmConfig::get('prodimg_browse', 1);
             $productModel->addImages($this->products, $imgAmount);
             if ($this->products) {
                 $currency = CurrencyDisplay::getInstance();
                 $this->assignRef('currency', $currency);
                 $display_stock = VmConfig::get('display_stock', 1);
                 $showCustoms = VmConfig::get('show_pcustoms', 1);
                 if ($display_stock or $showCustoms) {
                     if (!$showCustoms) {
                         foreach ($this->products as $i => $productItem) {
                             $productItem->stock = $productModel->getStockIndicator($productItem);
                         }
                     } else {
                         shopFunctionsF::sortLoadProductCustomsStockInd($this->products, $productModel);
                     }
                 }
                 // add javascript for price and cart, need even for quantity buttons, so we need it almost anywhere
                 vmJsApi::jPrice();
             }
             // Add feed links
             if ($this->showproducts and $this->products && VmConfig::get('feed_cat_published', 0) == 1) {
                 $link = '&format=feed&limitstart=';
                 $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
                 $document->addHeadLink(JRoute::_($link . '&type=rss', FALSE), 'alternate', 'rel', $attribs);
                 $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
                 $document->addHeadLink(JRoute::_($link . '&type=atom', FALSE), 'alternate', 'rel', $attribs);
             }
             $user = JFactory::getUser();
             $this->showBasePrice = (vmAccess::manager() or vmAccess::isSuperVendor());
         }
         //No redirect here, for category id = 0 means show ALL categories! note by Max Milbers
         if (!empty($this->categoryId) and $this->categoryId !== -1 and (empty($category->slug) or !$category->published)) {
             if (empty($category->slug)) {
                 vmInfo(vmText::_('COM_VIRTUEMART_CAT_NOT_FOUND'));
             } else {
                 if ($category->virtuemart_id !== 0 and !$category->published) {
                     vmInfo('COM_VIRTUEMART_CAT_NOT_PUBL', $category->category_name, $this->categoryId);
                 }
             }
             //Fallback
             $categoryLink = '';
             if ($category->category_parent_id) {
                 $categoryLink = '&view=category&virtuemart_category_id=' . $category->category_parent_id;
             } else {
                 $last_category_id = shopFunctionsF::getLastVisitedCategoryId();
                 if (!$last_category_id or $this->categoryId == $last_category_id) {
                     $last_category_id = vRequest::getInt('virtuemart_category_id', false);
                 }
                 if ($last_category_id and $this->categoryId != $last_category_id) {
                     $categoryLink = '&view=category&virtuemart_category_id=' . $last_category_id;
                 }
             }
             if (VmConfig::get('handle_404', 1)) {
                 $app->redirect(JRoute::_('index.php?option=com_virtuemart' . $categoryLink . '&error=404', FALSE));
             } else {
                 JError::raise(E_ERROR, '404', 'Not found');
             }
             return;
         }
         shopFunctionsF::setLastVisitedCategoryId($this->categoryId);
         shopFunctionsF::setLastVisitedManuId($virtuemart_manufacturer_id);
         // Add the category name to the pathway
         if ($category->parents) {
             foreach ($category->parents as $c) {
                 $pathway->addItem(strip_tags(vmText::_($c->category_name)), JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $c->virtuemart_category_id, FALSE));
             }
         }
         $catImgAmount = VmConfig::get('catimg_browse', 1);
         $categoryModel->addImages($category, $catImgAmount);
         if (!isset($menu->query['showcategory'])) {
             $menu->query['showcategory'] = 1;
         }
         $this->showcategory = vRequest::getInt('showcategory', $menu->query['showcategory']);
         //$this->showcategory = vRequest::getInt('showcategory',true);
         if ($this->showcategory) {
             //if($category->category_layout == 'categories' or ($this->categoryId >0 and $virtuemart_manufacturer_id <1)){
             $category->children = $categoryModel->getChildCategoryList($vendorId, $this->categoryId, $categoryModel->getDefaultOrdering(), $categoryModel->_selectedOrderingDir);
             $categoryModel->addImages($category->children, $catImgAmount);
         } else {
             $category->children = false;
         }
         if (VmConfig::get('enable_content_plugin', 0)) {
             shopFunctionsF::triggerContentPlugin($category, 'category', 'category_description');
         }
         $metadesc = '';
         $metakey = '';
         $metarobot = '';
         if (isset($menu->params)) {
             $metadesc = $menu->params->get('menu-meta_description');
             $metakey = $menu->params->get('menu-meta_keywords');
             $metarobot = $menu->params->get('robots');
         }
         if ($category->metadesc) {
             $metadesc = $category->metadesc;
         }
         if ($category->metakey) {
             $metakey = $category->metakey;
         }
         if ($category->metarobot) {
             $metarobot = $category->metarobot;
         }
         $document->setDescription($metadesc);
         $document->setMetaData('keywords', $metakey);
         $document->setMetaData('robots', $metarobot);
         if ($app->getCfg('MetaAuthor') == '1' and !empty($category->metaauthor)) {
             $document->setMetaData('author', $category->metaauthor);
         }
         if (empty($category->category_template)) {
             $category->category_template = VmConfig::get('categorytemplate');
         }
         if (!empty($menu->query['categorylayout'])) {
             //if(!empty($menu->query['categorylayout']) and $menu->query['virtuemart_category_id']==$this->categoryId){
             $category->category_layout = $menu->query['categorylayout'];
         }
         $productsLayout = VmConfig::get('productsublayout', 'products');
         if (empty($productsLayout)) {
             $productsLayout = 'products';
         }
         $this->productsLayout = empty($menu->query['productsublayout']) ? $productsLayout : $menu->query['productsublayout'];
         shopFunctionsF::setVmTemplate($this, $category->category_template, 0, $category->category_layout);
     } else {
         //Backward compatibility
         if (!isset($category)) {
             $category = new stdClass();
             $category->category_name = '';
             $category->category_description = '';
             $category->haschildren = false;
         }
     }
     $this->assignRef('category', $category);
     // Set the titles
     if (!empty($category->customtitle)) {
         $title = strip_tags($category->customtitle);
     } elseif (!empty($category->category_name)) {
         $title = strip_tags($category->category_name);
     } else {
         $title = $this->setTitleByJMenu($app);
     }
     $title = vmText::_($title);
     if (vRequest::getInt('error')) {
         $title .= ' ' . vmText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND');
     }
     if (!empty($keyword)) {
         $title .= ' (' . strip_tags(htmlspecialchars_decode($keyword)) . ')';
     }
     if ($virtuemart_manufacturer_id > 0 and !empty($this->products[0])) {
         $title .= ' ' . $this->products[0]->mf_name;
     }
     $document->setTitle($title);
     // Override Category name when viewing manufacturers products !IMPORTANT AFTER page title.
     if ($virtuemart_manufacturer_id > 0 and !empty($this->products[0]) and isset($category->category_name)) {
         $category->category_name = $this->products[0]->mf_name;
     }
     if ($app->getCfg('MetaTitle') == '1') {
         $document->setMetaData('title', $title);
     }
     parent::display($tpl);
 }
    /**
     * @author Max Milbers
     * @param $field
     * @param $product_id
     * @param $row
     */
    public function displayProductCustomfieldBE($field, $product, $row)
    {
        //This is a kind of fallback, setting default of custom if there is no value of the productcustom
        $field->customfield_value = empty($field->customfield_value) ? $field->custom_value : $field->customfield_value;
        $field->customfield_price = empty($field->customfield_price) ? 0 : $field->customfield_price;
        if (is_object($product)) {
            $product_id = $product->virtuemart_product_id;
            $virtuemart_vendor_id = $product->virtuemart_vendor_id;
        } else {
            $product_id = $product;
            $virtuemart_vendor_id = vmAccess::isSuperVendor();
            vmdebug('displayProductCustomfieldBE product was not object, use for productId ' . $product_id . ' and $virtuemart_vendor_id = ' . $virtuemart_vendor_id);
        }
        //vmdebug('displayProductCustomfieldBE',$product_id,$field,$virtuemart_vendor_id,$product);
        //the option "is_cart_attribute" gives the possibility to set a price, there is no sense to set a price,
        //if the custom is not stored in the order.
        if ($field->is_input) {
            if (!class_exists('VirtueMartModelVendor')) {
                require VMPATH_ADMIN . DS . 'models' . DS . 'vendor.php';
            }
            if (!class_exists('VirtueMartModelCurrency')) {
                require VMPATH_ADMIN . DS . 'models' . DS . 'currency.php';
            }
            $vendor_model = VmModel::getModel('vendor');
            //$virtuemart_vendor_id = 1;
            $vendor = $vendor_model->getVendor($virtuemart_vendor_id);
            $currency_model = VmModel::getModel('currency');
            $vendor_currency = $currency_model->getCurrency($vendor->vendor_currency);
            $priceInput = '<span style="white-space: nowrap;"><input type="text" size="12" style="text-align:right;" value="' . $field->customfield_price . '" name="field[' . $row . '][customfield_price]" /> ' . $vendor_currency->currency_symbol . "</span>";
        } else {
            $priceInput = ' ';
        }
        switch ($field->field_type) {
            case 'C':
                //vmdebug('displayProductCustomfieldBE $field',$field);
                //if(!isset($field->withParent)) $field->withParent = 0;
                //if(!isset($field->parentOrderable)) $field->parentOrderable = 0;
                //vmdebug('displayProductCustomfieldBE',$field,$product);
                if (!empty($product->product_parent_id) and $product->product_parent_id == $field->virtuemart_product_id) {
                    return 'controlled by parent';
                }
                $html = '';
                if (!class_exists('VmHTML')) {
                    require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
                }
                //$html = vmText::_('COM_VIRTUEMART_CUSTOM_WP').VmHTML::checkbox('field[' . $row . '][withParent]',$field->withParent,1,0,'');
                //$html .= vmText::_('COM_VIRTUEMART_CUSTOM_PO').VmHTML::checkbox('field[' . $row . '][parentOrderable]',$field->parentOrderable,1,0,'').'<br />';
                if (empty($field->selectoptions) or count($field->selectoptions) == 0) {
                    $selectOption = new stdClass();
                    //The json conversts it anyway in an object, so suitable to use an object here
                    $selectOption->voption = 'product_name';
                    $selectOption->slabel = '';
                    $selectOption->clabel = '';
                    $selectOption->canonical = 0;
                    $selectOption->values = '';
                    $c = 0;
                    $field->selectoptions = new stdClass();
                    $field->selectoptions->{$c} = $selectOption;
                    $field->options = new stdClass();
                } else {
                    if (is_array($field->selectoptions)) {
                        $field->selectoptions = (object) $field->selectoptions;
                    }
                }
                $field->options = (object) $field->options;
                $optAttr = array();
                $optAttr[] = array('value' => '0', 'text' => vmText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION'));
                $optAttr[] = array('value' => 'product_name', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_FORM_NAME'));
                $optAttr[] = array('value' => 'product_sku', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_SKU'));
                $optAttr[] = array('value' => 'slug', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_ALIAS'));
                $optAttr[] = array('value' => 'product_length', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_LENGTH'));
                $optAttr[] = array('value' => 'product_width', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WIDTH'));
                $optAttr[] = array('value' => 'product_height', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_HEIGHT'));
                $optAttr[] = array('value' => 'product_weight', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WEIGHT'));
                $optAttr[] = array('value' => 'clabels', 'text' => vmText::_('COM_VIRTUEMART_CLABELS'));
                $productModel = VmModel::getModel('product');
                $childIds = array();
                $sorted = array();
                $productModel->getAllProductChildIds($product_id, $childIds);
                if (isset($childIds[$product_id])) {
                    $sorted = self::sortChildIds($product_id, $childIds[$product_id]);
                }
                array_unshift($sorted, array('parent_id' => $product_id, 'vm_product_id' => $product_id));
                $showSku = true;
                $k = 0;
                if (empty($field->selectoptions)) {
                    $field->selectoptions = array();
                }
                foreach ($field->selectoptions as $k => &$soption) {
                    $options = array();
                    $options[] = array('value' => '0', 'text' => vmText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION'));
                    $added = array();
                    if ($soption->voption != 'clabels') {
                        foreach ($sorted as $vmProductId) {
                            if (empty($vmProductId) or $vmProductId['vm_product_id'] == $product_id) {
                                continue;
                            }
                            $product = $productModel->getProductSingle($vmProductId['vm_product_id'], false);
                            $voption = trim($product->{$soption->voption});
                            if (!empty($voption)) {
                                $found = false;
                                //Guys, dont tell me about in_array or array_search, it does not work here
                                foreach ($added as $add) {
                                    if ($add == $voption) {
                                        $found = true;
                                    }
                                }
                                if (!$found) {
                                    $added[] = $voption;
                                }
                            }
                        }
                        if ($soption->voption == 'product_sku') {
                            $showSku = false;
                        }
                    }
                    if (!empty($soption->values)) {
                        $values = explode("\n", $soption->values);
                        foreach ($values as $value) {
                            $found = false;
                            $value = trim($value);
                            foreach ($added as $add) {
                                if ($add == $value) {
                                    $found = true;
                                    vmdebug('Found true due $soption->values');
                                }
                            }
                            if (!$found) {
                                $added[] = $value;
                            }
                        }
                    }
                    $soption->values = implode("\n", $added);
                    foreach ($added as &$value) {
                        $options[] = array('value' => $value, 'text' => $value);
                    }
                    $soption->comboptions = $options;
                    if (!isset($soption->clabel)) {
                        $soption->clabel = '';
                    }
                    $soption->slabel = empty($soption->clabel) ? vmText::_('COM_VIRTUEMART_' . strtoupper($soption->voption)) : vmText::_($soption->clabel);
                    if ($k == 0) {
                        $html .= '<div style="float:left">';
                    } else {
                        $html .= '<div class="removable">';
                    }
                    $idTag = 'selectoptions' . $k;
                    $html .= JHtml::_('select.genericlist', $optAttr, 'field[' . $row . '][selectoptions][' . $k . '][voption]', '', 'value', 'text', $soption->voption, $idTag);
                    $html .= '<input type="text" value="' . $soption->clabel . '" name="field[' . $row . '][selectoptions][' . $k . '][clabel]" style="line-height:2em;margin:5px 5px 0;" />';
                    $html .= '<textarea name="field[' . $row . '][selectoptions][' . $k . '][values]" rows="5" cols="35" style="float:none;margin:5px 5px 0;" >' . $soption->values . '</textarea>';
                    if ($k > 0) {
                        $html .= '<span class="vmicon vmicon-16-remove"></span>';
                    } else {
                    }
                    $html .= '</div>';
                    if ($k == 0) {
                        $html .= '<div style="float:right;max-width:60%;width:45%;min-width:30%" >' . vmText::_('COM_VIRTUEMART_CUSTOM_CV_DESC') . '</div>';
                        $html .= '<div class="clear"></div>';
                    }
                }
                $idTag = 'selectoptions' . ++$k;
                $html .= '<fieldset style="background-color:#F9F9F9;">
					<legend>' . vmText::_('COM_VIRTUEMART_CUSTOM_RAMB_NEW') . '</legend>
					<div id="new_ramification">';
                //$html .= JHtml::_ ('select.genericlist', $options, 'field[' . $row . '][selectoptions]['.$k.'][voption]', '', 'value', 'text', 'product_name',$idTag) ;
                //$html .= '<input type="text" value="" name="field[' . $row . '][selectoptions]['.$k.'][slabel]" />';
                $html .= JHtml::_('select.genericlist', $optAttr, 'voption', '', 'value', 'text', 'product_name', 'voption');
                $html .= '<input type="text" value="" id="vlabel" name="vlabel" />';
                $html .= '<span id="new_ramification_bt"><span class="icon-nofloat vmicon vmicon-16-new"></span>' . vmText::_('COM_VIRTUEMART_ADD') . '</span>
					</div>
				</fieldset>';
                vmJsApi::addJScript('new_ramification', "\n\tjQuery( function(\$) {\n\t\t\$('#new_ramification_bt').click(function() {\n\t\t\tvar Prod = \$('.new_ramification');//obsolete?\n\n\t\t\tvar voption = jQuery('#voption').val();\n\t\t\tvar label = jQuery('#vlabel').val();\n\t\t\t\t//console.log ('my label '+label);\n\t\t\tform = document.getElementById('adminForm');\n\t\t\tvar newdiv = document.createElement('div');\n\t\t\tnewdiv.innerHTML = '<input type=\"text\" value=\"'+voption+'\" name=\"field[" . $row . "][selectoptions][" . $k . "][voption]\" /><input type=\"text\" value=\"'+label+'\" name=\"field[" . $row . "][selectoptions][" . $k . "][clabel]\" />';\n\t\t\tform.appendChild(newdiv);\n\n\t\t\tform.task.value = 'apply';\n\t\t\tform.submit();\n\t\t\treturn false;\n\t\t});\n\t});\n\t");
                if ($product_id) {
                    $link = JRoute::_('index.php?option=com_virtuemart&view=product&task=createChild&virtuemart_product_id=' . $product_id . '&' . JSession::getFormToken() . '=1&target=parent');
                    $add_child_button = "";
                } else {
                    $link = "";
                    $add_child_button = " not-active";
                }
                $html .= '<div class="button2-left ' . $add_child_button . ' btn-wrapper">
						<div class="blank">';
                if ($link) {
                    $html .= '<a href="' . $link . '" class="btn btn-small">';
                } else {
                    $html .= '<span class="hasTip" title="' . vmText::_('COM_VIRTUEMART_PRODUCT_ADD_CHILD_TIP') . '">';
                }
                $html .= vmText::_('COM_VIRTUEMART_PRODUCT_ADD_CHILD');
                if ($link) {
                    $html .= '</a>';
                } else {
                    $html .= '</span>';
                }
                $html .= '</div>
					</div><div class="clear"></div>';
                //vmdebug('my $field->selectoptions',$field->selectoptions,$field->options);
                $html .= '<table id="syncro">';
                $html .= '<tr>
<th style="text-align: left !important;width:130px;">#</th>';
                if ($showSku) {
                    $html .= '<th style="text-align: left !important;width:90px;">' . vmText::_('COM_VIRTUEMART_PRODUCT_SKU') . '</th>';
                }
                $html .= '<th style="text-align: left !important;width:80px;">' . vmText::_('COM_VIRTUEMART_PRODUCT_GTIN') . '</th>
<th style="text-align: left !important;" width="5%">' . vmText::_('COM_VIRTUEMART_PRODUCT_FORM_PRICE_COST') . '</th>
<th style="text-align: left !important;width:30px;">' . vmText::_('COM_VIRTUEMART_PRODUCT_FORM_IN_STOCK') . '</th>
<th style="text-align: left !important;width:30px;">' . vmText::_('COM_VIRTUEMART_PRODUCT_FORM_ORDERED_STOCK') . '</th>';
                foreach ($field->selectoptions as $k => $option) {
                    $html .= '<th>' . vmText::_('COM_VIRTUEMART_' . strtoupper($option->voption)) . '</th>';
                }
                $html .= '</tr>';
                if (isset($childIds[$product_id])) {
                    foreach ($sorted as $i => $line) {
                        $html .= self::renderProductChildLine($i, $line, $field, $productModel, $row, $showSku);
                    }
                }
                $html .= '</table>';
                return $html;
                // 					return 'Automatic Childvariant creation (later you can choose here attributes to show, now product name) </td><td>';
                break;
            case 'A':
                //vmdebug('displayProductCustomfieldBE $field',$field);
                if (!isset($field->withParent)) {
                    $field->withParent = 0;
                }
                if (!isset($field->parentOrderable)) {
                    $field->parentOrderable = 0;
                }
                //vmdebug('displayProductCustomfieldBE',$field);
                if (!class_exists('VmHTML')) {
                    require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
                }
                $html = '</td><td>' . vmText::_('COM_VIRTUEMART_CUSTOM_WP') . VmHTML::checkbox('field[' . $row . '][withParent]', $field->withParent, 1, 0, '') . '<br />';
                $html .= vmText::_('COM_VIRTUEMART_CUSTOM_PO') . VmHTML::checkbox('field[' . $row . '][parentOrderable]', $field->parentOrderable, 1, 0, '');
                $options = array();
                $options[] = array('value' => 'product_name', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_FORM_NAME'));
                $options[] = array('value' => 'product_sku', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_SKU'));
                $options[] = array('value' => 'slug', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_ALIAS'));
                $options[] = array('value' => 'product_length', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_LENGTH'));
                $options[] = array('value' => 'product_width', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WIDTH'));
                $options[] = array('value' => 'product_height', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_HEIGHT'));
                $options[] = array('value' => 'product_weight', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WEIGHT'));
                $html .= JHtml::_('select.genericlist', $options, 'field[' . $row . '][customfield_value]', '', 'value', 'text', $field->customfield_value);
                return $html;
                // 					return 'Automatic Childvariant creation (later you can choose here attributes to show, now product name) </td><td>';
                break;
                /* string or integer */
            /* string or integer */
            case 'B':
            case 'S':
                if ($field->is_list) {
                    $options = array();
                    $values = explode(';', $field->custom_value);
                    foreach ($values as $key => $val) {
                        $options[] = array('value' => $val, 'text' => $val);
                    }
                    $currentValue = $field->customfield_value;
                    return $priceInput . '</td><td>' . JHtml::_('select.genericlist', $options, 'field[' . $row . '][customfield_value]', NULL, 'value', 'text', $currentValue);
                } else {
                    return $priceInput . '</td><td><input type="text" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" />';
                    break;
                }
                break;
                // Property
            // Property
            case 'P':
                $options = array();
                $options[] = array('value' => 'product_name', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_FORM_NAME'));
                $options[] = array('value' => 'product_sku', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_SKU'));
                $options[] = array('value' => 'slug', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_ALIAS'));
                $options[] = array('value' => 'product_length', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_LENGTH'));
                $options[] = array('value' => 'product_width', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WIDTH'));
                $options[] = array('value' => 'product_height', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_HEIGHT'));
                $options[] = array('value' => 'product_weight', 'text' => vmText::_('COM_VIRTUEMART_PRODUCT_WEIGHT'));
                return '</td><td>' . JHtml::_('select.genericlist', $options, 'field[' . $row . '][customfield_value]', '', 'value', 'text', $field->customfield_value) . '<input type="text" value="' . $field->round . '" name="field[' . $row . '][round]" />';
                /* parent hint, this is a GROUP and should be G not P*/
            /* parent hint, this is a GROUP and should be G not P*/
            case 'G':
                return $field->customfield_value . '<input type="hidden" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" /></td><td>';
                break;
                /* image */
            /* image */
            case 'M':
                if ($field->is_list and $field->is_input) {
                    $html = $priceInput . '</td><td>is list ';
                    $values = explode(';', $field->custom_value);
                    foreach ($values as $val) {
                        $html .= $this->displayCustomMedia($val, 'product');
                    }
                    return $html;
                } else {
                    if (empty($field->custom_value)) {
                        $q = 'SELECT `virtuemart_media_id` as value,`file_title` as text FROM `#__virtuemart_medias` WHERE `published`=1
					AND (`virtuemart_vendor_id`= "' . $virtuemart_vendor_id . '" OR `shared` = "1")';
                        $db = JFactory::getDBO();
                        $db->setQuery($q);
                        $options = $db->loadObjectList();
                    } else {
                        $values = explode(';', $field->custom_value);
                        $mM = VmModel::getModel('media');
                        foreach ($values as $key => $val) {
                            $mM->setId($val);
                            $file = $mM->getFile();
                            $tmp = array('value' => $val, 'text' => $file->file_name);
                            $options[] = (object) $tmp;
                        }
                    }
                    return $priceInput . '</td><td>' . JHtml::_('select.genericlist', $options, 'field[' . $row . '][customfield_value]', '', 'value', 'text', $field->customfield_value);
                }
                break;
            case 'D':
                return $priceInput . '</td><td>' . vmJsApi::jDate($field->customfield_value, 'field[' . $row . '][customfield_value]', 'field_' . $row . '_customvalue');
                break;
                //'X'=>'COM_VIRTUEMART_CUSTOM_EDITOR',
            //'X'=>'COM_VIRTUEMART_CUSTOM_EDITOR',
            case 'X':
                // Not sure why this block is needed to get it to work when editing the customfield (the subsequent block works fine when creating it, ie. in JS)
                $document = JFactory::getDocument();
                if (get_class($document) == 'JDocumentHTML') {
                    $editor = JFactory::getEditor();
                    return '</td><td>' . $editor->display('field[' . $row . '][customfield_value]', $field->customfield_value, '550', '400', '60', '20', false);
                }
                return $priceInput . '</td><td><textarea class="mceInsertContentNew" name="field[' . $row . '][customfield_value]" id="field-' . $row . '-customfield_value">' . $field->customfield_value . '</textarea>
						<script type="text/javascript">// Creates a new editor instance
							tinymce.execCommand("mceAddControl",true,"field-' . $row . '-customfield_value")
						</script>';
                //return '<input type="text" value="'.$field->customfield_value.'" name="field['.$row.'][customfield_value]" /></td><td>'.$priceInput;
                break;
                //'Y'=>'COM_VIRTUEMART_CUSTOM_TEXTAREA'
            //'Y'=>'COM_VIRTUEMART_CUSTOM_TEXTAREA'
            case 'Y':
                return $priceInput . '</td><td><textarea id="field[' . $row . '][customfield_value]" name="field[' . $row . '][customfield_value]" class="inputbox" cols=80 rows=6 >' . $field->customfield_value . '</textarea>';
                //return '<input type="text" value="'.$field->customfield_value.'" name="field['.$row.'][customfield_value]" /></td><td>'.$priceInput;
                break;
                /*Extended by plugin*/
            /*Extended by plugin*/
            case 'E':
                $html = '<input type="hidden" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" />';
                if (!class_exists('vmCustomPlugin')) {
                    require VMPATH_PLUGINLIBS . DS . 'vmcustomplugin.php';
                }
                //vmdebug('displayProductCustomfieldBE $field',$field);
                JPluginHelper::importPlugin('vmcustom', $field->custom_element);
                $dispatcher = JDispatcher::getInstance();
                $retValue = '';
                $dispatcher->trigger('plgVmOnProductEdit', array($field, $product_id, &$row, &$retValue));
                return $html . $priceInput . '</td><td>' . $retValue;
                break;
                /* related category*/
            /* related category*/
            case 'Z':
                if (!$product_id or empty($field->customfield_value)) {
                    return '';
                }
                // special case it's category ID !
                $q = 'SELECT * FROM `#__virtuemart_categories_' . VmConfig::$vmlang . '` INNER JOIN `#__virtuemart_categories` AS p using (`virtuemart_category_id`) WHERE `virtuemart_category_id`= "' . (int) $field->customfield_value . '" ';
                $db = JFactory::getDBO();
                $db->setQuery($q);
                //echo $db->_sql;
                if ($category = $db->loadObject()) {
                    $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias` WHERE `virtuemart_category_id`= "' . (int) $field->customfield_value . '" ';
                    $db->setQuery($q);
                    $thumb = '';
                    if ($media_id = $db->loadResult()) {
                        $thumb = $this->displayCustomMedia($media_id, 'category');
                    }
                    $display = '<input type="hidden" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" />';
                    $display .= '<span class="custom_related_image">' . $thumb . '</span><span class="custom_related_title">';
                    $display .= JHtml::link('index.php?option=com_virtuemart&view=category&task=edit&cid=' . (int) $field->customfield_value, $category->category_name, array('title' => $category->category_name, 'target' => 'blank')) . '</span>';
                    return $display;
                } else {
                    return 'no result $product_id = ' . $product_id . ' and ' . $field->customfield_value;
                }
                /* related product*/
            /* related product*/
            case 'R':
                if (!$product_id) {
                    return '';
                }
                $pModel = VmModel::getModel('product');
                $related = $pModel->getProduct((int) $field->customfield_value, TRUE, FALSE, FALSE, 1);
                if (!empty($related->virtuemart_media_id[0])) {
                    $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0]) . ' ';
                } else {
                    $thumb = $this->displayCustomMedia(0) . ' ';
                }
                $display = '<input type="hidden" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" />';
                $display .= '<span class="custom_related_image">' . $thumb . '</span><span class="custom_related_title">';
                $display .= JHtml::link('index.php?option=com_virtuemart&view=product&task=edit&virtuemart_product_id=' . $related->virtuemart_product_id, $related->product_name, array('title' => $related->product_name, 'target' => 'blank')) . '</span>';
                return $display;
        }
    }
Exemple #19
0
 /**
  * Todo, works only for small stores, we need a new solution there with a bit filtering
  * For example by time, if already shopper, and a simple search
  * @return object list of users
  */
 function getUserList()
 {
     $result = false;
     if ($this->allowChangeShopper) {
         $this->adminID = vmAccess::getBgManagerId();
         $superVendor = vmAccess::isSuperVendor($this->adminID);
         if ($superVendor) {
             $uModel = VmModel::getModel('user');
             $result = $uModel->getSwitchUserList($superVendor, $this->adminID);
         }
     }
     if (!$result) {
         $this->allowChangeShopper = false;
     }
     return $result;
 }
Exemple #20
0
 /**
  * This fills the empty properties of a product
  * todo add if(!empty statements
  *
  * @author Max Milbers
  * @param unknown_type $product
  * @param unknown_type $front
  */
 private function fillVoidProduct($front = TRUE)
 {
     /* Load an empty product */
     $product = $this->getTable('products');
     $product->load();
     /* Add optional fields */
     $product->virtuemart_manufacturer_id = NULL;
     $product->virtuemart_product_price_id = NULL;
     if (!class_exists('VirtueMartModelVendor')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'vendor.php';
     }
     $product->selectedPrice = 0;
     $product->allPrices[0] = $this->fillVoidPrice();
     $product->categories = array();
     if ($front) {
         $product->link = '';
         $product->virtuemart_category_id = 0;
         $product->virtuemart_shoppergroup_id = 0;
         $product->mf_name = '';
         $product->packaging = '';
         $product->related = '';
         $product->box = '';
         $product->addToCartButton = false;
     }
     $product->virtuemart_vendor_id = vmAccess::isSuperVendor();
     return $product;
 }
Exemple #21
0
    /**
     * This displays a media handler. It displays the full and the thumb (icon) of the media.
     * It also gives a possibility to upload/change/thumbnail media
     *
     * @param string $imageArgs html atttributes, Just for displaying the fullsized image
     */
    public function displayFileHandler()
    {
        VmConfig::loadJLang('com_virtuemart_media');
        $this->addHiddenByType();
        $html = '<fieldset class="checkboxes">';
        $html .= '<legend>' . vmText::_('COM_VIRTUEMART_IMAGE_INFORMATION') . '</legend>';
        $html .= '<div class="vm__img_autocrop">';
        $imageArgs = array('id' => 'vm_display_image');
        $html .= $this->displayMediaFull($imageArgs, false, '', false) . '</div>';
        //This makes problems, when there is already a form, and there would be form in a form. breaks js in some browsers
        //		$html .= '<form name="adminForm" id="adminForm" method="post" enctype="multipart/form-data">';
        $html .= ' <table class="adminform"> ';
        if ($this->published || $this->virtuemart_media_id === 0) {
            $checked = 1;
        } else {
            $checked = 0;
        }
        $html .= '<tr>';
        //  The following was removed bacause the check box (publish/unpublish) was not functioning...
        // 			$this->media_published = $this->published;
        $html .= '<td class="labelcell" style="width:20em">
	<label for="published">' . vmText::_('COM_VIRTUEMART_FILES_FORM_FILE_PUBLISHED') . '</label>
</td>
<td>';
        if (!class_exists('VmHtml')) {
            require VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php';
        }
        $html .= VmHtml::checkbox('media[media_published]', $checked, 1, 0, 'class="inputbox"', 'media[media_published]');
        //<input type="checkbox" class="inputbox" id="media_published'.$identify.'" name="media_published'.$identify.'" '.$checked.' size="16" value="1" />
        $html .= '</td>';
        $imgWidth = VmConfig::get('img_width', '');
        if (!empty($imgWidth)) {
            $imgWidth = 'width:' . VmConfig::get('img_width', 90) . 'px;';
        } else {
            $imgWidth = 'max-width:200px;width:auto;';
        }
        $imgHeight = VmConfig::get('img_height', '');
        if (!empty($imgHeight)) {
            $imgHeight = 'height:' . VmConfig::get('img_height', 90) . 'px;';
        } else {
            $imgHeight = '';
        }
        $html .= '<td rowspan = "8" min-width = "' . (VmConfig::get('img_width', 90) + 10) . 'px" overflow="hidden">';
        $thumbArgs = array('class' => 'vm_thumb_image', 'style' => 'overflow: auto;' . $imgWidth . $imgHeight);
        $html .= $this->displayMediaThumb($thumbArgs);
        //JHTML::image($this->file_url_thumb, 'thumbnail', 'id="vm_thumb_image" style="overflow: auto; float: right;"');
        // $html .= $this->displayMediaThumb('',false,'id="vm_thumb_image" style="overflow: auto; float: right;"');
        $html .= '</td>';
        $html .= '</tr>';
        if (vmAccess::manager('media')) {
            $readonly = 'readonly';
        } else {
            $readonly = '';
        }
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_TITLE', 'file_title');
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_DESCRIPTION', 'file_description');
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_META', 'file_meta');
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_CLASS', 'file_class');
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_URL', 'file_url', $readonly);
        //remove the file_url_thumb in case it is standard
        if (!empty($this->file_url_thumb) and is_a($this, 'VmImage')) {
            $file_url_thumb = $this->createThumbFileUrl();
            //vmdebug('my displayFileHandler ',$this,$file_url_thumb);
            if ($this->file_url_thumb == $file_url_thumb) {
                $this->file_url_thumb = vmText::sprintf('COM_VIRTUEMART_DEFAULT_URL', $file_url_thumb);
            }
        }
        $html .= $this->displayRow('COM_VIRTUEMART_FILES_FORM_FILE_URL_THUMB', 'file_url_thumb', $readonly);
        $this->addMediaAttributesByType();
        $html .= '<tr>
				<td class="labelcell">' . vmText::_('COM_VIRTUEMART_FILES_FORM_ROLE') . '</td>
				<td><fieldset class="checkboxes">' . JHtml::_('select.radiolist', $this->getOptions($this->_mRoles), 'media[media_roles]', '', 'value', 'text', $this->media_role) . '</fieldset></td></tr>';
        // 			$html .= '<tr><td class="labelcell">'.VmHTML::checkbox('file_is_forSale', $this->file_is_forSale);
        // 			$html .= VmHTML::checkbox('file_is_downloadable', $this->file_is_downloadable);
        if (!empty($this->file_type)) {
            $html .= '<tr>
					<td class="labelcell">' . vmText::_('COM_VIRTUEMART_FILES_FORM_LOCATION') . '</td>
					<td><fieldset class="checkboxes">' . vmText::_('COM_VIRTUEMART_FORM_MEDIA_SET_' . strtoupper($this->file_type)) . '</fieldset></td></tr>';
        } else {
            $mediaattribtemp = $this->media_attributes;
            if (empty($this->media_attributes)) {
                $mediaattribtemp = 'product';
            }
            $html .= '<tr>
					<td class="labelcell">' . vmText::_('COM_VIRTUEMART_FILES_FORM_LOCATION') . '</td>
					<td><fieldset class="checkboxes">' . JHtml::_('select.radiolist', $this->getOptions($this->_mLocation), 'media[media_attributes]', '', 'value', 'text', $mediaattribtemp) . '</fieldset></td></tr>';
        }
        // select language for image
        $active_languages = VmConfig::get('active_languages');
        if (count($active_languages) > 1) {
            $selectedImageLangue = explode(",", $this->file_lang);
            $configM = VmModel::getModel('config');
            $languages = $configM->getActiveLanguages($selectedImageLangue, 'media[active_languages][]');
            $html .= '<tr>
					<td class="labelcell"><span class="hasTip" title="' . vmText::_('COM_VIRTUEMART_FILES_FORM_LANGUAGE_TIP') . '">' . vmText::_('COM_VIRTUEMART_FILES_FORM_LANGUAGE') . '</span></td>
					<td><fieldset class="inputbox">' . $languages . '</fieldset></td>
					</tr>';
        }
        if (VmConfig::get('multix', 'none') != 'none') {
            if (empty($this->virtuemart_vendor_id)) {
                $vendorId = vmAccess::isSuperVendor();
            } else {
                $vendorId = $this->virtuemart_vendor_id;
            }
            if (!class_exists('ShopFunctions')) {
                require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php';
            }
            $vendorList = ShopFunctions::renderVendorList($vendorId, 'media[virtuemart_vendor_id]');
            $html .= VmHTML::row('raw', 'COM_VIRTUEMART_VENDOR', $vendorList);
        }
        $html .= '</table>';
        $html .= '<br /></fieldset>';
        $this->addMediaActionByType();
        $html .= '<fieldset class="checkboxes">';
        $html .= '<legend>' . vmText::_('COM_VIRTUEMART_FILE_UPLOAD') . '</legend>';
        $html .= vmText::_('COM_VIRTUEMART_IMAGE_ACTION') . JHtml::_('select.radiolist', $this->getOptions($this->_actions), 'media[media_action]', '', 'value', 'text', 0) . '<br /><br style="clear:both" />';
        $html .= vmText::_('COM_VIRTUEMART_FILE_UPLOAD') . ' <input type="file" name="upload" id="upload" size="50" class="inputbox" /><br />';
        $html .= '<br />' . $this->displaySupportedImageTypes();
        $html .= '<br /></fieldset>';
        $html .= $this->displayFoldersWriteAble();
        $html .= $this->displayHidden();
        //		$html .= '</form>';
        return $html;
    }
Exemple #22
0
 /**
  * Save the user info. The saveData function don't use the userModel store function for anonymous shoppers, because it would register them.
  * We make this function private, so we can do the tests in the tasks.
  *
  * @author Max Milbers
  * @author Valérie Isaksen
  *
  * @param boolean Defaults to false, the param is for the userModel->store function, which needs it to determine how to handle the data.
  * @return String it gives back the messages.
  */
 private function saveData($cartObj)
 {
     $mainframe = JFactory::getApplication();
     $msg = true;
     $data = vRequest::getPost(FILTER_SANITIZE_STRING);
     $register = isset($_REQUEST['register']);
     $userModel = tmsModel::getModel('user');
     $currentUser = JFactory::getUser();
     if (empty($data['address_type'])) {
         $data['address_type'] = vRequest::getCmd('addrtype', 'BT');
     }
     if ($cartObj) {
         if ($cartObj->_fromCart or $cartObj->getInCheckOut()) {
             if (!class_exists('VirtueMartCart')) {
                 require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
             }
             $cart = VirtueMartCart::getCart();
             $prefix = '';
             if ($data['address_type'] == 'STaddress' || $data['address_type'] == 'ST') {
                 $prefix = 'shipto_';
                 vmdebug('Storing user ST prefix ' . $prefix);
             }
             $cart->saveAddressInCart($data, $data['address_type'], true, $prefix);
         }
     }
     if (isset($data['vendor_accepted_currencies'])) {
         // Store multiple selectlist entries as a ; separated string
         if (array_key_exists('vendor_accepted_currencies', $data) && is_array($data['vendor_accepted_currencies'])) {
             $data['vendor_accepted_currencies'] = implode(',', $data['vendor_accepted_currencies']);
         }
         $data['vendor_store_name'] = vRequest::getHtml('vendor_store_name');
         $data['vendor_store_desc'] = vRequest::getHtml('vendor_store_desc');
         $data['vendor_terms_of_service'] = vRequest::getHtml('vendor_terms_of_service');
         $data['vendor_letter_css'] = vRequest::getHtml('vendor_letter_css');
         $data['vendor_letter_header_html'] = vRequest::getHtml('vendor_letter_header_html');
         $data['vendor_letter_footer_html'] = vRequest::getHtml('vendor_letter_footer_html');
     }
     if ($data['address_type'] == 'ST' and !$currentUser->guest) {
         $ret = $userModel->storeAddress($data);
         $msg = is_array($ret) ? $ret['message'] : $ret;
         if ($cartObj and !empty($ret)) {
             $cartObj->selected_shipto = $ret;
             $cartObj->setCartIntoSession();
         }
     } else {
         if ($currentUser->guest == 1 and ($register or !$cartObj)) {
             if ($this->checkCaptcha('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT') == FALSE) {
                 $msg = tsmText::_('PLG_RECAPTCHA_ERROR_INCORRECT_CAPTCHA_SOL');
                 if ($cartObj and $cartObj->_fromCart) {
                     $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'), $msg);
                 } else {
                     if ($cartObj and $cartObj->getInCheckOut()) {
                         $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT'), $msg);
                     } else {
                         $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=edit&addrtype=BT'), $msg);
                     }
                 }
                 return $msg;
             }
         }
         if ($currentUser->guest != 1 or !$cartObj or $currentUser->guest == 1 and $register) {
             $switch = false;
             if ($currentUser->guest == 1 and $register) {
                 $userModel->setId(0);
                 $superUser = vmAccess::isSuperVendor();
                 if ($superUser > 1) {
                     $data['vendorId'] = $superUser;
                 }
                 $switch = true;
             }
             if (!class_exists('VirtueMartCart')) {
                 require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
             }
             $cart = VirtueMartCart::getCart();
             if (!empty($cart->vendorId) and $cart->vendorId != 1) {
                 $data['vendorId'] = $cart->vendorId;
             }
             $ret = $userModel->store($data);
             if ($switch) {
                 //and VmConfig::get ('oncheckout_change_shopper')){
                 //update session
                 $current = JFactory::getUser($ret['newId']);
                 $session = JFactory::getSession();
                 $session->set('user', $current);
             }
             $msg = is_array($ret) ? $ret['message'] : $ret;
         }
         if ($currentUser->guest == 1 and ($register or !$cartObj)) {
             $usersConfig = JComponentHelper::getParams('com_users');
             $useractivation = $usersConfig->get('useractivation');
             if (is_array($ret) and $ret['success'] and !$useractivation) {
                 // Username and password must be passed in an array
                 $credentials = array('username' => $ret['user']->username, 'password' => $ret['user']->password_clear);
                 $return = $mainframe->login($credentials);
             } else {
                 if (tsmConfig::get('oncheckout_only_registered', 0)) {
                     $layout = vRequest::getCmd('layout', 'edit');
                     $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&layout=' . $layout, FALSE), $msg);
                 }
             }
         }
     }
     if (isset($ret['success'])) {
         return $ret['success'];
     } else {
         return $msg;
     }
 }