/** * Sets the model's state * * @return array() */ function _setModelState() { $state = parent::_setModelState(); $app = JFactory::getApplication(); $model = $this->getModel($this->get('suffix')); $ns = $this->getNamespace(); $session = JFactory::getSession(); $user = JFactory::getUser(); $state['filter_user'] = $user->id; if (empty($user->id)) { $state['filter_session'] = $session->getId(); } Citruscart::load('CitruscartHelperUser', 'helpers.user'); $filter_group = CitruscartHelperUser::getUserGroup($user->id); $state['filter_group'] = $filter_group; foreach (@$state as $key => $value) { $model->setState($key, $value); } return $state; }
/** * Gets a product's add to cart section * formatted for display * * @param int $address_id * @return string html */ function getAddToCart($product_id, $values = array()) { $input = JFactory::getApplication()->input; $layout = 'product_buy'; Citruscart::load('CitruscartHelperProduct', 'helpers.product'); if (isset($values['layout'])) { $layout = $values['layout']; } JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setId($product_id); $user_id = JFactory::getUser()->id; $filter_group = CitruscartHelperUser::getUserGroup($user_id, $product_id); $qty = $input->getInt('product_qty', 1); $model->setState('filter_group', $filter_group); $model->setState('product.qty', $qty); $model->setState('user.id', $user_id); $row = $model->getItem(false, false, false); $buy_layout_override = $row->product_parameters->get('product_buy_layout_override'); if (!empty($buy_layout_override)) { $layout = $buy_layout_override; } $html = CitruscartHelperProduct::getCartButton($product_id, $layout, $values, $this->_callback_js); return $html; }
/** * Sample use of the products model for getting products with certain properties * See admin/models/products.php for all the filters currently built into the model * * @param $parameters * @return unknown_type */ function getProducts() { // Check the registry to see if our Citruscart class has been overridden if (!class_exists('Citruscart')) { JLoader::register("Citruscart", JPATH_ADMINISTRATOR . "/components/com_citruscart/defines.php"); } // load the config class Citruscart::load('Citruscart', 'defines'); Citruscart::load('CitruscartHelperProduct', 'helpers.product'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_citruscart/models'); // get the model $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); // setting the model's state tells it what items to return $model->setState('filter_published', '1'); $date = JFactory::getDate(); $model->setState('filter_published_date', $date->toSql()); $model->setState('filter_enabled', '1'); // Set category state if ($this->params->get('category', '1') != '1') { $model->setState('filter_category', $this->params->get('category', '1')); } // Set manufacturer state if ($this->params->get('manufacturer', '') != '') { $model->setState('filter_manufacturer', $this->params->get('manufacturer', '')); } // Set id set state if ($this->params->get('id_set', '') != '') { $params_id_set = $this->params->get('id_set'); $id_array = explode(',', $params_id_set); $id_set = "'" . implode("', '", $id_array) . "'"; $model->setState('filter_id_set', $id_set); } // set the states based on the parameters $model->setState('limit', $this->params->get('max_number', '10')); if ($this->params->get('price_from', '-1') != '-1') { $model->setState('filter_price_from', $this->params->get('price_from', '-1')); } if ($this->params->get('price_to', '-1') != '-1') { $model->setState('filter_price_to', $this->params->get('price_to', '-1')); } $order = $this->params->get('order'); $direction = $this->params->get('direction', 'ASC'); switch ($order) { case "2": case "name": $model->setState('order', 'tbl.product_name'); break; case "1": case "created": $model->setState('order', 'tbl.created_date'); break; case "0": case "ordering": default: $model->setState('order', 'tbl.ordering'); break; } if ($this->params->get('random', '0') == '1') { $model->setState('order', 'RAND()'); } $model->setState('direction', $direction); $config = Citruscart::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $default_user_group = Citruscart::getInstance()->get('default_user_group'); $user_groups_array = $this->getUserGroups(); $overide_price = false; if (count($user_groups_array) > 1 && $user_groups_array[0] != $default_user_group) { $overide_price = true; } // using the set filters, get a list of products if ($products = $model->getList(true, false)) { if ($show_tax) { Citruscart::load('CitruscartHelperUser', 'helpers.user'); $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'CitruscartTable'); $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } foreach ($products as $product) { if ($overide_price) { $filter_group = CitruscartHelperUser::getUserGroup(JFactory::getUser()->id, $product->product_id); $price = CitruscartHelperProduct::getPrice($product->product_id, '1', $filter_group); $product->price = $price->product_price; } $product->taxtotal = 0; $product->tax = 0; if ($show_tax) { $taxtotal = CitruscartHelperProduct::getTaxTotal($product->product_id, $geozones); $product->taxtotal = $taxtotal; $product->tax = $taxtotal->tax_total; } $product->filter_category = ''; $categories = CitruscartHelperProduct::getCategories($product->product_id); if (!empty($categories)) { $product->link .= "&filter_category=" . $categories[0]; $product->filter_category = $categories[0]; } $itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($product->filter_category, true); if (empty($itemid)) { $product->itemid = $this->params->get('itemid'); } else { $product->itemid = $itemid; } } } return $products; }
/** * Gets a product's add to cart section * formatted for display * * @param int $address_id * @return string html */ function getAddToCart($product_id, $values = array()) { $input = JFactory::getApplication()->input; $html = ''; $view = $this->getView('products', 'html'); //$model = $this->getModel( $this->get('suffix') ); $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setId($product_id); Citruscart::load('CitruscartHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; $filter_group = CitruscartHelperUser::getUserGroup($user_id); $model->setState('filter_group', $filter_group); //$model->_item = ''; $row = $model->getItem(false); if ($row->product_notforsale || Citruscart::getInstance()->get('shop_enabled') == '0') { return $html; } $view->set('_controller', 'products'); $view->set('_view', 'products'); $view->set('_doTask', true); $view->set('hidemenu', true); $view->setModel($model, true); $view->setLayout('product_buy'); $view->assign('item', $row); $view->assign('product_id', $product_id); $view->assign('values', $values); $filter_category = $model->getState('filter_category', $input->getInt('filter_category', (int) @$values['filter_category'])); $view->assign('filter_category', $filter_category); $view->assign('validation', "index.php?option=com_citruscart&view=products&task=validate&format=raw"); $config = Citruscart::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $view->assign('show_tax', $show_tax); $view->assign('tax', 0); $view->assign('taxtotal', ''); $view->assign('shipping_cost_link', ''); $row->tax = '0'; if ($show_tax) { // finish CitruscartHelperUser::getGeoZone -- that's why this isn't working Citruscart::load('CitruscartHelperUser', 'helpers.user'); $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'CitruscartTable'); $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } $taxtotal = CitruscartHelperProduct::getTaxTotal($product_id, $geozones); $tax = $taxtotal->tax_total; $row->taxtotal = $taxtotal; $row->tax = $tax; $view->assign('taxtotal', $taxtotal); $view->assign('tax', $tax); } // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $view->assign('shipping_cost_link', $shipping_cost_link); } $invalidQuantity = '0'; if (empty($values)) { $product_qty = '1'; // get the default set of attribute_csv $default_attributes = CitruscartHelperProduct::getDefaultAttributes($product_id); sort($default_attributes); $attributes_csv = implode(',', $default_attributes); $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } if (!empty($values)) { $product_id = !empty($values['product_id']) ? (int) $values['product_id'] : $input->getInt('product_id'); $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : '1'; // TODO only display attributes available based on the first selected attribute? $attributes = array(); foreach ($values as $key => $value) { if (substr($key, 0, 10) == 'attribute_') { $attributes[] = $value; } } sort($attributes); $attributes_csv = implode(',', $attributes); // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } // adjust the displayed price based on the selected attributes $table = JTable::getInstance('ProductAttributeOptions', 'CitruscartTable'); $attrs = array(); foreach ($attributes as $attrib_id) { // load the attrib's object $table->load($attrib_id); // update the price //$row->price = $row->price + floatval( "$table->productattributeoption_prefix"."$table->productattributeoption_price"); // is not + or - if ($table->productattributeoption_prefix == '=') { $row->price = floatval($table->productattributeoption_price); } else { $row->price = $row->price + floatval("{$table->productattributeoption_prefix}" . "{$table->productattributeoption_price}"); } $attrs[] = $table->productattributeoption_id; } $row->sku = CitruscartHelperProduct::getProductSKU($row, $attrs); $view->assign('item', $row); } $view->assign('availableQuantity', $availableQuantity); $view->assign('invalidQuantity', $invalidQuantity); ob_start(); JFactory::getApplication()->triggerEvent('onDisplayProductAttributeOptions', array($row->product_id)); $view->assign('onDisplayProductAttributeOptions', ob_get_contents()); ob_end_clean(); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Returns the shipping rate for an item * Going through this helper enables product-specific flat rates in the future... * * @param int $shipping_method_id * @param int $geozone_id * @param int $product_id * @return object */ public function getRate($shipping_method_id, $geozone_id, $product_id = '', $use_weight = '0', $weight = '0') { $session = JFactory::getSession(); $isPOS = $session->get('user_type', '', 'citruscart_pos') == ''; $user_id = JFactory::getUser()->id; if ($isPOS) { $user_id = $session->get('user_id', JFactory::getUser()->id, 'citruscart_pos'); } Citruscart::load('CitruscartHelperUser', 'helpers.user'); $filter_group = CitruscartHelperUser::getUserGroup($user_id, $product_id); // TODO Give this better error reporting capabilities JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('ShippingRates', 'CitruscartModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_geozone', $geozone_id); $model->setState('filter_user_group', $filter_group); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); if (empty($product->product_id)) { return JTable::getInstance('ShippingRates', 'CitruscartTable'); } if (empty($product->product_ships)) { // product doesn't require shipping, therefore cannot impact shipping costs return JTable::getInstance('ShippingRates', 'CitruscartTable'); } if (!empty($use_weight) && $use_weight == '1') { if (!empty($weight)) { $model->setState('filter_weight', $weight); } else { $model->setState('filter_weight', $product->product_weight); } } $items = $model->getList(); if (empty($items)) { return JTable::getInstance('ShippingRates', 'CitruscartTable'); } return $items[0]; }
/** * Gets a product's add to cart section * formatted for display * * @param int $address_id * @return string html */ private function getAddToCart($product_id, $values = array(), $params = array()) { $input = JFactory::getApplication()->input; $html = ''; Citruscart::load('CitruscartModelProducts', 'models.products'); $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $user = JFactory::getUser(); Citruscart::load('CitruscartHelperUser', 'helpers.user'); $filter_group = CitruscartHelperUser::getUserGroup($user->id, $product_id); $model->setState('filter_group', $filter_group); $model->setId($product_id); $row = $model->getItem(false); $vars = new JObject(); if ($row->product_notforsale || Citruscart::getInstance()->get('shop_enabled') == '0') { return $html; } $vars->item = $row; $vars->product_id = $product_id; $vars->values = $values; $vars->validation = "index.php?option=com_citruscart&view=products&task=validate&format=raw"; $vars->params = $params; $config = Citruscart::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $vars->show_tax = $show_tax; $vars->tax = 0; $vars->taxtotal = ''; $vars->shipping_cost_link = ''; if ($show_tax) { // finish CitruscartHelperUser::getGeoZone -- that's why this isn't working Citruscart::load('CitruscartHelperUser', 'helpers.user'); $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'CsitruscartTable'); $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } $taxtotal = CitruscartHelperProduct::getTaxTotal($product_id, $geozones); $tax = $taxtotal->tax_total; $vars->taxtotal = $taxtotal; $vars->tax = $tax; } // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $vars->shipping_cost_link = $shipping_cost_link; } $invalidQuantity = '0'; if (empty($values)) { $product_qty = '1'; // get the default set of attribute_csv $default_attributes = CitruscartHelperProduct::getDefaultAttributes($product_id); sort($default_attributes); $attributes_csv = implode(',', $default_attributes); $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } if (!empty($values)) { $product_id = !empty($values['product_id']) ? (int) $values['product_id'] : $input->getInt('product_id'); $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : '1'; // TODO only display attributes available based on the first selected attribute? $attributes = array(); foreach ($values as $key => $value) { if (substr($key, 0, 10) == 'attribute_') { $attributes[] = $value; } } sort($attributes); $attributes_csv = implode(',', $attributes); // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } $vars->availableQuantity = $availableQuantity; $vars->invalidQuantity = $invalidQuantity; JPluginHelper::importPlugin('Citruscart'); ob_start(); JFactory::getApplication()->triggerEvent('onDisplayProductAttributeOptions', array($product_id)); $vars->onDisplayProductAttributeOptions = ob_get_contents(); ob_end_clean(); ob_start(); echo $this->_getLayout('product_buy', $vars); $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Sample use of the products model for getting products with certain properties * See admin/models/products.php for all the filters currently built into the model * * @param $parameters * @return unknown_type */ function getProducts() { // Check the registry to see if our Citruscart class has been overridden if (!class_exists('Citruscart')) { JLoader::register("Citruscart", JPATH_ADMINISTRATOR . "/components/com_citruscart/defines.php"); } // load the config class Citruscart::load('Citruscart', 'defines'); Citruscart::load('CitruscartHelperProduct', 'helpers.product'); Citruscart::load('CitruscartHelperUser', 'helpers.user'); $helper = new CitruscartHelperProduct(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_citruscart/models'); // get the model $model = JModelLegacy::getInstance('OrderItems', 'CitruscartModel'); $model->setState('limit', $this->params->get('max_number', '5')); $query = $model->getQuery(); // group results by product ID $query->group('tbl.product_id'); // select the total number of sales for each product $field = array(); $field[] = " SUM(tbl.orderitem_quantity) AS total_sales "; $field[] = " p.product_description_short AS product_description_short "; $query->select($field); // order results by the total sales $query->order('total_sales DESC'); $model->setQuery($query); $show_tax = Citruscart::getInstance()->get('display_prices_with_tax'); // using the set filters, get a list of products if ($products = $model->getList(false, false)) { if ($show_tax) { $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'CitruscartTable'); $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } foreach ($products as $product) { $product->link = 'index.php?option=com_citruscart&view=products&task=view&id=' . $product->product_id; $filter_group = CitruscartHelperUser::getUserGroup(JFactory::getUser()->id, $product->product_id); $price = $helper->getPrice($product->product_id, '1', $filter_group); $product->price = isset($price->product_price) ? $price->product_price : 0; //product total $product->taxtotal = 0; $product->tax = 0; if ($show_tax) { $taxtotal = CitruscartHelperProduct::getTaxTotal($product->product_id, $geozones); $product->taxtotal = $taxtotal; $product->tax = $taxtotal->tax_total; } $product->filter_category = ''; $categories = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getCategories($product->product_id); if (!empty($categories)) { $product->link .= "&filter_category=" . $categories[0]; $product->filter_category = $categories[0]; } $itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($product->filter_category, true); if (empty($itemid)) { $itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->findItemid(array('view' => 'products')); } $product->itemid = $itemid; } } return $products; }
/** * Set basic properties for the item, whether in a list or a singleton * * @param unknown_type $item * @param unknown_type $key * @param unknown_type $refresh */ protected function prepareItem(&$item, $key = 0, $refresh = false) { Citruscart::load("CitruscartHelperProduct", 'helpers.product'); Citruscart::load('CitruscartHelperSubscription', 'helpers.subscription'); $helper_product = new CitruscartHelperProduct(); if (!empty($item->product_recurs)) { $item->recurring_price = $item->price; if ($item->subscription_prorated) { Citruscart::load('CitruscartHelperSubscription', 'helpers.subscription'); $result = CitruscartHelperSubscription::calculateProRatedTrial($item->subscription_prorated_date, $item->subscription_prorated_term, $item->recurring_period_unit, $item->recurring_trial_price, $item->subscription_prorated_charge); $item->price = $result['price']; $item->prorated_price = $result['price']; $item->prorated_interval = $result['interval']; $item->prorated_unit = $result['unit']; // $item->recurring_trial = $result['trial']; } else { if (!empty($item->recurring_trial)) { $item->price = $item->recurring_trial_price; } } } $user_id = $this->getState('user.id', 0); $qty = $this->getState('product.qty', -1); if ($qty > -1) { $user_group = CitruscartHelperUser::getUserGroup($user_id, $item->product_id); $price = CitruscartHelperProduct::getPrice($item->product_id, $qty, $user_group); $item->price = @$price->product_price; } $item->product_parameters = new DSCParameter($item->product_params); $item->slug = $item->product_alias ? ":{$item->product_alias}" : ""; $item->link = 'index.php?option=com_citruscart&view=products&task=view&id=' . $item->product_id; $item->link_edit = 'index.php?option=com_citruscart&view=products&task=edit&id=' . $item->product_id; $item->product_categories = $this->getCategories($item->product_id); $item->default_attributes = $helper_product->getDefaultAttributes($item->product_id); $item->product_classes = null; foreach ($item->product_categories as $cat) { $item->product_classes .= " " . $cat->category_alias; } if (!empty($item->product_class_suffix)) { $item->product_classes .= " " . $item->product_class_suffix; } $item->product_classes = trim($item->product_classes); parent::prepareItem($item, $key, $refresh); }
/** * * Enter description here ... * @param $product_id * @param $values * @return unknown_type */ function getAddToCart($product_id, $values = array()) { $app = JFactory::getApplication(); $html = ''; DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Products', 'CitruscartModel'); $model->setId($product_id); $session = JFactory::getSession(); $user_id = $session->get('user_id', '', 'citruscart_pos'); $filter_group = CitruscartHelperUser::getUserGroup($user_id, $product_id); $view = $this->getView('pos', 'html'); $view->setModel($model, true); $model->setState('filter_group', $filter_group); $row = $model->getItem(false); $view->assign('product', $row); $view->setLayout('viewproduct'); ob_start(); JFactory::getApplication()->triggerEvent('onDisplayProductAttributeOptions', array($product_id)); $view->assign('onDisplayProductAttributeOptions', ob_get_contents()); ob_end_clean(); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Get the cart button form for a specific product * * @param int $product_id The id of the product * @return html The add to cart form */ public static function getCartButton($product_id, $layout = 'product_buy', $values = array(), &$callback_js = '') { /* Get the application */ $app = JFactory::getApplication(); if (is_array($values) && !count($values)) { $values = $app->input->get('request'); //$values = JRequest::get( 'request' ); } $html = ''; $page = $app->input->get('page', 'product'); //$page = JRequest::getVar( 'page', 'product' ); $isPOS = $page == 'pos'; if ($isPOS) { JLoader::register("CitruscartViewPOS", JPATH_ADMINISTRATOR . "/components/com_citruscart/views/pos/view.html.php"); $view = new CitruscartViewPOS(); } else { JLoader::register("CitruscartViewProducts", JPATH_SITE . "/components/com_citruscart/views/products/view.html.php"); $view = new CitruscartViewProducts(); } $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setId($product_id); $model->setState('task', 'product_buy'); Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper_product = CitruscartHelperBase::getInstance('Product'); Citruscart::load('CitruscartHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; if ($isPOS) { $user_id = $app->input->getInt('user_id', $user_id); //$user_id = JRequest::getInt( 'user_id', $user_id ); } $filter_group = CitruscartHelperUser::getUserGroup($user_id, $product_id); $qty = isset($values['product_qty']) && !empty($values['product_qty']) ? $values['product_qty'] : 1; $model->setState('filter_group', $filter_group); $model->setState('product.qty', $qty); $model->setState('user.id', $user_id); $row = $model->getItem(false, true, false); if ($row->product_notforsale || Citruscart::getInstance()->get('shop_enabled') == '0') { return $html; } // This enable this helper method to be used outside of Citruscart if ($isPOS) { $view->set('_controller', 'pos'); $view->set('_view', 'pos'); } else { $view->addTemplatePath(JPATH_SITE . '/components/com_citruscart/views/products/tmpl'); $view->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication('site')->getTemplate() . '/html/com_citruscart/products/'); // add extra templates $view->addTemplatePath(Citruscart::getPath('product_buy_templates')); $view->set('_controller', 'products'); $view->set('_view', 'products'); } $view->set('_doTask', true); $view->set('hidemenu', true); $view->setModel($model, true); $view->setLayout($layout); $view->product_id = $product_id; $view->values = $values; $filter_category = $model->getState('filter_category', $app->input->getInt('filter_category', 0)); //$filter_category = $model->getState( 'filter_category', JRequest::getInt( 'filter_category', ( int ) $values['filter_category'] ) ); $view->filter_category = $filter_category; if ($isPOS) { $view->validation = "index.php?option=com_citruscart&view=pos&task=validate&format=raw"; } else { $view->validation = "index.php?option=com_citruscart&view=products&task=validate&format=raw"; } $config = Citruscart::getInstance(); // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $view->shipping_cost_link = $shipping_cost_link; } $quantity_min = 1; if ($row->quantity_restriction) { $quantity_min = $row->quantity_min; } $invalidQuantity = '0'; $attributes = array(); $attr_orig = array(); if (empty($values)) { $product_qty = $quantity_min; // get the default set of attribute_csv if (!isset($row->default_attributes)) { $default_attributes = $helper_product->getDefaultAttributes($product_id); } else { $default_attributes = $row->default_attributes; } sort($default_attributes); $attributes_csv = implode(',', $default_attributes); $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } $attr_orig = $attributes = $default_attributes; } else { $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : $quantity_min; // TODO only display attributes available based on the first selected attribute? foreach ($values as $key => $value) { if (substr($key, 0, 10) == 'attribute_') { if (empty($value)) { $attributes[$key] = 0; } else { $attributes[$key] = $value; } } } if (!count($attributes)) { // no attributes are selected -> use default if (!isset($row->default_attributes)) { $attributes = $helper_product->getDefaultAttributes($product_id); } else { $attributes = $row->default_attributes; } } $attr_orig = $attributes; sort($attributes); // Add 0 to attributes to include all the root attributes //$attributes[] = 0;//remove this one. its causing the getAvailableQuantity to not get quantity because of wrong csv // For getting child opts $view->selected_opts = json_encode(array_merge($attributes, array('0'))); $attributes_csv = implode(',', $attributes); // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $invalidQuantity = '1'; } } // adjust the displayed price based on the selected or default attributes CitruscartHelperProduct::calculateProductAttributeProperty($row, $attr_orig, 'price', 'product_weight'); $show_tax = $config->get('display_prices_with_tax'); $show_product = $config->get('display_category_cartbuttons'); $view->show_tax = $show_tax; $row->tax = '0'; $row->taxtotal = '0'; if ($show_tax) { // finish CitruscartHelperUser::getGeoZone -- that's why this isn't working Citruscart::load('CitruscartHelperUser', 'helpers.user'); $geozones_user = CitruscartHelperUser::getGeoZones($user_id); if (empty($geozones_user)) { $geozones = array(Citruscart::getInstance()->get('default_tax_geozone')); } else { $geozones = array(); foreach ($geozones_user as $value) { $geozones[] = $value->geozone_id; } } Citruscart::load('CitruscartHelperTax', 'helpers.tax'); $product = new stdClass(); $product->product_price = $row->price; $product->product_id = $product_id; $tax = CitruscartHelperTax::calculateGeozonesTax(array($product), 2, $geozones); $row->taxtotal = $tax->tax_total; $row->tax = $tax->tax_total; } $row->_product_quantity = $product_qty; if ($page == 'product' || $isPOS) { $display_cartbutton = Citruscart::getInstance()->get('display_product_cartbuttons', '1'); } else { $display_cartbutton = Citruscart::getInstance()->get('display_category_cartbuttons', '1'); } $view->page = $page; $view->display_cartbutton = $display_cartbutton; $view->availableQuantity = $availableQuantity; $view->invalidQuantity = $invalidQuantity; if ($isPOS) { $view->product = $row; } else { $view->item = $row; } $dispatcher = JDispatcher::getInstance(); ob_start(); JFactory::getApplication()->triggerEvent('onDisplayProductAttributeOptions', array($row->product_id)); $view->onDisplayProductAttributeOptions = ob_get_contents(); ob_end_clean(); $html = $view->loadTemplate(); if (isset($view->callback_js) && !empty($view->callback_js)) { $callback_js = $view->callback_js; } return $html; }
private function doSearch($keyword = '', $match = '', $ordering = '', $areas = null) { if (!$this->_isInstalled()) { return array(); } $search_products = $search_wishlists = false; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->doSearchAreas()))) { return array(); } else { if (in_array('Citruscart', $areas) !== false) { $search_products = true; } if (in_array('wishlist', $areas) !== false) { $search_wishlists = true; } } } else { $search_products = $search_wishlists = true; } $keyword = trim($keyword); if (empty($keyword)) { return array(); } $cache_key = base64_encode(serialize($keyword) . serialize($match) . serialize($ordering) . serialize($areas)) . '.search-results'; $classname = strtolower(get_class($this)); $cache = JFactory::getCache($classname . '.search-results', ''); $cache->setCaching($this->cache_enabled); $cache->setLifeTime($this->cache_lifetime); $list = $cache->get($cache_key); if (empty($list)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $list = array(); $match = strtolower($match); if ($search_products) { $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setState('filter_published', 1); $model->setState('filter_enabled', 1); $model->setState('filter_published_date', JFactory::getDate()->toSql()); switch ($match) { case 'any': $model->setState('filter_any', $keyword); break; case 'all': $model->setState('filter_all', $keyword); break; case 'exact': default: $model->setState('filter', $keyword); break; } // order the items according to the ordering selected in com_search switch ($ordering) { case 'newest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'DESC'); break; case 'oldest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); break; case 'alpha': case 'popular': default: $model->setState('order', 'tbl.product_name'); break; } // filter according to shopper group Citruscart::load('CitruscartHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; $model->setState('filter_group', CitruscartHelperUser::getUserGroup($user_id)); //display_out_of_stock if (!$this->defines->get('display_out_of_stock')) { $model->setState('filter_quantity_from', '1'); } $items = $model->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->itemid_string = null; $item->itemid = (int) Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->product($item->product_id, null, true); if (!empty($item->itemid)) { $item->itemid_string = "&Itemid=" . $item->itemid; } $item->link = 'index.php?option=com_citruscart&view=products&task=view&id=' . $item->product_id; $item->href = $item->link . $item->itemid_string; $item->title = $item->product_name; $item->created = $item->created_date; $item->section = $this->params->get('title', "Citruscart"); $item->text = $item->product_description; $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'product'; } $list = array_merge($list, $items); } } if ($search_wishlists) { $model = JModelLegacy::getInstance('Wishlists', 'CitruscartModel'); $model->setState('filter_accessible', 1); $model->setState('filter_user', JFactory::getUser()->id); $model_items = JModelLegacy::getInstance('WishlistItems', 'CitruscartModel'); if (!empty(JFactory::getUser()->id)) { $model_items->setState('filter_user', JFactory::getUser()->id); } switch ($match) { case 'any': $model->setState('filter_any', $keyword); $model_items->setState('filter_search_any', $keyword); break; case 'all': $model->setState('filter_all', $keyword); $model_items->setState('filter_search_all', $keyword); break; case 'exact': default: $model->setState('filter', $keyword); $model_items->setState('filter_search', $keyword); break; } // order the items according to the ordering selected in com_search switch ($ordering) { case 'newest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'DESC'); break; case 'oldest': $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); break; case 'alpha': case 'popular': default: $model->setState('order', 'tbl.wishlist_name'); break; } $items = $model->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->href = $item->link = 'index.php?option=com_citruscart&view=wishlists&task=view&id=' . $item->wishlist_id; $item->title = $item->wishlist_name; $item->created = $item->created_date; $item->section = $this->params->get('title_wishlist', "Citruscart"); $item->text = ''; $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'wishlist'; } $list = array_merge($list, $items); } // now go through wishlist items $items = $model_items->getListRaw(); if (!empty($items)) { // format the items array according to what com_search expects foreach ($items as $key => $item) { $item->customer = $item->first_name . ' '; if (empty($item->middle_name)) { $item->customer .= $item->middle_name . ' '; } $item->customer .= $item->last_name; if (!strlen(trim($item->customer))) { $item->customer = $item->user_joomla_name; } $item->customer_link = 'index.php?option=com_users&view=profile&id=' . $item->user_id; $item->href = $item->link = 'index.php?option=com_citruscart&view=products&task=view&id=' . $item->product_id; $item->title = $item->product_name; $item->created = $item->created_date; $item->section = $this->params->get('title_wishlist', "Citruscart"); if (strlen($item->product_attributes)) { $attributes = explode(',', $item->product_attributes); $tbl = JTable::getInstance('ProductAttributes', 'CitruscartTable'); $tbl_opt = JTable::getInstance('ProductAttributeOptions', 'CitruscartTable'); $attr_list = array(); for ($i = 0, $c = count($attributes); $i < $c; $i++) { $tbl_opt->load($attributes[$i]); $tbl->load($tbl_opt->productattribute_id); $item->href .= '&attribute_' . $tbl_opt->productattribute_id . '=' . $attributes[$i]; $attr_list[] = $tbl->productattribute_name . ': ' . $tbl_opt->productattributeoption_name; } $item->text = implode('<br>', $attr_list); } else { $item->text = $item->product_name; } $item->browsernav = $this->params->get('link_behaviour', "0"); $item->source = $classname; $item->type = 'wishlistitem'; } $list = array_merge($list, $items); } } $cache->store($list, $cache_key); } return $list; }