public static function setOtherParams($products) { foreach ($products as &$product) { $product = KSMProducts::getProduct($product->id); } return $products; }
public function getComment() { $this->onExecuteBefore('getComment'); $id = JRequest::getInt('id', 0); $comment = KSSystem::getTableByIds(array($id), 'comments', array('t.id', 't.parent_id', 't.user_id AS user', 't.product_id AS product', 't.name', 't.comment', 't.good', 't.bad', 't.rate', 't.date_add', 't.type'), true, false, true); if (!empty($comment)) { $comment->user = KSUsers::getUser($comment->user); if (isset($comment->product) && $comment->product > 0) { $comment->product = KSMProducts::getProduct($comment->product); } $this->onExecuteAfter('getComment', array(&$comment)); return $comment; } return new stdClass(); }
public function getProductsObject($p_ids) { $this->onExecuteBefore('getProductsObject', array(&$p_ids)); foreach ($p_ids as &$item) { $item = KSMProducts::getProduct($item->id); } $this->onExecuteAfter('getProductsObject', array(&$p_ids)); return $p_ids; }
function getSet($categories = array()) { $this->onExecuteBefore('getSet', array(&$categories)); $id = JRequest::getInt('id'); $ids = JRequest::getVar('ids', array()); $set = KSSystem::loadDbItem($id, 'products'); $set = KSMedia::setItemMedia($set, 'product'); if (count($categories)) { $query = $this->_db->getQuery(true); $query->select('category_id')->from('#__ksenmart_products_categories')->where('product_id=' . $id)->where('is_default=1'); $this->_db->setQuery($query); $is_default = $this->_db->loadResult(); foreach ($categories as $category_id) { $category = new stdClass(); $category->category_id = $category_id; $category->is_default = $category->category_id == $is_default ? 1 : 0; $set->categories[$category_id] = $category; } } else { $query = $this->_db->getQuery(true); $query->select('category_id, is_default')->from('#__ksenmart_products_categories')->where('product_id=' . $id); $this->_db->setQuery($query); $set->categories = $this->_db->loadObjectList('category_id'); } if (count($ids)) { $query = $this->_db->getQuery(true); $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id in (' . implode(',', $ids) . ')'); $query = KSMedia::setItemMainImageToQuery($query); $this->_db->setQuery($query); $set->relative = $this->_db->loadObjectList('id'); } else { $query = $this->_db->getQuery(true); $query->select('p.*')->from('#__ksenmart_products as p')->innerjoin('#__ksenmart_products_relations as pr on pr.relative_id=p.id')->where('pr.relation_type=' . $this->_db->quote('set'))->where('pr.product_id=' . $id); $query = KSMedia::setItemMainImageToQuery($query); $this->_db->setQuery($query); $set->relative = $this->_db->loadObjectList('id'); } $set->old_price = 0; foreach ($set->relative as &$prd) { $prd->small_img = KSMedia::resizeImage($prd->filename, $prd->folder, 36, 36, json_decode($prd->params, true)); KSMProducts::productPricesTransform($prd); $set->old_price += $prd->price; } $this->onExecuteAfter('getSet', array(&$set)); return $set; }
function validate_in_stock() { $params = JComponentHelper::getParams('com_ksenmart'); $db = JFactory::getDBO(); $id = JRequest::getVar('id', 0); $count = JRequest::getVar('count', 0); $product = KSMProducts::getProduct($id); if ($count > $product->in_stock && $params->get('use_stock', 1) == 1) { echo 'Недостаточно количества на складе'; } exit; }
private function getOrderUpdateItems($oid, $itemId) { $this->onExecuteBefore('getOrderUpdateItems'); if (!empty($oid)) { $query = $this->_db->getQuery(true); $query->select($this->_db->qn(array('o.id', 'o.order_id', 'o.product_id', 'o.price', 'o.count', 'o.properties')))->from($this->_db->qn('#__ksenmart_order_items', 'o'))->where($this->_db->qn('o.order_id') . '=' . $this->_db->q($oid))->where($this->_db->qn('o.id') . '=' . $this->_db->q($itemId)); $this->_db->setQuery($query); $order = $this->_db->loadObject(); if ($order) { $order->product = KSMProducts::getProduct($order->product_id); } $this->onExecuteAfter('getOrderUpdateItems', array(&$order)); return $order; } return new stdClass(); }
/** * KsenMartModelProfile::getComments() * * @return */ public function getComments() { $this->onExecuteBefore('getComments'); $query = $this->_db->getQuery(true); $this->_limit = 10; $limitstart = JRequest::getVar('limitstart', 0); $user = JFactory::getUser(); $query->select(' c.id, c.user_id AS user, c.product_id AS product, c.name, c.comment, c.good, c.bad, c.rate, c.date_add, p.id AS p_id, p.title, p.alias, i.filename, i.folder '); $query->from('#__ksenmart_comments AS c'); $query->leftjoin('#__ksenmart_products AS p ON c.product_id = p.id'); $query->leftjoin('#__ksenmart_files AS i ON p.id=i.owner_id'); $query->where('c.published = 1'); $query->where('c.user_id = ' . $user->id); $query->where("c.type = 'review'"); $query->group('c.id'); $this->_db->setQuery($query, $limitstart, $this->_limit); $comments = $this->_db->loadObjectList(); $this->_pagination = new JPagination(count($comments), $limitstart, $this->_limit); foreach ($comments as $comment) { $comment->user = KSUsers::getUser($comment->user); $comment->link = KSMProducts::generateProductLink($comment->p_id, $comment->alias); $comment->product = KSMProducts::getProduct($comment->p_id); $comment->small_img = $comment->product->small_img; } $this->onExecuteAfter('getComments', array(&$comments)); return $comments; }
public function createOrder($flag = 2) { $this->onExecuteBefore('createOrder', array($flag)); $params = JComponentHelper::getParams('com_ksenmart'); $session = JFactory::getSession(); $jinput = JFactory::getApplication()->input; $user = JFactory::getUser(); $user_id = $user->id; $order_id = $session->get('shop_order_id', null); $name = $jinput->get('name', null, 'string'); $email = $jinput->get('email', null, 'string'); $sendEmail = $jinput->get('sendEmail', null, 'string'); $address = $jinput->get('address', null, 'string'); $deliverycost = $jinput->get('deliverycost', 0, 'int'); $phone = $jinput->get('phone', null, 'string'); $region_id = $jinput->get('region', 0, 'int'); $shipping_id = $jinput->get('shipping_type', 0, 'int'); $payment_id = $jinput->get('payment_type', 0, 'int'); $ymaphtml = $jinput->get('ymaphtml', null, 'string'); $note = $jinput->get('note', null, 'string'); $prd_id = $jinput->get('id', 0, 'int'); $count = $jinput->get('count', 1, 'int'); $roistat = $jinput->get('roistat_visit', 0, 'int'); if (!empty($prd_id)) { $prd = KSMProducts::getProduct($prd_id); } $shipping_coords = $jinput->get('shipping_coords', 0, 'int'); $address_fields = $jinput->get('address_fields', 0, 'int'); $customer_fields = $jinput->get('customer_fields', 0, 'int'); $status = 2; if ($flag == 1) { $status = 1; } if (empty($order_id)) { $orders = new stdClass(); $orders->user_id = $user->id; $orders->region_id = $this->_db->Quote($region_id); $orders->status_id = 2; try { $this->_db->insertObject('#__ksenmart_orders', $orders); $order_id = $this->_db->insertid(); } catch (Exception $e) { } } else { $orders = new stdClass(); $orders->id = $this->_db->Quote($order_id); $orders->user_id = $user->id; $orders->region_id = $this->_db->Quote($region_id); $orders->shipping_id = $this->_db->Quote($shipping_id); $orders->payment_id = $this->_db->Quote($payment_id); $orders->shipping_coords = $this->_db->Quote($shipping_coords); $orders->customer_fields = json_encode($customer_fields); $orders->address_fields = json_encode($address_fields); $orders->note = $this->_db->Quote($note); $orders->status_id = $this->_db->Quote($status); $orders->roistat = $this->_db->q($roistat); try { $result = $this->_db->updateObject('#__ksenmart_orders', $orders, 'id'); } catch (Exception $e) { } } if ($prd->type == 'set') { $properties = $this->getPropertiesVByIds(KSMProducts::getSetRelatedIds($prd_id)); $item_properties = array(); foreach ($properties as $property) { $value = $jinput->get('property_' . $prd_id . '_' . $property->property_id, null, 'string'); if (!empty($value)) { $item_properties[$property->property_id] = array('value_id' => $value); } } } else { $properties = $this->getPropertiesVByIds(array($prd->id)); $item_properties = array(); foreach ($properties as $property) { $value = $jinput->get('property_' . $property->property_id, null, 'string'); if (!empty($value)) { $item_properties[$property->property_id] = array('value_id' => $value); } } } $order_item = new stdClass(); $order_item->order_id = $order_id; $order_item->product_id = $prd->id; $order_item->price = $prd->price; $order_item->count = $count; $order_item->properties = json_encode($item_properties); try { $this->_db->insertObject('#__ksenmart_order_items', $order_item); } catch (Exception $e) { } if ($params->get('use_stock', 1) == 1) { $prop_values = new stdClass(); $prop_values->id = $prd->id; $prop_values->in_stock = $prd->in_stock - $count; try { $result = $this->_db->updateObject('#__ksenmart_product_properties_values', $orders, 'id'); } catch (Exception $e) { } } if ($flag == 1) { if (!empty($email)) { KSMOrders::sendOrderMail($order_id); } KSMOrders::sendOrderMail($order_id, true); $session->set('shopcart_discount', ''); $session->set('shop_order_id', null); } else { $session->set('shop_order_id', $order_id); } $cost = $prd->price * $count; $order_object = new stdClass(); $order_object->id = $order_id; $order_object->cost = $cost; try { $result = $this->_db->updateObject('#__ksenmart_orders', $order_object, 'id'); } catch (Exception $e) { } $this->onExecuteAfter('createOrder', array(&$order_id)); return $order_id; }
public static function getRelated($pid) { $rows = new stdClass(); if (!empty($pid) && $pid > 0) { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select(' pr.id, pr.product_id, pr.relative_id, pr.relation_type ')->from('#__ksenmart_products_relations AS pr')->where('pr.relation_type="relation"')->where('pr.product_id=' . $db->escape($pid)); $db->setQuery($query); $rows = $db->loadObjectList(); if (!empty($rows)) { foreach ($rows as &$row) { $row = KSMProducts::getProduct($row->relative_id); } } } return $rows; }
public static function getOrderItems($oid) { self::onExecuteBefore(array(&$oid)); if (!empty($oid)) { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select(' o.id, o.order_id, o.product_id, o.price, o.count, o.properties '); $query->from('#__ksenmart_order_items AS o'); $query->where('o.order_id=' . $db->escape($oid)); $db->setQuery($query); $order = $db->loadObjectList(); if (!empty($order)) { self::setOrderItemsProperties($order, $oid); foreach ($order as $o_item) { $o_item->product = KSMProducts::getProduct($o_item->product_id); } } self::onExecuteAfter(array($order)); return $order; } return new stdClass(); }
function getOrder($vars = array()) { $this->onExecuteBefore('getOrder', array(&$value)); $id = JRequest::getInt('id'); $order = KSSystem::loadDbItem($id, 'orders'); if (isset($vars['user_id'])) { $order->user_id = $vars['user_id']; } if (isset($vars['region_id'])) { $order->region_id = $vars['region_id']; } if (isset($vars['shipping_id'])) { $order->shipping_id = $vars['shipping_id']; } if (isset($vars['payment_id'])) { $order->payment_id = $vars['payment_id']; } $order->cost = 0; $order->discounts = property_exists($order, 'discounts') ? $order->discounts : '[]'; $order->customer_fields = json_decode($order->customer_fields, true); $order->address_fields = json_decode($order->address_fields, true); if (!isset($vars['items'])) { $query = $this->_db->getQuery(true); $query->select('*')->from('#__ksenmart_order_items')->where('order_id=' . $id); $this->_db->setQuery($query); $order->items = $this->_db->loadObjectList(); } else { $items = array(); if (count($vars['items']) == 1 && !is_array($vars['items'][0])) { $vars['items'] = array(); } foreach ($vars['items'] as $item) { $item['properties'] = isset($item['properties']) ? $item['properties'] : array(); $item = (object) $item; $item->price = KSMProducts::getPriceWithProperties($item->product_id, $item->properties, $item->basic_price); $item->properties = json_encode($item->properties); $items[] = $item; } $order->items = $items; } foreach ($order->items as &$item) { $query = $this->_db->getQuery(true); $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id=' . $item->product_id); $query = KSMedia::setItemMainImageToQuery($query); $this->_db->setQuery($query); $product = $this->_db->loadObject(); if (count($product)) { $item->title = $product->title; $item->alias = $product->alias; $item->product_code = $product->product_code; $item->product_packaging = $product->product_packaging; $item->properties = json_decode($item->properties, true); $query = $this->_db->getQuery(true); $query->select('kp.*')->from('#__ksenmart_properties as kp')->innerjoin('#__ksenmart_product_properties_values as kppv on kp.id=kppv.property_id')->where('kppv.product_id=' . $item->product_id)->where('kp.type=' . $this->_db->quote('select'))->order('kp.ordering')->group('kp.id'); $this->_db->setQuery($query); $properties = $this->_db->loadObjectList('id'); foreach ($properties as &$property) { $query = $this->_db->getQuery(true); $query->select('kpv.*')->from('#__ksenmart_property_values as kpv')->innerjoin('#__ksenmart_product_properties_values as kppv on kpv.id=kppv.value_id')->where('kppv.product_id=' . $item->product_id)->where('kpv.property_id=' . $property->id)->order('kpv.ordering')->group('kpv.id'); $this->_db->setQuery($query); $property->values = $this->_db->loadObjectList('id'); foreach ($property->values as $value) { if (isset($item->properties[$property->id]) && is_array($item->properties[$property->id]) && in_array($value->id, $item->properties[$property->id])) { $value->selected = true; } else { $value->selected = false; } } } $item->properties = $properties; $item->small_img = KSMedia::resizeImage($product->filename, 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36), json_decode($product->params, true)); } else { $item->title = JText::_('ksm_orders_order_deleteditem_title'); $item->alias = ''; $item->product_code = ''; $item->product_packaging = 1; $item->properties = array(); $item->small_img = KSMedia::resizeImage('', 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36)); } $item->val_price = KSMPrice::showPriceWithTransform($item->price); $item->val_total_price = KSMPrice::showPriceWithTransform($item->price * $item->count); $order->cost += $item->price * $item->count; } $order->costs = array('cost' => $order->cost, 'cost_val' => KSMPrice::showPriceWithTransform($order->cost), 'discount_cost' => 0, 'discount_cost_val' => KSMPrice::showPriceWithTransform(0), 'shipping_cost' => 0, 'shipping_cost_val' => KSMPrice::showPriceWithTransform(0), 'total_cost' => $order->cost, 'total_cost_val' => KSMPrice::showPriceWithTransform($order->cost)); $this->onExecuteAfter('getOrder', array(&$order)); return $order; }
public function getLinks() { $this->onExecuteBefore('getLinks'); $query = $this->_db->getQuery(true); $query->select('id')->from('#__ksenmart_products')->where('id<' . $this->_id)->order('id DESC'); $this->_db->setQuery($query, 0, 1); $prev_id = $this->_db->loadResult(); if (empty($prev_id)) { $query = $this->_db->getQuery(true); $query->select('max(id)')->from('#__ksenmart_products'); $this->_db->setQuery($query, 0, 1); $prev_id = $this->_db->loadResult(); } $query = $this->_db->getQuery(true); $query->select('id')->from('#__ksenmart_products')->where('id>' . $this->_id)->order('id ASC'); $this->_db->setQuery($query, 0, 1); $next_id = $this->_db->loadResult(); if (empty($next_id)) { $query = $this->_db->getQuery(true); $query->select('min(id)')->from('#__ksenmart_products'); $this->_db->setQuery($query, 0, 1); $next_id = $this->_db->loadResult(); } $prev_link = KSMProducts::generateProductLink($prev_id); $next_link = KSMProducts::generateProductLink($next_id); $this->onExecuteAfter('getLinks', array(&$prev_link, &$next_link)); return array($prev_link, $next_link); }
function onBeforeStartComponent() { $config = JFactory::getConfig(); if (!$config->get('config.caching', 0)) { return false; } $db = JFactory::getDBO(); $app = JFactory::getApplication(); $path = $app->getPathway(); $jinput = $app->input; $view = $jinput->get('view', 'catalog', 'string'); $layout = $jinput->get('layout', 'default', 'string'); switch ($view) { case 'catalog': $catalog_path = array(); $categories = JRequest::getVar('categories', array()); JArrayHelper::toInteger($categories); $manufacturers = JRequest::getVar('manufacturers', array()); JArrayHelper::toInteger($manufacturers); $countries = JRequest::getVar('countries', array()); JArrayHelper::toInteger($countries); if (count($categories) == 1) { $catid = $categories[0]; while ((int) $catid != 0) { $query = "select id,parent,title,alias from #__ksenmart_categories where id='{$catid}'"; $db->setQuery($query); $cat = $db->loadObject(); $cat->link = JRoute::_('index.php?option=com_ksenmart&view=catalog&categories[]=' . $cat->id); $catalog_path[] = array('title' => $cat->title, 'link' => $cat->link); $catid = $cat->parent; } $catalog_path = array_reverse($catalog_path); } elseif (count($manufacturers) == 1) { $query = "select title from #__ksenmart_manufacturers where id='{$manufacturers['0']}'"; $db->setQuery($query); $title = $db->loadResult(); $catalog_path[] = array('title' => $title, 'link' => ''); } elseif (count($countries) == 1) { $query = "select title from #__ksenmart_countries where id='{$countries['0']}'"; $db->setQuery($query); $title = $db->loadResult(); $catalog_path[] = array('title' => $title, 'link' => ''); } else { $catalog_path[] = array('title' => JText::_('KSM_CATALOG_TITLE'), 'link' => ''); } $k = 0; foreach ($catalog_path as $c_path) { $k++; if ($k == count($catalog_path)) { $path->addItem($c_path['title']); } else { $path->addItem($c_path['title'], $c_path['link']); } } break; case 'comments': $id = $jinput->get('id', 0, 'int'); if ($id == 0) { $path->addItem(JText::_('KSM_REVIEWS_LIST_PATH_TITLE')); } else { $path->addItem(JText::_('KSM_REVIEWS_LIST_PATH_TITLE'), 'index.php?option=com_ksenmart&view=comments&Itemid=' . KSSystem::getShopItemid()); $path->addItem(JText::_('KSM_REVIEW_ITEM_PATH_TITLE')); } break; case 'order': $path->addItem('Оформление заказа'); break; case 'product': $id = $jinput->get('id', 0, 'int'); KSMProducts::incProductHit($id); $cat_path = array(); $final_categories = array(); $sql = $db->getQuery(true); $sql->select('category_id')->from('#__ksenmart_products_categories')->where('product_id=' . $id)->where('is_default=1'); $db->setQuery($sql); $default_category = $db->loadResult(); $sql = $db->getQuery(true); $sql->select('category_id')->from('#__ksenmart_products_categories')->where('product_id=' . $id); $db->setQuery($sql); $product_categories = $db->loadObjectList(); foreach ($product_categories as $product_category) { if (!empty($default_category)) { $id_default_way = false; } else { $id_default_way = true; } $categories = array(); $parent = $product_category->category_id; while ($parent != 0) { if ($parent == $default_category) { $id_default_way = true; } $sql = $db->getQuery(true); $sql->select('id,parent')->from('#__ksenmart_categories')->where('id=' . $parent); $db->setQuery($sql); $category = $db->loadObject(); $categories[] = $category->id; $parent = $category->parent; } if ($id_default_way && count($categories) > count($final_categories)) { $final_categories = $categories; } } $final_categories = array_reverse($final_categories); foreach ($final_categories as $final_category) { $sql = $db->getQuery(true); $sql->select('title,id')->from('#__ksenmart_categories')->where('id=' . $final_category); $db->setQuery($sql); $category = $db->loadObject(); $category->link = JRoute::_('index.php?option=com_ksenmart&view=catalog&categories[]=' . $final_category . '&Itemid=' . KSSystem::getShopItemid()); $cat_path[] = $category; } foreach ($cat_path as $cat) { $path->addItem($cat->title, $cat->link); } $query = "select title from #__ksenmart_products where id='{$id}'"; $db->setQuery($query); $title = $db->loadResult(); $path->addItem($title); break; } return true; }
/** * KsenMartModelcatalog::getItems() * * @return */ public function getItems() { $this->onExecuteBefore('getItems'); $items = parent::getItems(); foreach ($items as &$item) { $item = KSMProducts::getProduct($item->id); } $this->onExecuteAfter('getItems', array(&$items)); return $items; }
public function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $this->params = JComponentHelper::getParams('com_ksenmart'); $path = $app->getPathway(); $model = $this->getModel(); $this->state = $this->get('State'); $document->addScript(JURI::base() . 'components/com_ksenmart/js/highslide/highslide-with-gallery.js', 'text/javascript', true); $document->addScript(JURI::base() . 'components/com_ksenmart/js/highslide.js', 'text/javascript', true); $document->addScript(JURI::base() . 'components/com_ksenmart/js/slides.min.jquery.js', 'text/javascript', true); $document->addStyleSheet(JURI::base() . 'components/com_ksenmart/js/highslide/highslide.css'); $document->addStyleSheet(JURI::base() . 'components/com_ksenmart/css/slides.css'); if ($model->_id && $this->getLayout() != 'comment_congratulation') { $this->product = $model->getProduct(); if ($this->product) { if (!JFactory::getConfig()->get('config.caching', 0)) { $cat_path = $this->get('CategoriesPath'); foreach ($cat_path as $cat) { $path->addItem($cat->title, $cat->link); } } $title = $model->getProductTitle(); $this->images = $model->getImages(); $this->related = KSMProducts::getRelated($this->product->id); $this->links = KSMProducts::getLinks($this->product->id); $document->setTitle($title); $model->setProductMetaData(); if ($this->product->type == 'set') { $document->addScript(JURI::base() . 'components/com_ksenmart/js/set.js', 'text/javascript', true); $this->set_related = KSMProducts::getSetRelated($this->product->id, true); } else { $document->addScript(JURI::base() . 'components/com_ksenmart/js/product.js', 'text/javascript', true); } if ($this->product->is_parent) { $template = $this->params->get('parent_products_template', 'list'); if ($template == 'list') { $this->childs_groups = $model->getChildsGroups(); } elseif ($template == 'select') { $this->childs_titles = $model->getChildsTitles(); $this->childs_title = $model->getChildsTitle(); if (!count($this->images)) { $model->_id = $this->product->parent_id; $this->images = $model->getImages(); $model->_id = $this->product->id; } } $this->setLayout('parent_product_' . $template); } elseif ($this->product->parent_id != 0) { $this->product->parent = KSMProducts::getProduct($this->product->parent_id); if ($this->params->get('parent_products_template', 'list') != 'list') { $template = $this->params->get('parent_products_template', 'list'); $this->product->title = $this->product->parent->title; $this->assign('childs_titles', $model->getChildsTitles($this->product->parent_id)); $this->assign('childs_title', $model->getChildsTitle($this->product->parent_id)); $this->setLayout('parent_product_' . $template); } else { $this->setLayout($this->product->type); } if (!JFactory::getConfig()->get('config.caching', 0)) { $path->addItem($this->product->parent->title, $this->product->parent->link); } } else { $this->setLayout($this->product->type); } if (!JFactory::getConfig()->get('config.caching', 0)) { $path->addItem($this->product->title); } $model->form = 'review'; $this->reviewform = $model->getForm(); } else { $this->setLayout('no_product'); } } else { if ($this->getLayout() == 'product_comment_form') { $document->addScript(JURI::base() . 'components/com_ksenmart/js/product.js', 'text/javascript', true); $this->product->id = JRequest::getVar('id', 0); $this->setLayout('product_comment_form'); } elseif ($this->getLayout() == 'comment_congratulation') { echo '<script> window.parent.location.reload();</script>'; $this->setLayout('product_comment_form'); } else { $this->setLayout('no_product'); } } parent::display($tpl); }