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 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(); }
public function getChildsGroups() { $this->onExecuteBefore('getChildsGroups'); $childs_groups = array(); if ($this->_product->type == 'product' && $this->_product->parent_id == 0) { $empty_group = new stdClass(); $empty_group->id = 0; $empty_group->title = JText::_('KSM_PRODUCT_CHILDS_EMPTY_GROUP'); $empty_group->product_id = $this->_id; $empty_group->ordering = 0; $query = $this->_db->getQuery(true); $query->select(' cg.id, cg.title, cg.product_id, cg.ordering ')->from('#__ksenmart_products_child_groups AS cg')->where('cg.product_id=' . $this->_db->escape($this->_id))->order('cg.ordering'); $this->_db->setQuery($query); $childs_groups = $this->_db->loadObjectList('id'); array_unshift($childs_groups, $empty_group); $where = array(); foreach ($childs_groups as &$child) { $where[] = $child->id; } $sql = $this->_db->getQuery(true); $sql->select('p.id, p.parent_id, p.childs_group')->from("#__ksenmart_products as p")->where('p.parent_id =' . $this->_db->escape($this->_id))->where('(p.childs_group IN(' . implode(', ', $where) . '))')->order('p.ordering'); $this->_db->setQuery($sql); $products = $this->_db->loadObjectList('id'); foreach ($childs_groups as &$child) { $child->products = array(); foreach ($products as &$product) { if ($product->childs_group == $child->id) { $product = KSMProducts::getProduct($product->id); $child->products[$product->id] = $product; } continue; } } } $this->onExecuteAfter('getChildsGroups', array(&$childs_groups)); return $childs_groups; }
/** * 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); }