function get($cid = 0, $default = '') { if (!empty($cid)) { $widget = parent::get($cid); if (!empty($widget->widget_params)) { $widget->widget_params = unserialize($widget->widget_params); if (!empty($widget->widget_params->status)) { $widget->widget_params->status = explode(',', $widget->widget_params->status); } } return $widget; } $filters = array(); $filters[] = 'widget_published=1'; hikashop_addACLFilters($filters, 'widget_access'); $filters = implode(' AND ', $filters); $query = 'SELECT * FROM ' . hikashop_table('widget') . ' WHERE ' . $filters . ' ORDER BY widget_ordering ASC'; $this->database->setQuery($query); $widgets = $this->database->loadObjectList(); if (!empty($widgets)) { foreach ($widgets as $k => $widget) { if (!empty($widget->widget_params)) { $widgets[$k]->widget_params = unserialize($widget->widget_params); if (!empty($widgets[$k]->widget_params->status)) { $widgets[$k]->widget_params->status = explode(',', $widgets[$k]->widget_params->status); } } } } return $widgets; }
function getCategories($filter, $datas = '') { $left = ''; $filters = array('a.category_published=1'); if (!empty($datas['products'])) { $left = ' LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.category_id=b.category_id '; $optionElement = ''; foreach ($datas['products'] as $data) { $optionElement[$data->product_id] = $data->product_id; } $filters[] = 'b.product_id IN (' . implode(',', $optionElement) . ')'; } if (!empty($filter->filter_options['parent_category_id'])) { $parentCat = $filter->filter_options['parent_category_id']; } else { $parentCat = 0; } $filters[] = 'a.category_parent_id=' . (int) $parentCat; hikashop_addACLFilters($filters, 'category_access', 'a'); $database = JFactory::getDBO(); $query = 'SELECT * FROM ' . hikashop_table('category') . ' AS a ' . $left . ' WHERE ' . implode(' AND ', $filters) . ' ORDER BY a.category_ordering ASC'; $database->setQuery($query); $categories_name = $database->loadObjectList('category_id'); return $categories_name; }
function check(&$coupon, &$total, $zones, &$products, $display_error = true) { JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $error_message = ''; $do = true; if (isset($coupon->discount_value)) { $coupon = $this->get($coupon->discount_id); } $dispatcher->trigger('onBeforeCouponCheck', array(&$coupon, &$total, &$zones, &$products, &$display_error, &$error_message, &$do)); if ($do) { $user = hikashop_get('class.user'); $currency = hikashop_get('class.currency'); if (empty($coupon)) { $error_message = JText::_('COUPON_NOT_VALID'); } elseif ($coupon->discount_start > time()) { $error_message = JText::_('COUPON_NOT_YET_USABLE'); } elseif ($coupon->discount_end && $coupon->discount_end < time()) { $error_message = JText::_('COUPON_EXPIRED'); } elseif (hikashop_level(2) && !empty($coupon->discount_access) && $coupon->discount_access != 'all' && ($coupon->discount_access == 'none' || !hikashop_isAllowed($coupon->discount_access))) { $error_message = JText::_('COUPON_NOT_FOR_YOU'); } elseif (empty($error_message) && hikashop_level(1) && !empty($coupon->discount_quota) && $coupon->discount_quota <= $coupon->discount_used_times) { $error_message = JText::_('QUOTA_REACHED_FOR_COUPON'); } elseif (empty($error_message) && hikashop_level(1)) { if (!empty($coupon->discount_quota_per_user)) { $user_id = hikashop_loadUser(); if ($user_id) { $db = JFactory::getDBO(); $config =& hikashop_config(); $cancelled_order_status = explode(',', $config->get('cancelled_order_status')); $cancelled_order_status = "'" . implode("','", $cancelled_order_status) . "'"; $query = 'SELECT COUNT(order_id) AS already_used FROM ' . hikashop_table('order') . ' WHERE order_user_id=' . (int) $user_id . ' AND order_status NOT IN (' . $cancelled_order_status . ') AND order_discount_code=' . $db->Quote($coupon->discount_code) . ' GROUP BY order_id'; $db->setQuery($query); $already_used = $db->loadResult(); if ($coupon->discount_quota_per_user <= $already_used) { $error_message = JText::_('QUOTA_REACHED_FOR_COUPON'); } } } if (empty($error_message) && $coupon->discount_zone_id) { if (!is_array($coupon->discount_zone_id)) { $coupon->discount_zone_id = explode(',', $coupon->discount_zone_id); } $class = hikashop_get('class.zone'); $zone = $class->getZones($coupon->discount_zone_id, 'zone_namekey', 'zone_namekey', true); if ($zone && !count(array_intersect($zone, $zones))) { $error_message = JText::_('COUPON_NOT_AVAILABLE_IN_YOUR_ZONE'); } } $ids = array(); $qty = 0; foreach ($products as $prod) { $qty += $prod->cart_product_quantity; if (!empty($prod->product_parent_id)) { $ids[$prod->product_parent_id] = (int) $prod->product_parent_id; } else { $ids[$prod->product_id] = (int) $prod->product_id; } } if (empty($ids)) { $error_message = JText::_('COUPON_NOT_FOR_EMPTY_CART'); } if (!empty($coupon->discount_product_id) && is_string($coupon->discount_product_id)) { $coupon->discount_product_id = explode(',', $coupon->discount_product_id); } if (empty($error_message) && !empty($coupon->discount_product_id) && count(array_intersect($ids, $coupon->discount_product_id)) == 0) { $error_message = JText::_('COUPON_NOT_FOR_THOSE_PRODUCTS'); } if (empty($error_message) && $coupon->discount_category_id) { $db = JFactory::getDBO(); if (!is_array($coupon->discount_category_id)) { $coupon->discount_category_id = explode(',', trim($coupon->discount_category_id, ',')); } if ($coupon->discount_category_childs) { $filters = array('b.category_type=\'product\'', 'a.product_id IN (' . implode(',', $ids) . ')'); $categoryClass = hikashop_get('class.category'); $categories = $categoryClass->getCategories($coupon->discount_category_id, 'category_left, category_right'); if (!empty($categories)) { $categoriesFilters = array(); foreach ($categories as $category) { $categoriesFilters[] = 'b.category_left >= ' . $category->category_left . ' AND b.category_right <= ' . $category->category_right; } if (count($categoriesFilters)) { $filters[] = '((' . implode(') OR (', $categoriesFilters) . '))'; hikashop_addACLFilters($filters, 'category_access', 'b'); $select = 'SELECT a.product_id FROM ' . hikashop_table('category') . ' AS b LEFT JOIN ' . hikashop_table('product_category') . ' AS a ON b.category_id=a.category_id WHERE ' . implode(' AND ', $filters); $db->setQuery($select); $id = $db->loadRowList(); if (empty($id)) { $error_message = JText::_('COUPON_NOT_FOR_PRODUCTS_IN_THOSE_CATEGORIES'); } } } } else { JArrayHelper::toInteger($coupon->discount_category_id); $filters = array('b.category_id IN (' . implode(',', $coupon->discount_category_id) . ')', 'a.product_id IN (' . implode(',', $ids) . ')'); hikashop_addACLFilters($filters, 'category_access', 'b'); $select = 'SELECT a.product_id FROM ' . hikashop_table('category') . ' AS b LEFT JOIN ' . hikashop_table('product_category') . ' AS a ON b.category_id=a.category_id WHERE ' . implode(' AND ', $filters); $db->setQuery($select); $id = $db->loadRowList(); if (empty($id)) { $error_message = JText::_('COUPON_NOT_FOR_PRODUCTS_IN_THOSE_CATEGORIES'); } } } $coupon->products = array(); if (!empty($coupon->discount_product_id)) { foreach ($products as $product) { if (!in_array($product->product_id, $coupon->discount_product_id)) { foreach ($products as $product2) { if ($product2->cart_product_id == $product->cart_product_parent_id && in_array($product2->product_id, $coupon->discount_product_id)) { $coupon->products[] = $product; } } } else { $coupon->products[] = $product; } } } else { if (!empty($id)) { foreach ($products as $product) { foreach ($id as $productid) { if ($product->product_id !== $productid[0]) { foreach ($products as $product2) { if ($product2->cart_product_id == $product->cart_product_parent_id && $product2->product_id == $productid[0]) { $coupon->products[] = $product; } } } else { $coupon->products[] = $product; } } } } else { foreach ($products as $product) { $coupon->products[] = $product; } $coupon->all_products = true; } } if (empty($error_message) && bccomp($coupon->discount_minimum_order, 0, 5)) { $currency->convertCoupon($coupon, $total->prices[0]->price_currency_id); $config =& hikashop_config(); $discount_before_tax = $config->get('discount_before_tax'); $var = 'price_value_with_tax'; if ($discount_before_tax) { $var = 'price_value'; } $total_amount = 0; if (!empty($coupon->products)) { foreach ($coupon->products as $product) { if ($product->cart_product_quantity > 0) { $total_amount += @$product->prices[0]->{$var}; } } } if ($coupon->discount_minimum_order > $total_amount) { $error_message = JText::sprintf('ORDER_NOT_EXPENSIVE_ENOUGH_FOR_COUPON', $currency->format($coupon->discount_minimum_order, $coupon->discount_currency_id)); } } if (empty($error_message) && (int) $coupon->discount_minimum_products > 0) { $qty = 0; if (!empty($coupon->products)) { foreach ($coupon->products as $product) { $qty += $product->cart_product_quantity; } } if ((int) $coupon->discount_minimum_products > $qty) { $error_message = JText::sprintf('NOT_ENOUGH_PRODUCTS_FOR_COUPON', (int) $coupon->discount_minimum_products); } } } } $dispatcher->trigger('onAfterCouponCheck', array(&$coupon, &$total, &$zones, &$products, &$display_error, &$error_message, &$do)); if (!empty($error_message)) { $class = hikashop_get('class.cart'); $class->update('', 0, 0, 'coupon'); if ($display_error) { JRequest::setVar('coupon_error_message', $error_message); } return null; } JRequest::setVar('coupon_error_message', ''); if ($do) { $currency->convertCoupon($coupon, $total->prices[0]->price_currency_id); if (!HIKASHOP_PHP5) { $coupon->total = $total; } else { if (!isset($coupon->total)) { $coupon->total = new stdClass(); } $coupon->total->prices = array(clone reset($total->prices)); } $this->recalculateDiscountValue($coupon, $products, $id); switch (@$coupon->discount_coupon_nodoubling) { case 1: case 2: $coupon = $this->addCoupon($coupon, $products, $currency, $coupon->discount_coupon_nodoubling); break; default: $currency->addCoupon($coupon->total, $coupon, $products, $id); break; } } return $coupon; }
function waitlist() { $user = hikashop_loadUser(true); $this->assignRef('element', $user); $app = JFactory::getApplication(); $product_id = (int) hikashop_getCID('product_id'); $config =& hikashop_config(); $this->assignRef('config', $config); $filters = array('a.product_id=' . $product_id); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT a.*,b.product_category_id, b.category_id, b.ordering FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' LIMIT 1'; $database = JFactory::getDBO(); $database->setQuery($query); $element = $database->loadObject(); if (empty($element)) { return; } if ($element->product_type == 'variant') { $this->selected_variant_id = $product_id; $filters = array('a.product_id=' . $element->product_parent_id); hikashop_addACLFilters($filters, 'product_access', 'a'); $query = 'SELECT a.*,b.* FROM ' . hikashop_table('product') . ' AS a LEFT JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id = b.product_id WHERE ' . implode(' AND ', $filters) . ' LIMIT 1'; $database->setQuery($query); $main = $database->loadObject(); if (empty($main)) { return; } $main->variants = array($element); $element = $main; $product_id = $element->product_id; $ids = array($element->variants[0]->product_id, $product_id); $query = 'SELECT a.*,b.* FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ') ORDER BY a.ordering,b.characteristic_value'; $database->setQuery($query); $characteristics = $database->loadObjectList(); if (!empty($characteristics)) { $mainCharacteristics = array(); foreach ($characteristics as $characteristic) { if ($product_id == $characteristic->variant_product_id) { $mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } } $cartClass = hikashop_get('class.cart'); $cartClass->addCharacteristics($element, $mainCharacteristics, $characteristics); $productClass = hikashop_get('class.product'); $productClass->checkVariant($element->variants[0], $element); $element = $element->variants[0]; } } $productClass = hikashop_get('class.product'); $productClass->addAlias($element); if (!$element->product_published) { return; } $this->assignRef('product', $element); global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $product_url = hikashop_contentLink('product&task=show&cid=' . (int) $element->product_id . '&name=' . $element->alias . $url_itemid, $element); $this->assignRef('product_url', $product_url); }
function listing() { $config =& hikashop_config(); $this->assignRef('config', $config); $module = hikashop_get('helper.module'); $module->initialize($this); $this->paramBase .= '_' . $this->params->get('main_div_name'); $filters = array(); $app = JFactory::getApplication(); $pageInfo = new stdClass(); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->limit = new stdClass(); $catData = null; $database = JFactory::getDBO(); $defaultParams = $config->get('default_params'); if (empty($defaultParams['links_on_main_categories'])) { $defaultParams['links_on_main_categories'] = 1; } $params = array('limit' => '', 'order_dir' => 'inherit', 'margin' => '', 'border_visible' => '-1', 'div_item_layout_type' => 'inherit', 'text_center' => '-1', 'columns' => '', 'number_of_products' => '-1', 'background_color' => '', 'link_to_product_page' => '-1', 'only_if_products' => '-1', 'child_display_type' => 'inherit', 'child_limit' => '', 'links_on_main_categories' => '-1', 'layout_type' => 'inherit'); $data = $this->params->get('data', new stdClass()); if (isset($data->hk_category) && is_object($data->hk_category)) { $categoryId = (int) $this->params->get('category', 0); if ($categoryId > 0) { $categoryClass = hikashop_get('class.category'); $cat = $categoryClass->get($categoryId); if ($cat->category_type == 'manufacturer') { $this->params->set('content_type', 'manufacturer'); } } if (!empty($data->hk_category->category)) { $this->params->set('selectparentlisting', (int) $data->hk_category->category); } } foreach ($params as $k => $v) { if ($this->params->get($k, $v) == $v) { $this->params->set($k, @$defaultParams[$k]); } } if ((int) $this->params->get('limit') == 0) { $this->params->set('limit', 1); } $content_type = $this->params->get('content_type'); if ($content_type == 'manufacturer') { $category_type = 'manufacturer'; $id = JRequest::getInt("cid"); $class = hikashop_get('class.category'); $new_id = 'manufacturer'; $class->getMainElement($new_id); $this->params->set('selectparentlisting', $new_id); } else { $category_type = 'product'; } if ($this->params->get('content_synchronize')) { if (JRequest::getString('option', '') == HIKASHOP_COMPONENT) { if (JRequest::getString('ctrl', 'category') == 'product') { $product_id = hikashop_getCID('product_id'); if (!empty($product_id)) { $query = 'SELECT category_id FROM ' . hikashop_table('product_category') . ' WHERE product_id=' . $product_id; $database->setQuery($query); if (!HIKASHOP_J25) { $pageInfo->filter->cid = $database->loadResultArray(); } else { $pageInfo->filter->cid = $database->loadColumn(); } } else { $pageInfo->filter->cid = $this->params->get('selectparentlisting'); } } elseif (JRequest::getString('ctrl', 'category') == 'category') { $pageInfo->filter->cid = JRequest::getInt("cid", $this->params->get('selectparentlisting')); } else { $pageInfo->filter->cid = $this->params->get('selectparentlisting'); } } else { $pageInfo->filter->cid = $this->params->get('selectparentlisting'); } } else { if (empty($this->module)) { $pageInfo->filter->cid = JRequest::getInt("cid", $this->params->get('selectparentlisting')); } else { $pageInfo->filter->cid = $this->params->get('selectparentlisting'); } } if (empty($pageInfo->filter->cid)) { $pageInfo->filter->cid = 'product'; } $category_selected = ''; if (!is_array($pageInfo->filter->cid)) { $category_selected = '_' . $pageInfo->filter->cid; $this->paramBase .= $category_selected; } if (!empty($pageInfo->filter->cid)) { $acl_filters = array(); hikashop_addACLFilters($acl_filters, 'category_access'); if (!empty($acl_filters)) { if (!is_array($pageInfo->filter->cid)) { $category = hikashop_get('class.category'); $catData = $category->get($pageInfo->filter->cid); if (!empty($catData->category_type)) { $category_type = $catData->category_type; } $pageInfo->filter->cid = array($database->Quote($pageInfo->filter->cid)); } $acl_filters[] = 'category_type=\'' . $category_type . '\''; $acl_filters[] = 'category_id IN (' . implode(',', $pageInfo->filter->cid) . ')'; $query = 'SELECT category_id FROM ' . hikashop_table('category') . ' WHERE ' . implode(' AND ', $acl_filters); $database->setQuery($query); if (!HIKASHOP_J25) { $pageInfo->filter->cid = $database->loadResultArray(); } else { $pageInfo->filter->cid = $database->loadColumn(); } } } $this->assignRef('category_selected', $category_selected); if ($this->params->get('category_order', 'inherit') == 'inherit') { $defaultParams = $config->get('default_params'); $this->params->set('category_order', $defaultParams['category_order']); if ($this->params->get('category_order', 'inherit') == 'inherit') { $this->params->set('category_order', 'category_ordering'); } } if ($this->params->get('order_dir', 'inherit') == 'inherit' || $this->params->get('order_dir', 'inherit') == '') { $defaultParams = $config->get('default_params'); $this->params->set('order_dir', @$defaultParams['order_dir']); if ($this->params->get('order_dir', 'inherit') == 'inherit' || $this->params->get('order_dir', 'inherit') == '') { $this->params->set('order_dir', 'ASC'); } } $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir_' . $this->params->get('main_div_name') . $category_selected, $this->params->get('order_dir', 'ASC'), 'word'); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order_' . $this->params->get('main_div_name') . $category_selected, 'a.' . $this->params->get('category_order', 'category_ordering'), 'cmd'); if (!in_array(strtoupper($pageInfo->filter->order->dir), array('ASC', 'DESC'))) { $pageInfo->filter->order->dir = 'ASC'; } $oldValue = $app->getUserState($this->paramBase . '.list_limit'); if ($this->params->get('limit', '') == '') { $defaultParams = $config->get('default_params'); $this->params->set('limit', $defaultParams['limit']); } if (empty($oldValue)) { $oldValue = $this->params->get('limit'); } $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit_' . $this->params->get('main_div_name') . $category_selected, $this->params->get('limit'), 'int'); if ($oldValue != $pageInfo->limit->value) { JRequest::setVar('limitstart_' . $this->params->get('main_div_name') . $category_selected, 0); } $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart_' . $this->params->get('main_div_name') . $category_selected, 0, 'int'); if (empty($this->module)) { if ($config->get('hikarss_format') != 'none') { $doc_title = $config->get('hikarss_name', ''); if (empty($doc_title)) { if (!isset($catData)) { $category = hikashop_get('class.category'); if (is_array($pageInfo->filter->cid)) { $cat = reset($pageInfo->filter->cid); } else { $cat = $pageInfo->filter->cid; } $catData = $category->get($cat); } if ($catData) { $doc_title = $catData->category_name; } } if (!HIKASHOP_PHP5) { $doc =& JFactory::getDocument(); } else { $doc = JFactory::getDocument(); } if ($config->get('hikarss_format') != 'both') { $link = '&format=feed&limitstart='; $attribs = array('type' => 'application/rss+xml', 'title' => $doc_title . ' RSS 2.0'); $doc->addHeadLink(JRoute::_($link . '&type=' . $config->get('hikarss_format')), 'alternate', 'rel', $attribs); } else { $link = '&format=feed&limitstart='; $attribs = array('type' => 'application/rss+xml', 'title' => $doc_title . ' RSS 2.0'); $doc->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs); $attribs = array('type' => 'application/atom+xml', 'title' => $doc_title . ' Atom 1.0'); $doc->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs); } } $cid = JRequest::getInt("cid", 0); if (empty($cid)) { JRequest::setVar("no_cid", 1); } if (is_array($pageInfo->filter->cid)) { JRequest::setVar("cid", reset($pageInfo->filter->cid)); } else { JRequest::setVar("cid", $pageInfo->filter->cid); } JRequest::setVar('menu_main_category', $this->params->get('selectparentlisting')); } $searchMap = array('a.category_name', 'a.category_description', 'a.category_id'); $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } if ($this->params->get('random', '-1') == '-1') { $defaultParams = $config->get('default_params'); $this->params->set('random', $defaultParams['random']); } if ($this->params->get('random')) { $order = ' ORDER BY RAND()'; } $class = hikashop_get('class.category'); $class->parentObject =& $this; if ($this->params->get('filter_type', 2) == 2) { $config =& hikashop_config(); $defaultParams = $config->get('default_params'); $this->params->set('filter_type', $defaultParams['filter_type']); } $rows = $class->getChildren($pageInfo->filter->cid, $this->params->get('filter_type'), $filters, $order, $pageInfo->limit->start, $pageInfo->limit->value, true); $pageInfo->elements = new stdClass(); if (!empty($class->query)) { $database->setQuery('SELECT COUNT(*) ' . $class->query); $pageInfo->elements->total = $database->loadResult(); $pageInfo->elements->page = count($rows); } else { $pageInfo->elements->total = 0; $pageInfo->elements->page = 0; } if ($pageInfo->elements->page) { $ids = array(); foreach ($rows as $key => $row) { $ids[(int) $row->category_id] = (int) $row->category_id; $class->addAlias($rows[$key]); } if ($this->params->get('number_of_products', '-1') == '-1') { $defaultParams = $config->get('default_params'); $this->params->set('number_of_products', @$defaultParams['number_of_products']); } if ($this->params->get('only_if_products', '-1') == '-1') { $defaultParams = $config->get('default_params'); $this->params->set('only_if_products', @$defaultParams['only_if_products']); } $number_of_products = $this->params->get('number_of_products', 0) || $this->params->get('only_if_products', 0); if ($this->params->get('child_display_type', 'inherit') == 'inherit') { $defaultParams = $config->get('default_params'); $this->params->set('child_display_type', $defaultParams['child_display_type']); } if ($this->params->get('child_display_type') != 'nochild' || $number_of_products) { $childs = $class->getChildren($ids, true, array(), $order, 0, 0, false); if (!empty($childs)) { $this->_associateChilds($rows, $childs); foreach ($childs as $child) { if (is_numeric($child)) { $ids[$child] = $child; } else { $ids[(int) $child->category_id] = (int) $child->category_id; } } } if ($number_of_products) { $additional_condition = ''; if ($content_type == 'manufacturer') { if (!$config->get('show_out_of_stock', 1)) { $additional_condition = ' AND a.product_quantity!=0'; } $database->setQuery('SELECT count(a.product_id) AS number_of_products,a.product_manufacturer_id as category_id FROM ' . hikashop_table('product') . ' AS a WHERE a.product_published>0' . $additional_condition . ' AND a.product_parent_id=0 AND a.product_manufacturer_id IN (' . implode(',', $ids) . ') GROUP BY a.product_manufacturer_id'); } else { if (!$config->get('show_out_of_stock', 1)) { $additional_condition = ' AND b.product_quantity!=0'; } $database->setQuery('SELECT count(a.product_id) AS number_of_products,a.category_id FROM ' . hikashop_table('product_category') . ' AS a INNER JOIN ' . hikashop_table('product') . ' AS b ON a.product_id=b.product_id AND b.product_published>0' . $additional_condition . ' AND b.product_parent_id=0 WHERE a.category_id IN (' . implode(',', $ids) . ') GROUP BY a.category_id'); } $counts = $database->loadObjectList('category_id'); $this->_getCount($rows, $counts); } } } $this->assignRef('rows', $rows); $this->assignRef('modules', $this->modules); $image = hikashop_get('helper.image'); $this->assignRef('image', $image); $this->assignRef('category_image', $category_image); $menu_id = ''; if (empty($this->module)) { if (is_array($pageInfo->filter->cid)) { $pageInfo->filter->cid = reset($pageInfo->filter->cid); } $element = $class->get($pageInfo->filter->cid, true); $fieldsClass = hikashop_get('class.field'); $fields = $fieldsClass->getFields('frontcomp', $element, 'category', 'checkout&task=state'); $this->assignRef('fieldsClass', $fieldsClass); $this->assignRef('fields', $fields); $this->assignRef('element', $element); $use_module = $this->params->get('use_module_name'); $title = $this->params->get('page_title'); if (empty($title)) { $title = $this->params->get('title'); } if (empty($use_module) && !empty($element->category_name)) { $title = $element->category_name; } if (!empty($element->category_page_title)) { $page_title = $element->category_page_title; } else { $page_title = $title; } hikashop_setPageTitle($page_title); $this->params->set('page_title', $title); if (!HIKASHOP_PHP5) { $document =& JFactory::getDocument(); } else { $document = JFactory::getDocument(); } if (!empty($element->category_keywords)) { $document->setMetadata('keywords', $element->category_keywords); } if (!empty($element->category_meta_description)) { $document->setMetadata('description', $element->category_meta_description); } $pagination = hikashop_get('helper.pagination', $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value); $pagination->hikaSuffix = '_' . $this->params->get('main_div_name') . $category_selected; $this->assignRef('pagination', $pagination); $this->params->set('show_limit', 1); if (!HIKASHOP_PHP5) { $pathway =& $app->getPathway(); } else { $pathway = $app->getPathway(); } $categories = $class->getParents($cid, $this->params->get('selectparentlisting')); global $Itemid; if (!empty($Itemid)) { $menu_id = '&Itemid=' . $Itemid; } $one = true; if (is_array($categories)) { foreach ($categories as $category) { if ($one) { $one = false; } else { $class->addAlias($category); $alias = $category->alias; $pathway->addItem($category->category_name, hikashop_completeLink('category&task=listing&cid=' . (int) $category->category_id . '&name=' . $alias . $menu_id)); } } } } else { $menu_id = $this->params->get('itemid', 0); if (!empty($menu_id)) { $menu_id = '&Itemid=' . $menu_id; } else { $menu_id = ''; } } $this->assignRef('pageInfo', $pageInfo); $this->assignRef('menu_id', $menu_id); $this->assignRef('params', $this->params); }
function onSearch($text, $phrase = '', $ordering = '', $areas = null) { if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return array(); } $db = JFactory::getDBO(); $types = array(); if (!empty($areas) && is_array($areas)) { $valid = array_keys($this->onSearchAreas()); $use = array_intersect($areas, $valid); if (!$use) { return array(); } if (in_array('categories', $valid)) { $types[] = '\'product\''; } if (in_array('manufacturers', $valid)) { $types[] = '\'manufacturer\''; } } else { $types[] = '\'product\''; if (1 == (int) $this->params->get('manufacturers', '1')) { $types[] = '\'manufacturer\''; } } $limit = $this->params->def('search_limit', 50); $text = trim($text); if ($text == '') { return array(); } switch ($ordering) { case 'alpha': $order = 'a.category_name ASC'; break; case 'newest': $order = 'a.category_modified DESC'; break; case 'oldest': $order = 'a.category_created ASC'; break; case 'category': case 'popular': default: $order = 'a.category_name DESC'; break; } $trans = hikashop_get('helper.translation'); $multi = $trans->isMulti(); $trans_table = 'jf_content'; if ($trans->falang) { $trans_table = 'falang_content'; } $rows = array(); $filters = array('a.category_published=1'); if (count($types)) { $filters[] = 'a.category_type IN (' . implode(',', $types) . ')'; } else { $filters[] = 'a.category_type NOT IN (\'status\',\'tax\')'; } hikashop_addACLFilters($filters, 'category_access', 'a'); $filters2 = array(); if ($multi) { $registry = JFactory::getConfig(); if (!HIKASHOP_J25) { $code = $registry->getValue('config.jflang'); } else { $code = $registry->get('language'); } $myLang = $trans->getId($code); $filters2[] = "b.reference_table='hikashop_category'"; $filters2[] = "b.published=1"; $filters2[] = 'b.language_id=' . $myLang; } switch ($phrase) { case 'exact': $text = $db->Quote('%' . hikashop_getEscaped($text, true) . '%', false); $filters1 = array(); $filters1[] = "a.category_name LIKE " . $text; $filters1[] = "a.category_description LIKE " . $text; if ($multi) { $filters2[] = "b.value LIKE " . $text; } break; case 'all': case 'any': default: $words = explode(' ', $text); $wordFilters = array(); $subWordFilters1 = array(); $subWordFilters2 = array(); $wordFilters2 = array(); foreach ($words as $word) { $word = $db->Quote('%' . hikashop_getEscaped($word, true) . '%', false); $subWordFilters1[] = "a.category_name LIKE " . $word; $subWordFilters2[] = "a.category_description LIKE " . $word; if ($multi) { $wordFilters2[] = "b.value LIKE " . $word; } } $wordFilters[0] = '((' . implode($phrase == 'all' ? ') AND (' : ') OR (', $subWordFilters1) . '))'; $wordFilters[1] = '((' . implode($phrase == 'all' ? ') AND (' : ') OR (', $subWordFilters2) . '))'; $filters[] = '((' . implode(') OR (', $wordFilters) . '))'; if ($multi) { $filters2[] = '((' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wordFilters2) . '))'; } break; } $new_page = (int) $this->params->get('new_page', '1'); $select = ' a.category_type AS section, a.category_id AS id, a.category_name AS title, a.category_created AS created , a.category_description AS text, "' . $new_page . '" AS browsernav, a.category_canonical, a.category_alias'; $count = 0; if ($multi && !empty($myLang)) { $query = ' SELECT DISTINCT ' . $select . ' FROM ' . hikashop_table($trans_table, false) . ' AS b LEFT JOIN ' . hikashop_table('category') . ' AS a ON b.reference_id=a.category_id WHERE ' . implode(' AND ', $filters2) . ' ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList("id"); $count = count($rows); if ($count) { $limit = $limit - $count; $ids = array_keys($rows); JArrayHelper::toInteger($ids); $filters[] = 'a.category_id NOT IN (' . implode(',', $ids) . ')'; } } if ($limit) { $filters = implode(' AND ', $filters); if (isset($filters1)) { $filters = '(' . $filters . ') AND (' . implode(' OR ', $filters1) . ')'; } $query = ' SELECT ' . $select . ' FROM ' . hikashop_table('category') . ' AS a WHERE ' . $filters . ' ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $mainRows = $db->loadObjectList("id"); if (!empty($mainRows)) { foreach ($mainRows as $k => $main) { $rows[$k] = $main; } $count = count($rows); } } if ($count) { if ($multi && !empty($myLang)) { $query = ' SELECT * FROM ' . hikashop_table($trans_table, false) . ' WHERE reference_table=\'hikashop_category\' AND language_id=\'' . $myLang . '\' AND published=1 AND reference_id IN (' . implode(',', array_keys($rows)) . ')'; $db->setQuery($query); $trans = $db->loadObjectList(); foreach ($trans as $item) { foreach ($rows as $key => $row) { if ($row->id == $item->reference_id) { if ($item->reference_field == 'category_name') { $row->title = $item->value; } elseif ($item->reference_field == 'category_description') { $row->text = $item->value; } break; } } } } $item_id = $this->params->get('item_id', ''); $menuClass = hikashop_get('class.menus'); if (!empty($item_id)) { $item_id = $menuClass->loadAMenuItemId('category', 'listing', $item_id); } $Itemid = ""; if (!empty($item_id)) { $Itemid = '&Itemid=' . $item_id; } $manu_item_id = $this->params->get('manu_item_id', ''); if (!empty($manu_item_id)) { $manu_item_id = $menuClass->loadAMenuItemId('manufacturer', 'listing', $manu_item_id); } $manu_Itemid = ''; if (!empty($manu_item_id)) { $manu_Itemid = '&Itemid=' . $manu_item_id; } $itemids = array(); $categoryClass = hikashop_get('class.category'); foreach ($rows as $k => $row) { $row->category_name = $row->title; $categoryClass->addAlias($row); if (!empty($row->category_canonical)) { $rows[$k]->href = $row->category_canonical; } else { if (empty($manu_item_id) && !empty($row->id) && $row->section == 'manufacturer') { if (!isset($itemids[$row->id])) { $itemids[$row->id] = $menuClass->getItemidFromCategory($row->id, $row->section); } $manu_item_id = $itemids[$row->id]; if (!empty($manu_item_id)) { $manu_Itemid = '&Itemid=' . $manu_item_id; } if (!$this->params->get('manu_item_id', '')) { $manu_item_id = ''; } } elseif (empty($item_id) && !empty($row->id) && $row->section != 'manufacturer') { if (!isset($itemids[$row->id])) { $itemids[$row->id] = $menuClass->getItemidFromCategory($row->id, 'category'); } $item_id = $itemids[$row->id]; if (!empty($item_id)) { $Itemid = '&Itemid=' . $item_id; } if (!$this->params->get('item_id', '')) { $item_id = ''; } } if ($row->section == 'manufacturer') { $rows[$k]->href = 'index.php?option=com_hikashop&ctrl=category&task=listing&name=' . $row->alias . '&cid=' . $row->id . $manu_Itemid; } else { $rows[$k]->href = 'index.php?option=com_hikashop&ctrl=category&task=listing&name=' . $row->alias . '&cid=' . $row->id . $Itemid; } } if ($row->section == 'manufacturer') { $rows[$k]->section = JText::_('MANUFACTURERS'); } else { $rows[$k]->section = JText::_('PRODUCT_CATEGORY'); } } } return $rows; }
function listing() { $app = JFactory::getApplication(); $pageInfo = new stdClass(); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->limit = new stdClass(); $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string'); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.widget_ordering', 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word'); $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); $database = JFactory::getDBO(); $filters = array(); $searchMap = array('a.widget_id', 'a.widget_name'); if (!empty($pageInfo->search)) { $searchVal = '\'%' . hikashop_getEscaped(JString::strtolower(trim($pageInfo->search)), true) . '%\''; $filters[] = implode(" LIKE {$searchVal} OR ", $searchMap) . " LIKE {$searchVal}"; } $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } hikashop_addACLFilters($filters, 'widget_access', 'a'); if (!empty($filters)) { $filters = ' WHERE (' . implode(') AND (', $filters) . ')'; } else { $filters = ''; } $query = ' FROM ' . hikashop_table('widget') . ' AS a ' . $filters . $order; $database->setQuery('SELECT a.*' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value); $rows = $database->loadObjectList(); if (!empty($pageInfo->search)) { $rows = hikashop_search($pageInfo->search, $rows, 'widget_id'); } $database->setQuery('SELECT COUNT(*)' . $query); $pageInfo->elements = new stdClass(); $pageInfo->elements->total = $database->loadResult(); $pageInfo->elements->page = count($rows); $toggleClass = hikashop_get('helper.toggle'); $this->assignRef('toggleClass', $toggleClass); $this->assignRef('rows', $rows); $this->assignRef('pageInfo', $pageInfo); $order = new stdClass(); $order->ordering = true; $order->orderUp = 'orderup'; $order->orderDown = 'orderdown'; $order->reverse = false; if ($pageInfo->filter->order->value == 'a.widget_ordering') { if ($pageInfo->filter->order->dir == 'desc') { $order->orderUp = 'orderdown'; $order->orderDown = 'orderup'; $order->reverse = true; } } $this->assignRef('order', $order); hikashop_setTitle(JText::_($this->nameListing), $this->icon, $this->ctrl); $this->getPagination(); $config =& hikashop_config(); $manage = hikashop_isAllowed($config->get('acl_report_manage', 'all')); $this->assignRef('manage', $manage); $viewAccess = hikashop_isAllowed($config->get('acl_report_view', 'all')); $this->assignRef('viewAccess', $viewAccess); $this->toolbar = array(array('name' => 'addNew', 'display' => $manage), array('name' => 'editList', 'display' => $viewAccess), array('name' => 'deleteList', 'display' => hikashop_isAllowed($config->get('acl_report_delete', 'all'))), '|', array('name' => 'pophelp', 'target' => $this->ctrl . '-listing'), 'dashboard'); }
function getPrices(&$element, &$ids, $currency_id, $main_currency, $zone_id, $discount_before_tax, $user_id = 0) { $currency_ids = array($currency_id => $currency_id, $main_currency => $main_currency); $filters = array('price_currency_id IN (' . implode(',', $this->publishedCurrencies()) . ')'); $product_matches = array('discount_product_id = \'0\'', 'discount_product_id = \'\''); if (!empty($ids)) { $ids_string = ''; foreach ($ids as $id) { if (empty($id)) { continue; } $ids_string .= (int) $id . ','; $product_matches[] = 'discount_product_id LIKE \'%,' . (int) $id . ',%\''; $product_matches[] = 'discount_product_id = \'' . (int) $id . '\''; } $ids_string = rtrim($ids_string, ','); if (empty($ids_string)) { if (empty($element->product_id)) { return false; } $ids_string = $element->product_id; $ids = array($ids_string); } $filters[] = 'price_product_id IN (' . $ids_string . ')'; } else { $ids_string = '0'; } $app = JFactory::getApplication(); if (!$app->isAdmin() || (int) $user_id > 0) { hikashop_addACLFilters($filters, 'price_access', '', 2, false, (int) $user_id); } $query = 'SELECT * FROM ' . hikashop_table('price') . ' WHERE ' . implode(' AND ', $filters) . ' ORDER BY price_site_id ASC, price_value DESC'; $this->database->setQuery($query); $prices = $this->database->loadObjectList(); if (!empty($prices)) { if (is_array($element)) { foreach ($element as $k => $el) { $this->removeAndAddPrices($element[$k], $prices, $currency_ids, $currency_id, $main_currency, $zone_id); } } else { $this->removeAndAddPrices($element, $prices, $currency_ids, $currency_id, $main_currency, $zone_id); } $uneeded = array(); foreach ($prices as $k => $price) { if (empty($price->needed)) { $uneeded[] = $k; } } if (!empty($uneeded)) { foreach ($uneeded as $k) { unset($prices[$k]); } } } $filters = array('discount_type = \'discount\'', 'discount_published = 1', 'discount_quota > discount_used_times OR discount_quota = 0', 'discount_start < ' . time(), 'discount_end > ' . time() . ' OR discount_end = 0', '' . implode(' OR ', $product_matches) . '', 'discount_flat_amount != 0 OR discount_percent_amount != 0'); if (!$app->isAdmin() || (int) $user_id > 0) { hikashop_addACLFilters($filters, 'discount_access', '', 2, false, (int) $user_id); } $query = 'SELECT * FROM ' . hikashop_table('discount') . ' WHERE (' . implode(') AND (', $filters) . ')'; $this->database->setQuery($query); $discounts = $this->database->loadObjectList(); if (!empty($discounts)) { foreach ($discounts as $discount) { if (empty($discount->discount_currency_id)) { continue; } $currency_ids[$discount->discount_currency_id] = $discount->discount_currency_id; } } $null = null; $currencies = $this->getCurrencies($currency_ids, $null); $this->convertPrice($element, $currencies, $currency_id, $main_currency); if (!empty($discounts)) { $this->cartDiscountsLeft = array(); $this->productsDone = array(); $this->convertDiscounts($discounts, $currencies, $currency_id, $main_currency); $this->addDiscountToPrices($element, $discounts, $discount_before_tax, $zone_id); if (!empty($element->options)) { $this->addDiscountToPrices($element->options, $discounts, $discount_before_tax, $zone_id); } } }
function &getData($area, $type, $notcoreonly = false, $categories = null) { static $data = array(); $key = $area . '_' . $type . '_' . $notcoreonly; if (!empty($categories)) { if (!empty($categories['originals'])) { $key .= '_' . implode('/', $categories['originals']); } if (!empty($categories['parents'])) { $key .= '_' . implode('/', $categories['parents']); } } if (!empty($categories['products'])) { $key .= '_' . implode('/', $categories['products']); } if (!isset($data[$key])) { $this->where = array(); $this->where[] = 'a.`field_published` = 1'; if ($area == 'backend') { $this->where[] = 'a.`field_backend` = 1'; } elseif ($area == 'frontcomp') { $this->where[] = 'a.`field_frontcomp` = 1'; } elseif ($area == 'backend_listing') { $this->where[] = 'a.`field_backend_listing` = 1'; } elseif ($area != 'all') { $db = JFactory::getDBO(); $clauses = explode(';', trim($area, ';')); foreach ($clauses as $clause) { if (empty($clause)) { continue; } $v = '=1'; if (strpos($clause, '=') !== false) { list($clause, $v) = explode('=', $clause, 2); $v = '=' . (int) $v; } if (substr($clause, 0, 8) == 'display:') { $cond = substr($clause, 8) . $v; if (HIKASHOP_J25) { $cond = $db->escape($cond, true); } else { $cond = $db->getEscaped($cond, true); } $this->where[] = 'a.`field_display` LIKE \'%;' . $cond . ';%\''; } else { if (HIKASHOP_J25) { $this->where[] = 'a.' . $db->quoteName($clause) . $v; } else { $this->where[] = 'a.' . $db->nameQuote($clause) . $v; } } } } if ($notcoreonly) { $this->where[] = 'a.`field_core` = 0'; } if ($this->skipAddressName) { $this->where[] = 'a.field_namekey!=\'address_name\''; } $this->where[] = 'a.field_table=' . $this->database->Quote($type); $filters = ''; if (!empty($categories)) { $categories_filter = array('((field_with_sub_categories=0 AND (field_categories="all" OR field_categories=""'); if (!empty($categories['originals'])) { foreach ($categories['originals'] as $cat) { $categories_filter[] = 'field_categories LIKE \'%,' . $cat . ',%\''; } } $filters = implode(' OR ', $categories_filter) . '))'; $categories_filter = array('OR (field_with_sub_categories=1 AND (field_categories="all" OR field_categories=""'); if (!empty($categories['parents'])) { foreach ($categories['parents'] as $cat) { $categories_filter[] = 'field_categories LIKE \'%,' . $cat . ',%\''; } } $filters .= implode(' OR ', $categories_filter) . ')))'; } if (!empty($categories['products']) && is_array($categories['products']) && count($categories['products'])) { $products_filter = array(); foreach ($categories['products'] as $p) { $products_filter[] = 'field_products LIKE \'%,' . $p . ',%\''; } if (empty($filters)) { $filters = '(field_products="" OR ' . implode(' OR ', $products_filter) . ')'; } else { $filters = '((' . $filters . ' AND field_products="") OR (' . implode(' OR ', $products_filter) . '))'; } } if (!empty($filters)) { $filters = ' AND ' . $filters; } hikashop_addACLFilters($this->where, 'field_access', 'a'); $this->database->setQuery('SELECT * FROM ' . hikashop_table('field') . ' as a WHERE ' . implode(' AND ', $this->where) . ' ' . $filters . ' ORDER BY a.`field_ordering` ASC'); $data[$key] = $this->database->loadObjectList('field_namekey'); } return $data[$key]; }
function &loadFullCart($additionalInfos = false, $keepEmptyCart = false, $skipChecks = false) { $app = JFactory::getApplication(); $database = JFactory::getDBO(); $config =& hikashop_config(); $currencyClass = hikashop_get('class.currency'); $productClass = hikashop_get('class.product'); $main_currency = (int) $config->get('main_currency', 1); $currency_id = hikashop_getCurrency(); if (!in_array($currency_id, $currencyClass->publishedCurrencies())) { $currency_id = $main_currency; } $zone_id = hikashop_getZone('shipping'); if ($config->get('tax_zone_type', 'shipping') == 'billing') { $tax_zone_id = hikashop_getZone('billing'); } else { $tax_zone_id = $zone_id; } $discount_before_tax = (int) $config->get('discount_before_tax', 0); $cart = new stdClass(); $cart->products = $this->get(@$this->cart->cart_id, $keepEmptyCart, isset($this->cart->cart_type) ? $this->cart->cart_type : ''); $cart->cart_id = (int) @$this->cart->cart_id; $cart->cart_type = @$this->cart->cart_type; $cart->cart_params = @$this->cart->cart_params; $cart->coupon = null; $cart->shipping = null; $cart->total = null; $cart->additional = array(); if (!empty($cart->products)) { $ids = array(); $mainIds = array(); foreach ($cart->products as $product) { $ids[] = $product->product_id; if ($product->product_parent_id == '0') { $mainIds[] = (int) $product->product_id; } else { $mainIds[] = (int) $product->product_parent_id; } } $query = 'SELECT a.*, b.* FROM ' . hikashop_table('product_category') . ' AS a LEFT JOIN ' . hikashop_table('category') . ' AS b ON a.category_id = b.category_id WHERE a.product_id IN(' . implode(',', $mainIds) . ') ORDER BY a.ordering ASC'; $database->setQuery($query); $categories = $database->loadObjectList(); $quantityDisplayType = hikashop_get('type.quantitydisplay'); foreach ($cart->products as $k => $row) { if ($row->product_parent_id != 0 && $row->cart_product_parent_id != '0') { $row->product_quantity_layout = $cart->products[$row->cart_product_parent_id]->product_quantity_layout; $row->product_min_per_order = $cart->products[$row->cart_product_parent_id]->product_min_per_order; $row->product_max_per_order = $cart->products[$row->cart_product_parent_id]->product_max_per_order; } if (empty($row->product_quantity_layout) || $row->product_quantity_layout == 'inherit') { $categoryQuantityLayout = ''; if (!empty($categories)) { foreach ($categories as $category) { if ($category->product_id == $row->product_id && !empty($category->category_quantity_layout) && $quantityDisplayType->check($category->category_quantity_layout, $app->getTemplate())) { $categoryQuantityLayout = $category->category_quantity_layout; break; } } } } if (!empty($row->product_quantity_layout) && $row->product_quantity_layout != 'inherit') { $qLayout = $row->product_quantity_layout; } elseif (!empty($categoryQuantityLayout) && $categoryQuantityLayout != 'inherit') { $qLayout = $categoryQuantityLayout; } else { $qLayout = $config->get('product_quantity_display', 'show_default'); } $cart->products[$k]->product_quantity_layout = $qLayout; } JArrayHelper::toInteger($ids); $query = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type IN( \'product\',\'file\') ORDER BY file_ref_id ASC, file_ordering ASC'; $database->setQuery($query); $images = $database->loadObjectList(); if (!empty($images)) { foreach ($cart->products as $k => $row) { $productClass->addFiles($cart->products[$k], $images); } } foreach ($cart->products as $k => $row) { if ($row->product_type == 'variant') { foreach ($cart->products as $k2 => $row2) { if ($row->product_parent_id == $row2->product_id) { $cart->products[$k2]->variants[] =& $cart->products[$k]; break; } } } } $query = 'SELECT a.*,b.* FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN (' . implode(',', $ids) . ') ORDER BY a.ordering,b.characteristic_value'; $database->setQuery($query); $characteristics = $database->loadObjectList(); if (!empty($characteristics)) { foreach ($cart->products as $key => $product) { if ($product->product_type != 'variant') { $element =& $cart->products[$key]; $product_id = $product->product_id; $mainCharacteristics = array(); foreach ($characteristics as $characteristic) { if ($product_id == $characteristic->variant_product_id) { $mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } if (!empty($element->options)) { foreach ($element->options as $k => $optionElement) { if ($optionElement->product_id == $characteristic->variant_product_id) { $mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id] = $characteristic; } } } } JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterProductCharacteristicsLoad', array(&$element, &$mainCharacteristics, &$characteristics)); if (!empty($element->variants)) { $this->addCharacteristics($element, $mainCharacteristics, $characteristics); } if (!empty($element->options)) { foreach ($element->options as $k => $optionElement) { if (!empty($optionElement->variants)) { $this->addCharacteristics($element->options[$k], $mainCharacteristics, $characteristics); } } } } } } $product_quantities = array(); foreach ($cart->products as $row) { if (empty($product_quantities[$row->product_id])) { $product_quantities[$row->product_id] = (int) @$row->cart_product_quantity; } else { $product_quantities[$row->product_id] += (int) @$row->cart_product_quantity; } if (empty($product_quantities[$row->product_parent_id])) { $product_quantities[$row->product_parent_id] = (int) @$row->cart_product_quantity; } else { $product_quantities[$row->product_parent_id] += (int) @$row->cart_product_quantity; } } foreach ($cart->products as $k => $row) { $cart->products[$k]->cart_product_total_quantity = $product_quantities[$row->product_id]; if ($row->product_parent_id) { $cart->products[$k]->cart_product_total_variants_quantity = $product_quantities[$row->product_parent_id]; } else { $cart->products[$k]->cart_product_total_variants_quantity = $cart->products[$k]->cart_product_total_quantity; } } $currencyClass->getPrices($cart->products, $ids, $currency_id, $main_currency, $tax_zone_id, $discount_before_tax); if ($additionalInfos) { $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC'; $database->setQuery($queryImage); $images = $database->loadObjectList(); foreach ($cart->products as $k => $row) { if (!empty($images)) { foreach ($images as $image) { if ($row->product_id == $image->file_ref_id) { if (!isset($row->file_ref_id)) { foreach (get_object_vars($image) as $key => $name) { $cart->products[$k]->{$key} = $name; } } break; } } } if (!isset($cart->products[$k]->file_name)) { $cart->products[$k]->file_name = $row->product_name; } } } foreach ($cart->products as $k => $row) { if (!empty($row->variants)) { foreach ($row->variants as $k2 => $variant) { $productClass->checkVariant($cart->products[$k]->variants[$k2], $row); } } } $notUsable = array(); $cartData = $this->loadCart($cart->cart_id); if (!$skipChecks) { $cart->products = array_reverse($cart->products); foreach ($cart->products as $k => $product) { if (empty($product->product_id)) { continue; } if (!empty($product->cart_product_quantity)) { $oldQty = $product->cart_product_quantity; if (@$cartData->cart_type != 'wishlist') { $this->_checkQuantity($product, $product->cart_product_quantity, $cart->products, $product->cart_product_id); } if ($oldQty != $product->cart_product_quantity) { $notUsable[$product->cart_product_id] = 0; break; } if (!$config->get('display_add_to_cart_for_free_products', 0) && empty($product->prices)) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice'); continue; } if (empty($product->product_published)) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE', $product->product_name), 'notice'); continue; } if ($product->product_quantity != -1 && $product->product_quantity < $product->cart_product_quantity) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('NOT_ENOUGH_STOCK_FOR_PRODUCT', $product->product_name), 'notice'); continue; } if ($product->product_sale_start > time()) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_YET_ON_SALE', $product->product_name), 'notice'); continue; } if (!empty($product->product_sale_end) && $product->product_sale_end < time()) { $notUsable[$product->cart_product_id] = 0; $app->enqueueMessage(JText::sprintf('PRODUCT_NOT_SOLD_ANYMORE', $product->product_name), 'notice'); continue; } } } $cart->products = array_reverse($cart->products); } if (!empty($notUsable)) { $this->update($notUsable, 1, 0, 'item'); return $this->loadFullCart($additionalInfos); } $cart->number_of_items = 0; $group = $config->get('group_options', 0); foreach ($cart->products as $k => $row) { unset($cart->products[$k]->cart_modified); unset($cart->products[$k]->cart_coupon); $currencyClass->calculateProductPriceForQuantity($cart->products[$k]); if (!$group || !$row->cart_product_option_parent_id) { $cart->number_of_items += $row->cart_product_quantity; } } $currencyClass->calculateTotal($cart->products, $cart->total, $currency_id); $cart->full_total =& $cart->total; JPluginHelper::importPlugin('hikashop'); JPluginHelper::importPlugin('hikashoppayment'); JPluginHelper::importPlugin('hikashopshipping'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterCartProductsLoad', array(&$cart)); if (!empty($cart->additional)) { $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id); $cart->full_total =& $cart->additional_total; } if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $discountClass = hikashop_get('class.discount'); $discountData = $discountClass->load($this->cart->cart_coupon); if (@$discountData->discount_auto_load) { $current_auto_coupon_key = $this->_generateHash($cart->products, $zone_id); $previous_auto_coupon_key = $app->getUserState(HIKASHOP_COMPONENT . '.auto_coupon_key'); if ($current_auto_coupon_key != $previous_auto_coupon_key) { $this->cart->cart_coupon = ''; } } } if (hikashop_level(1) && empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $filters = array('discount_type=\'coupon\'', 'discount_published=1', 'discount_auto_load=1'); hikashop_addACLFilters($filters, 'discount_access'); $query = 'SELECT * FROM ' . hikashop_table('discount') . ' WHERE ' . implode(' AND ', $filters) . ' ORDER BY discount_minimum_order DESC, discount_minimum_products DESC'; $this->database->setQuery($query); $coupons = $this->database->loadObjectList(); if (!empty($coupons)) { $discountClass = hikashop_get('class.discount'); $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getZoneParents($zone_id); foreach ($coupons as $coupon) { $result = $discountClass->check($coupon, $cart->total, $zones, $cart->products, false); if ($result) { $auto_coupon_key = $this->_generateHash($cart->products, $zone_id); $app->setUserState(HIKASHOP_COMPONENT . '.auto_coupon_key', $auto_coupon_key); $app->setUserState(HIKASHOP_COMPONENT . '.coupon_code', ''); $this->update($coupon->discount_code, 1, 0, 'coupon', true); if (empty($this->cart)) { $this->cart = new stdClass(); } $this->cart->cart_coupon = $coupon->discount_code; static $done = false; if ($done == false) { $done = true; return $this->loadFullCart($additionalInfos); } break; } } } } if (!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') { $zoneClass = hikashop_get('class.zone'); $zones = $zoneClass->getZoneParents($zone_id); $cart->coupon = $discountClass->loadAndCheck($this->cart->cart_coupon, $cart->full_total, $zones, $cart->products, true); if (empty($cart->coupon)) { if (!empty($this->cart)) { $this->cart->cart_coupon = ''; } } else { $cart->full_total =& $cart->coupon->total; } } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } $shipping_id = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_id'); if (!empty($shipping_id)) { $cart->shipping = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_data'); if (!empty($cart->shipping)) { if (!is_array($cart->shipping)) { $cart->shipping = array($cart->shipping); } else { $shippings = array(); foreach ($cart->shipping as $method) { $group_key = $method->shipping_id; if (!empty($method->shipping_warehouse_id)) { $group_key .= '_'; if (is_array($method->shipping_warehouse_id)) { foreach ($method->shipping_warehouse_id as $key => $val) { $group_key .= $key . $val; } } else { $group_key .= $method->shipping_warehouse_id; } } $shippings[$group_key] = $method; } $cart->shipping = array_values($shippings); } $currencyClass = hikashop_get('class.currency'); $shipping =& $cart->shipping; $currencyClass->processShippings($shipping, $cart); $cart->full_total =& $currencyClass->addShipping($cart->shipping, $cart->full_total); } } $before_additional = !empty($cart->additional); $dispatcher->trigger('onAfterCartShippingLoad', array(&$cart)); if (!$before_additional && !empty($cart->additional)) { $currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id); $cart->full_total =& $cart->additional_total; } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } $payment_id = $app->getUserState(HIKASHOP_COMPONENT . '.payment_id'); if (!empty($payment_id)) { $cart->payment = $app->getUserState(HIKASHOP_COMPONENT . '.payment_data'); if (!empty($cart->payment)) { $currencyClass = hikashop_get('class.currency'); $payment =& $cart->payment; $payments = array(&$payment); $currencyClass->processPayments($payments, $cart); $currencyClass->addPayment($cart->payment, $cart->full_total); $cart->full_total =& $cart->payment->total; } } if (hikashop_toFloat($cart->full_total->prices[0]->price_value_with_tax) <= 0) { $cart->full_total->prices[0]->price_value_with_tax = 0; $cart->full_total->prices[0]->price_value = 0; if (isset($cart->full_total->prices[0]->taxes)) { unset($cart->full_total->prices[0]->taxes); } } } if ($additionalInfos) { $app = JFactory::getApplication(); $shipping_address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address', 0); if (!empty($shipping_address)) { $this->loadAddress($cart, $shipping_address); } $billing_address = $app->getUserState(HIKASHOP_COMPONENT . '.billing_address', 0); if ($billing_address == $shipping_address) { $cart->billing_address =& $cart->shipping_address; } else { if (!empty($billing_address)) { $this->loadAddress($cart, $billing_address, 'parent', 'billing'); } } $this->calculateWeightAndVolume($cart); } if (!empty($cart->products) && isset($dispatcher)) { $dispatcher->trigger('onAfterFullCartLoad', array(&$cart)); } return $cart; }
function onSearch($text, $phrase = '', $ordering = '', $areas = null) { if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return array(); } $db = JFactory::getDBO(); if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onSearchAreas()))) { return array(); } } $limit = $this->params->def('search_limit', 50); $text = trim($text); if ($text == '') { return array(); } switch ($ordering) { case 'alpha': $order = 'a.product_name ASC'; break; case 'newest': $order = 'a.product_modified DESC'; break; case 'oldest': $order = 'a.product_created ASC'; break; case 'popular': $order = 'a.product_hit DESC'; break; case 'category': default: $order = 'a.product_name DESC'; break; } $trans = hikashop_get('helper.translation'); $multi = $trans->isMulti(); $trans_table = 'jf_content'; if ($trans->falang) { $trans_table = 'falang_content'; } $rows = array(); $filters = array('a.product_published=1'); $variants = (int) $this->params->get('variants', '0'); if (!$variants) { $filters[] = 'a.product_type=\'main\''; } $out_of_stock = (int) $this->params->get('out_of_stock_display', '1'); if (!$out_of_stock) { $filters[] = 'a.product_quantity!=0'; } hikashop_addACLFilters($filters, 'product_access', 'a'); $leftjoin = ''; $catFilters = array('category_published=1', 'category_type=\'product\''); hikashop_addACLFilters($catFilters, 'category_access'); $db->setQuery('SELECT category_id FROM ' . hikashop_table('category') . ' WHERE ' . implode(' AND ', $catFilters)); if (!HIKASHOP_J25) { $cats = $db->loadResultArray(); } else { $cats = $db->loadColumn(); } if (!empty($cats)) { $filters[] = 'b.category_id IN (' . implode(',', $cats) . ')'; } if ($variants) { $leftjoin = ' INNER JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_parent_id=b.product_id OR a.product_id=b.product_id'; } else { $leftjoin = ' INNER JOIN ' . hikashop_table('product_category') . ' AS b ON a.product_id=b.product_id'; } $filters2 = array(); if ($multi) { $registry = JFactory::getConfig(); if (!HIKASHOP_J25) { $code = $registry->getValue('config.jflang'); } else { $code = $registry->get('language'); } $lg = $trans->getId($code); $filters2[] = "b.reference_table='hikashop_product'"; $filters2[] = "b.published=1"; $filters2[] = 'b.language_id=' . $lg; } $fields = $this->params->get('fields', ''); if (empty($fields)) { $fields = array('product_name', 'product_description'); } else { $fields = explode(',', $fields); } switch ($phrase) { case 'exact': $text = $db->Quote('%' . hikashop_getEscaped($text, true) . '%', false); $filters1 = array(); foreach ($fields as $f) { $filters1[] = "a." . $f . " LIKE " . $text; } if ($multi) { $filters2[] = "b.value LIKE " . $text; } break; case 'all': case 'any': default: $words = explode(' ', $text); $wordFilters = array(); $subWordFiltersX = array(); $wordFilters2 = array(); foreach ($words as $word) { $word = $db->Quote('%' . hikashop_getEscaped($word, true) . '%', false); foreach ($fields as $i => $f) { $subWordFiltersX[$i][] = "a." . $f . " LIKE " . $word; } if ($multi) { $wordFilters2[] = "b.value LIKE " . $word; } } foreach ($subWordFiltersX as $i => $subWordFilters) { $wordFilters[$i] = '((' . implode($phrase == 'all' ? ') AND (' : ') OR (', $subWordFilters) . '))'; } $filters[] = '((' . implode(') OR (', $wordFilters) . '))'; if ($multi) { $filters2[] = '((' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wordFilters2) . '))'; } break; } $new_page = (int) $this->params->get('new_page', '1'); $select = ' a.product_id AS id, a.product_name, a.product_alias, a.product_canonical, a.product_created AS created , a.product_description, "' . $new_page . '" AS browsernav'; if ($variants) { $select .= ', a.product_type, a.product_parent_id'; } $count = 0; if ($multi && !empty($lg)) { $db->setQuery('SET SQL_BIG_SELECTS=1'); $db->query(); $query = ' SELECT DISTINCT ' . $select . ' FROM ' . hikashop_table($trans_table, false) . ' AS b LEFT JOIN ' . hikashop_table('product') . ' AS a ON b.reference_id=a.product_id WHERE ' . implode(' AND ', $filters2) . ' ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList("id"); $count = count($rows); if ($count) { $limit = $limit - $count; $filters[] = 'a.product_id NOT IN (' . implode(',', array_keys($rows)) . ')'; } } if ($limit) { if (!empty($leftjoin)) { $select .= ', b.category_id as category_id'; } $db->setQuery('SET SQL_BIG_SELECTS=1'); $db->query(); $filters = implode(' AND ', $filters); if (isset($filters1)) { $filters = '(' . $filters . ') AND (' . implode(' OR ', $filters1) . ')'; } $query = ' SELECT DISTINCT ' . $select . ' FROM ' . hikashop_table('product') . ' AS a ' . $leftjoin . ' WHERE ' . $filters . ' GROUP BY (a.product_id) ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $mainRows = $db->loadObjectList("id"); if (!empty($mainRows)) { foreach ($mainRows as $k => $main) { $rows[$k] = $main; } $count = count($rows); } } if ($count) { if ($multi && !empty($lg)) { $query = ' SELECT * FROM ' . hikashop_table($trans_table, false) . ' WHERE reference_table=\'hikashop_product\' AND language_id=\'' . $lg . '\' AND published=1 AND reference_id IN (' . implode(',', array_keys($rows)) . ')'; $db->setQuery($query); $trans = $db->loadObjectList(); foreach ($trans as $item) { foreach ($rows as $key => $row) { if ($row->id == $item->reference_id) { if ($item->reference_field == 'product_name') { $row->product_name = $item->value; } elseif ($item->reference_field == 'product_description') { $row->product_description = $item->value; } else { $row->product_name = $item->value; } break; } } } } $parent = ''; $item_id = $this->params->get('item_id', ''); $menuClass = hikashop_get('class.menus'); $config =& hikashop_config(); $pathway_sef_name = $config->get('pathway_sef_name', 'category_pathway'); $menus = array(); $Itemid = ''; if (!empty($item_id)) { $Itemid = '&Itemid=' . $item_id; if ($this->params->get('full_path', 1)) { $menuData = $menus[$item_id] = $menuClass->get($item_id); if (!empty($menuData->hikashop_params['selectparentlisting'])) { $parent = '&' . $pathway_sef_name . '=' . (int) $menuData->hikashop_params['selectparentlisting']; } } } $itemids = array(); $app = JFactory::getApplication(); $class = hikashop_get('class.product'); $ids = array(); foreach ($rows as $k => $row) { $ids[$row->id] = $row->id; if (!empty($row->category_id)) { if (empty($item_id)) { if (!isset($itemids[$row->category_id])) { $itemids[$row->category_id] = $menuClass->getItemidFromCategory($row->category_id); } $item_id = $itemids[$row->category_id]; } if (!empty($item_id)) { $Itemid = '&Itemid=' . $item_id; } if ($this->params->get('full_path', 1)) { $parent = '&' . $pathway_sef_name . '=' . (int) $row->category_id; } if (!$this->params->get('item_id', '')) { $item_id = ''; } } $class->addAlias($row); $row->title = $row->product_name; $row->text = $row->product_description; if ($variants && $row->product_type == 'variant') { $ids[$row->product_parent_id] = $row->product_parent_id; static $mains = array(); if (!isset($mains[$row->product_parent_id])) { $mains[$row->product_parent_id] = $class->get((int) $row->product_parent_id); $class->addAlias($mains[$row->product_parent_id]); } $db = JFactory::getDBO(); $db->setQuery('SELECT * FROM ' . hikashop_table('variant') . ' AS a LEFT JOIN ' . hikashop_table('characteristic') . ' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id=' . (int) $row->id . ' ORDER BY a.ordering'); $row->characteristics = $db->loadObjectList(); $class->checkVariant($row, $mains[$row->product_parent_id]); if (empty($row->title)) { $row->title = $row->product_name; } if (empty($row->text)) { $row->text = $mains[$row->product_parent_id]->product_description; } } if (empty($row->product_canonical)) { $rows[$k]->href = JRoute::_('index.php?option=com_hikashop&ctrl=product&task=show&name=' . $row->alias . '&cid=' . $row->id . $Itemid . $parent); } else { $rows[$k]->href = $row->product_canonical; } $rows[$k]->href = hikashop_cleanURL($rows[$k]->href); $rows[$k]->section = JText::_('PRODUCT'); } if (!empty($ids)) { $imageHelper = hikashop_get('helper.image'); $height = (int) $config->get('thumbnail_y', '100'); $width = (int) $config->get('thumbnail_x', '100'); $image_options = array('default' => true, 'forcesize' => $config->get('image_force_size', true), 'scale' => $config->get('image_scale_mode', 'inside')); $db = JFactory::getDBO(); $queryImage = 'SELECT * FROM ' . hikashop_table('file') . ' WHERE file_ref_id IN (' . implode(',', $ids) . ') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering DESC, file_id ASC'; $db->setQuery($queryImage); $images = $db->loadObjectList('file_ref_id'); foreach ($rows as $k => $row) { foreach ($images as $k2 => $image) { if ($k == $k2) { $result = $imageHelper->getThumbnail(@$image->file_path, array('width' => $width, 'height' => $height), $image_options); if ($result->success) { $rows[$k]->image = $result->url; } break; } } if (!empty($rows[$k]->image)) { continue; } if (!$variants) { continue; } foreach ($images as $k2 => $image) { if ($row->product_parent_id == $k2) { $result = $imageHelper->getThumbnail(@$image->file_path, array('width' => $width, 'height' => $height), $image_options); if ($result->success) { $rows[$k]->image = $result->url; } break; } } } } } return $rows; }
function getChildren($element, $all = false, $additionalFilters = array(), $order = '', $start = 0, $value = 20, $category_image = false, $select = 'a.*', $lang = true) { $filters = array(); $this->category_used = null; if (empty($element)) { $element = $this->getRoot(); } if (is_array($element)) { if (count($element) > 1) { foreach ($element as $k => $v) { $element[$k] = (int) $v; } if ($all) { $this->database->setQuery('SELECT category_left,category_right FROM ' . hikashop_table('category') . ' WHERE category_id IN (' . implode(',', $element) . ')'); $leafs = $this->database->loadObjectList(); $conditions = array(); foreach ($leafs as $v) { $conditions[] = '(a.category_left > ' . $v->category_left . ' AND a.category_right < ' . $v->category_right . ')'; } $filters[] = '(' . implode(' OR ', $conditions) . ')'; $this->type = 0; } else { $filters[] = 'a.category_parent_id IN (' . implode(',', $element) . ')'; $this->type = 0; } } else { $element = (int) array_pop($element); } } elseif (!is_numeric($element)) { $this->getMainElement($element); } if (is_numeric($element)) { if ($all) { $data = $this->get($element); if (!empty($data)) { if ($data->category_left + 1 == $data->category_right) { return array(); } $filters[] = 'a.category_left > ' . $data->category_left; $filters[] = 'a.category_right < ' . $data->category_right; if (!empty($data->category_type) && $data->category_type != 'root') { $this->type = $data->category_type; } } } else { $filters[] = 'a.category_parent_id = ' . $element; $this->type = 0; } } elseif (!is_array($element)) { $this->type = $element; } if (is_numeric($element)) { $this->category_used = $element; } elseif (is_array($element)) { $this->category_used = (int) array_pop($element); } if (!empty($this->type)) { if ($this->type == 'product') { $filters[] = '(a.category_type = ' . $this->database->Quote($this->type) . ' OR a.category_type = ' . $this->database->Quote('vendor') . ')'; } else { $filters[] = 'a.category_type = ' . $this->database->Quote($this->type); } } if (!empty($additionalFilters)) { $filters = array_merge($filters, $additionalFilters); } $leftjoin = ''; $app = JFactory::getApplication(); if (!$app->isAdmin()) { $filters[] = 'a.category_published=1'; hikashop_addACLFilters($filters, 'category_access', 'a'); } JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onBeforeCategoryListingLoad', array(&$filters, &$order, &$this->parentObject, &$leftjoin)); if (!empty($filters)) { $filters = ' WHERE ' . implode(' AND ', $filters); } else { $filters = ''; } if (!$app->isAdmin() && preg_match('#(.*)a\\.category_name ?(ASC|DESC)(.*)#i', $order, $match) && (strpos($select, '*') !== false || strpos($select, 'category_name') !== false)) { $translationHelper = hikashop_get('helper.translation'); if ($translationHelper->isMulti()) { $trans_table = 'jf_content'; if ($translationHelper->falang) { $trans_table = 'falang_content'; } $language = JFactory::getLanguage(); $language_id = (int) $translationHelper->getId($language->getTag()); $filters = ' LEFT JOIN #__' . $trans_table . ' AS trans_table ON trans_table.reference_table=\'hikashop_category\' AND trans_table.language_id=' . $language_id . ' AND trans_table.reference_field=\'category_name\' AND a.category_id=trans_table.reference_id' . $filters; $order = $match[1] . 'trans_table.value ' . $match[2] . ', a.category_name ' . $match[2] . $match[3]; } } static $multiTranslation = null; $app = JFactory::getApplication(); if (!$lang && $multiTranslation === null && !$app->isAdmin()) { $translationHelper = hikashop_get('helper.translation'); $multiTranslation = $translationHelper->isMulti(true); } $this->query = ' FROM ' . hikashop_table(end($this->tables)) . ' AS a' . $leftjoin . $filters; $query = 'SELECT ' . $select . ' FROM ' . hikashop_table(end($this->tables)) . ' AS a' . $leftjoin . $filters . $order; $this->database->setQuery($query, (int) $start, (int) $value); if ($lang || !$multiTranslation || $app->isAdmin()) { $rows = $this->database->loadObjectList(); } else { if (class_exists('JFalangDatabase')) { $rows = $this->database->loadObjectList('', 'stdClass', false); } elseif (class_exists('JFDatabase') || class_exists('JDatabaseMySQLx')) { if (HIKASHOP_J25) { $rows = $this->database->loadObjectList('', 'stdClass', false); } else { $rows = $this->database->loadObjectList('', false); } } else { $rows = $this->database->loadObjectList(); } } if ($category_image && !empty($rows)) { $ids = array(); foreach ($rows as $row) { $ids[] = $row->category_id; } $this->database->setQuery('SELECT * FROM ' . hikashop_table('file') . ' WHERE file_type=\'category\' AND file_ref_id IN (' . implode(',', $ids) . ')'); $images = $this->database->loadObjectList(); foreach ($rows as $k => $cat) { if (!empty($images)) { foreach ($images as $img) { if ($img->file_ref_id == $cat->category_id) { foreach (get_object_vars($img) as $key => $val) { $rows[$k]->{$key} = $val; } break; } } } if (!isset($rows[$k]->file_name)) { $rows[$k]->file_name = $row->category_name; } } } return $rows; }
function loadBadges(&$row) { $discount = new stdClass(); $qty = 0; if (isset($row->main)) { if (@$row->main->discount) { $discount =& $row->main->discount; } elseif (@$row->discount) { $discount =& $row->discount; } $product_id = $row->main->product_id; $qty = $row->main->product_quantity; } else { if (@$row->discount) { $discount =& $row->discount; } $product_id = $row->product_id; $qty = $row->product_quantity; } $badge_filters = array('a.badge_start <= ' . time(), '( a.badge_end >= ' . time() . ' OR a.badge_end =0 )', 'a.badge_published=1', '(a.badge_quantity=\'\' OR a.badge_quantity=' . (int) $qty . ')'); if ($discount && isset($discount->discount_id)) { $badge_filters[] = '(badge_discount_id=' . (int) @$discount->discount_id . ' OR badge_discount_id LIKE \'%,' . (int) @$discount->discount_id . ',%\' OR badge_discount_id=\'0\' OR badge_discount_id=\'\' )'; } else { $badge_filters[] = '(badge_discount_id=\'0\' OR badge_discount_id=\'\')'; } $categories = array('originals' => array(), 'parents' => array()); $categoryClass = hikashop_get('class.category'); $productClass = hikashop_get('class.product'); if (isset($row->categories)) { $oneCat = reset($row->categories); if (is_object($oneCat)) { $loadedCategories = array_keys($row->categories); } else { $loadedCategories = $row->categories; } } else { $loadedCategories = $productClass->getCategories($product_id); } if (!empty($row->main->product_manufacturer_id)) { $categories['originals'][$row->main->product_manufacturer_id] = $row->main->product_manufacturer_id; } if (!empty($row->product_manufacturer_id)) { $categories['originals'][$row->product_manufacturer_id] = $row->product_manufacturer_id; } if (!empty($loadedCategories)) { foreach ($loadedCategories as $cat) { $categories['originals'][$cat] = $cat; } } $parents = $categoryClass->getParents($loadedCategories); if (!empty($parents) && is_array($parents)) { foreach ($parents as $parent) { $categories['parents'][$parent->category_id] = $parent->category_id; } } hikashop_addACLFilters($badge_filters, 'badge_access', 'a'); $badge_filters = implode(' AND ', $badge_filters); if (!empty($categories)) { $categories_filter = array(' AND ((badge_category_childs = 0 AND (badge_category_id = \'0\' OR badge_category_id = \'\''); if (!empty($categories['originals'])) { foreach ($categories['originals'] as $cat) { $categories_filter[] = 'badge_category_id = \'' . (int) $cat . '\''; $categories_filter[] = 'badge_category_id LIKE \'%,' . (int) $cat . ',%\''; } } $badge_filters .= implode(' OR ', $categories_filter) . '))'; $categories_filter = array(' OR (badge_category_childs = 1 AND (badge_category_id=\'0\' OR badge_category_id=\'\''); if (!empty($categories['parents'])) { foreach ($categories['parents'] as $cat) { $categories_filter[] = 'badge_category_id = \'' . (int) $cat . '\''; $categories_filter[] = 'badge_category_id LIKE \'%,' . (int) $cat . ',%\''; } } $badge_filters .= implode(' OR ', $categories_filter) . ')))'; } static $badges = array(); $key = sha1($badge_filters); if (!isset($badges[$key])) { $query = ' FROM ' . hikashop_table('badge') . ' AS a WHERE ' . $badge_filters . ' ORDER BY a.badge_ordering ASC,a.badge_id ASC'; $this->database->setQuery('SELECT a.*' . $query); $badges[$key] = $this->database->loadObjectList(); } $badgesForProduct = array(); if (is_array($badges[$key]) && count($badges[$key])) { foreach ($badges[$key] as $badge) { if (!empty($badge->badge_product_id)) { if (!is_array($badge->badge_product_id)) { $badge->badge_product_id = explode(',', $badge->badge_product_id); } if (!in_array($product_id, $badge->badge_product_id)) { continue; } } $badgesForProduct[] = $badge; } } if (count($badgesForProduct)) { $row->badges = $badgesForProduct; } else { $row->badges = null; } }
function loadPaymentMethod($name, $type, &$cart) { static $datas = array(); if (empty($name)) { $name = $this->name; } if (!isset($datas[$name])) { $db = JFactory::getDBO(); $where = array('payment_type = ' . $db->Quote($name), 'payment_published=\'1\''); $shipping = ''; if (!empty($cart->shipping)) { $shipping = $cart->shipping[0]->shipping_type . '_' . $cart->shipping[0]->shipping_id; } if (!empty($shipping)) { $where[] = '(payment_shipping_methods IN (\'\',\'_\') OR payment_shipping_methods LIKE \'%\\n' . $shipping . '\\n%\' OR payment_shipping_methods LIKE \'' . $shipping . '\\n%\' OR payment_shipping_methods LIKE \'%\\n' . $shipping . '\' OR payment_shipping_methods LIKE \'' . $shipping . '\')'; } $currency = hikashop_getCurrency(); if (!empty($currency)) { $where[] = "(payment_currency IN ('','_','all') OR payment_currency LIKE '%," . intval($currency) . ",%')"; } $app = JFactory::getApplication(); if (!$app->isAdmin()) { hikashop_addACLFilters($where, 'payment_access'); } if (!empty($where)) { $where = ' WHERE ' . implode(' AND ', $where); } else { $where = ''; } $sql = 'SELECT * FROM `#__hikashop_payment`' . $where . ' ORDER BY payment_ordering'; $db->setQuery($sql); $db->query(); $datas[$name] = $db->loadObjectList(); } if (!empty($datas[$name])) { if ($type == 'id') { return $datas[$name][0]->payment_id; } elseif ($type == 'first') { return $datas[$name][0]; } else { return $datas[$name]; } } return false; }
function getMethods($type = 'shipping', $name = '', $shipping = '', $currency = '') { $where = array(); $lf = ''; $select = '*'; if (!empty($name)) { $where[] = $type . '_type=' . $this->database->Quote($name); } if (!empty($shipping)) { $where[] = '(payment_shipping_methods IN (\'\',\'_\') OR payment_shipping_methods LIKE \'%\\n' . $shipping . '\\n%\' OR payment_shipping_methods LIKE \'' . $shipping . '\\n%\' OR payment_shipping_methods LIKE \'%\\n' . $shipping . '\' OR payment_shipping_methods LIKE \'' . $shipping . '\')'; } if (!empty($currency)) { $where[] = "(" . $type . "_currency IN ('','_','all') OR " . $type . "_currency LIKE '%," . intval($currency) . ",%')"; } $app = JFactory::getApplication(); if (!$app->isAdmin()) { $access = $type . '_access'; hikashop_addACLFilters($where, $access); } if (!empty($where)) { $where = ' WHERE ' . implode(' AND ', $where); } else { $where = ''; } if ($type == 'shipping') { $where .= ' ORDER BY shipping_ordering ASC'; } if ($type == 'payment') { $where .= ' ORDER BY payment_ordering ASC'; } $query = 'SELECT ' . $select . ' FROM ' . hikashop_table($type) . ' ' . $lf . $where; $this->database->setQuery($query); $methods = $this->database->loadObjectList($type . '_id'); $this->params($methods, $type); if (empty($methods)) { $methods = array(); } elseif ($type == 'payment') { $types = array(); foreach ($methods as $method) { $types[$method->payment_type] = $this->database->Quote($method->payment_type); } $types = implode(',', $types); if (!HIKASHOP_J16) { $query = 'SELECT *, published as enabled FROM ' . hikashop_table('plugins', false) . ' WHERE element IN (' . $types . ') AND folder=\'hikashoppayment\' ORDER BY ordering ASC'; } else { $query = 'SELECT * FROM ' . hikashop_table('extensions', false) . ' WHERE element IN (' . $types . ') AND folder=\'hikashoppayment\' AND type=\'plugin\' ORDER BY ordering ASC'; } $this->database->setQuery($query); $plugins = $this->database->loadObjectList(); foreach ($methods as $k => $method) { foreach ($plugins as $plugin) { if ($plugin->element == $method->payment_type) { foreach (get_object_vars($plugin) as $key => $val) { $methods[$k]->{$key} = $val; } break; } } } } return $methods; }
function downloadFieldFile($name, $field_table, $field_namekey, $options = array()) { $app = JFactory::getApplication(); if (!$app->isAdmin()) { $found = false; switch ($field_table) { case 'entry': $entriesData = $app->getUserState(HIKASHOP_COMPONENT . '.entries_fields'); if (!empty($entriesData)) { foreach ($entriesData as $entryData) { if (@$entryData->{$field_namekey} == $name) { $found = true; } } } break; case 'order': $orderData = $app->getUserState(HIKASHOP_COMPONENT . '.checkout_fields'); if (@$orderData->{$field_namekey} == $name) { $found = true; } break; case 'item': $class = hikashop_get('class.cart'); $products = $class->get(); if (!empty($products)) { foreach ($products as $product) { if (@$product->{$field_namekey} == $name) { $found = true; } } } $itemsData = $app->getUserState(HIKASHOP_COMPONENT . '.items_fields'); if (!empty($itemsData)) { foreach ($itemsData as $itemData) { if (@$itemData->{$field_namekey} == $name) { $found = true; } } } break; default: if (substr($field_table, 0, 4) == 'plg.') { $externalValues = array(); JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onTableFieldsLoad', array(&$externalValues)); $found = false; foreach ($externalValues as $external) { if ($external->value == $field_table) { $found = true; break; } } if ($found) { $elemsData = $app->getUserState(HIKASHOP_COMPONENT . '.plg_fields.' . substr($field_table, 4)); if (!empty($elemsData)) { foreach ($elemsData as $elemData) { if (@$elemData->{$field_namekey} == $name) { $found = true; } } } } } break; } if (!$found) { JPluginHelper::importPlugin('hikashop'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onFieldFileDownload', array(&$found, $name, $field_table, $field_namekey, $options)); } if (!$found) { if (!HIKASHOP_J25) { $escaped_field_namekey = $this->database->nameQuote($field_namekey); } else { $escaped_field_namekey = $this->database->quoteName($field_namekey); } switch ($field_table) { case 'order': $this->database->setQuery('SELECT order_id FROM ' . hikashop_table('order') . ' WHERE order_user_id=' . (int) hikashop_loadUser() . ' AND ' . $escaped_field_namekey . ' = ' . $this->database->Quote($name)); break; case 'item': $this->database->setQuery('SELECT b.order_product_id FROM ' . hikashop_table('order') . ' AS a LEFT JOIN ' . hikashop_table('order_product') . ' AS b ON a.order_id=b.order_id WHERE a.order_user_id=' . (int) hikashop_loadUser() . ' AND b.' . $escaped_field_namekey . ' = ' . $this->database->Quote($name)); break; case 'entry': $this->database->setQuery('SELECT b.entry_id FROM ' . hikashop_table('order') . ' AS a LEFT JOIN ' . hikashop_table('entry') . ' AS b ON a.order_id=b.order_id WHERE a.order_user_id=' . (int) hikashop_loadUser() . ' AND b.' . $escaped_field_namekey . ' = ' . $this->database->Quote($name)); break; case 'user': $this->database->setQuery('SELECT user_id FROM ' . hikashop_table('user') . ' WHERE user_id=' . (int) hikashop_loadUser() . ' AND ' . $escaped_field_namekey . ' = ' . $this->database->Quote($name)); break; case 'address': $this->database->setQuery('SELECT address_id FROM ' . hikashop_table('address') . ' WHERE address_user_id=' . (int) hikashop_loadUser() . ' AND ' . $escaped_field_namekey . ' = ' . $this->database->Quote($name)); break; case 'product': $filters = array($escaped_field_namekey . ' = ' . $this->database->Quote($name), 'product_published=1'); hikashop_addACLFilters($filters, 'product_access'); $this->database->setQuery('SELECT product_id FROM ' . hikashop_table('product') . ' WHERE ' . implode(' AND ', $filters)); break; case 'category': $filters = array($escaped_field_namekey . ' = ' . $this->database->Quote($name), 'category_published=1'); hikashop_addACLFilters($filters, 'category_access'); $this->database->setQuery('SELECT category_id FROM ' . hikashop_table('category') . ' WHERE ' . implode(' AND ', $filters)); break; default: return false; } $result = $this->database->loadResult(); if ($result) { $found = true; } } if (!$found) { $query = 'SELECT field_default FROM ' . hikashop_table('field') . ' WHERE field_table = ' . $this->database->Quote($field_table) . ' AND field_namekey = ' . $this->database->Quote($field_namekey) . ' AND field_published = 1 AND field_type IN (\'image\',\'ajaximage\')'; $this->database->setQuery($query); $default_value = $this->database->loadResult(); if ($default_value == $name) { $found = true; } } if (!$found) { return false; } } $path = $this->getPath('file'); if (file_exists($path . $name)) { $file = new stdClass(); $file->file_path = $name; $this->sendFile($file, true, $path, $options); } return false; }