/** * * @return unknown_type */ function getItems() { // 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'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); // get the model $model = JModelLegacy::getInstance('Manufacturers', 'CitruscartModel'); // TODO Make this depend on the current filter_category? // setting the model's state tells it what items to return $model->setState('filter_enabled', '1'); $model->setState('order', 'tbl.manufacturer_name'); // set the states based on the parameters // using the set filters, get a list $items = $model->getList(); if (!empty($items)) { foreach ($items as $item) { // this gives error $item->itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->manufacturer($item->manufacturer_id, false); if (empty($item->itemid)) { $item->itemid = $this->params->get('itemid'); } } } return $items; }
/** * Adds items to the pathway if they aren't already present * * @param array $items A full pathway to the category, an array of pathway objects * @param int $item_id A default Itemid to use if none is found */ function insertCategories($items, $item_id = '') { $app = JFactory::getApplication(); $pathway = $app->getPathway(); $pathway_values = $pathway->getPathway(); // find the array_key of the first item in items that is in pathway $found = false; $found_key = 0; $new_pathway = array(); foreach ($items as $item) { if (!$found) { foreach ($pathway_values as $key => $object) { if (!$found) { if ($object->name == $item->name) { $found = true; $found_key = $key; } } } } } foreach ($pathway_values as $key => $object) { if ($key < $found_key || !$found) { $new_pathway[] = $object; } } // $new_pathway now has the pathway UP TO where we should inject the category pathway foreach ($items as $item) { $category_itemid = !empty($item_id) ? $item_id : Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($item->id, true); $item->link .= "&Itemid=" . $category_itemid; $new_pathway[] = $item; } $pathway->setPathway($new_pathway); return $new_pathway; }
public function getPAOCategories($category_ids) { $model = Citruscart::getClass('CitruscartModelProducts', 'models.products'); $model->setState('filter_published_date', $this->state['filter_published_date']); $return = $model->getPAOCategories($category_ids); return $return; }
/** * Method to build the pathway/breadcrumbs * return string */ function pathway() { $input = JFactory::getApplication()->input; $pathway = ''; $catid = $input->getInt('filter_category'); if ($this->params->get('showhome')) { $homeText = $this->params->get('hometext'); $homeText = empty($homeText) ? JText::_('COM_CITRUSCART_HOME') : $homeText; $pathway .= " <a href='index.php'>" . $homeText . '</a> '; } // get the root category JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $root = JTable::getInstance('Categories', 'CitruscartTable')->getRoot(); $root_itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($root->category_id, true); $catRoot = $this->params->get('showcatroot', '1'); if ($catRoot && $catid != $root->category_id) { $pathway .= $this->getSeparator(); $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $root->category_id . "&Itemid=" . $root_itemid, false); $rootText = $this->params->get('roottext'); $rootText = empty($rootText) ? JText::_('COM_CITRUSCART_ALL_CATEGORIES') : $rootText; $pathway .= " <a href='{$link}'>" . $rootText . '</a> '; } $table = JTable::getInstance('Categories', 'CitruscartTable'); $table->load($catid); if (empty($table->category_id)) { return $pathway; } $path = $table->getPath(); foreach ($path as $cat) { if (!$cat->isroot) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($cat->category_id, true))) { $itemid = $root_itemid; } $slug = $cat->category_alias ? ":{$cat->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $cat->category_id . $slug . "&Itemid=" . $itemid, false); if (!empty($pathway)) { $pathway .= $this->getSeparator(); } $pathway .= " <a href='{$link}'>" . JText::_($cat->category_name) . '</a> '; } } if (!empty($pathway)) { $pathway .= $this->getSeparator(); } if ($linkSelf = $this->params->get('linkself')) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($table->category_id, true))) { $itemid = $root_itemid; } $slug = $table->category_alias ? ":{$table->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $table->category_id . $slug . "&Itemid=" . $itemid, false); $pathway .= " <a href='{$link}'>" . JText::_($table->category_name) . '</a> '; } else { $pathway .= JText::_($table->category_name); } return $pathway; }
/** * * @param unknown_type $updateNulls * @return unknown_type */ function store($updateNulls = false) { if ($return = parent::store($updateNulls)) { if ($this->notify_customer == '1') { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelSubscriptions", "models.subscriptions"); $model->setId($this->subscription_id); $subscription = $model->getItem(); $helper->sendEmailNotices($subscription, 'subscription'); } } return $return; }
/** * * @param unknown_type $updateNulls * @return unknown_type */ function store($updateNulls = false) { if ($return = parent::store($updateNulls)) { if ($this->notify_customer == '1') { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $model->setId($this->order_id); // this isn't necessary because you specify the requested PK id as a getItem() argument $order = $model->getItem($this->order_id, true); $helper->sendEmailNotices($order, 'order'); } } return $return; }
function set() { $currency_id = JRequest::getVar('currency_id', 0); if ($currency_id) { $helper = Citruscart::getClass('CitruscartHelperBase', 'helpers._base'); $helper->setSessionVariable('currency_id', $currency_id); } $return = JRequest::getVar('return', ''); if ($return) { $url = base64_decode($return); } else { $url = 'index.php?option=com_citruscart&view=products'; } $this->setRedirect(JRoute::_($url)); $this->redirect(); return; }
/** * Processes a new order * * @param $order_id * @return unknown_type */ public function processStringForOrder($order_id, &$string) { // get the order $model = JModelLegacy::getInstance('Orders', 'CitruscartModel'); $model->setId($order_id); $order = $model->getItem(); $this->_orderFromModel = $order; $orderTable = $model->getTable(); $orderTable->load($order_id); $this->_order = $orderTable; $this->_date = JFactory::getDate(); if ($order->user_id < Citruscart::getGuestIdStart()) { $this->_user = $order->user_id; } else { $this->_user = JFactory::getUser($order->user_id); } $this->products_model = Citruscart::getClass('CitruscartModelProducts', 'models.products'); return $this->processString($string); }
/** * Displays search results * * (non-PHPdoc) * @see Citruscart/admin/CitruscartController#display($cachable) */ function display($cachable = false, $urlparams = false) { $input = JFactory::getApplication()->input; $input->set('view', $this->get('suffix')); $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType()); $model = $this->getModel($this->get('suffix')); $this->_setModelState(); if ($items = $model->getList()) { foreach ($items as $row) { $row->category_id = 0; $categories = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getCategories($row->product_id); if (!empty($categories)) { $row->category_id = $categories[0]; } $itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->product($row->product_id, $row->category_id, true); $row->itemid = empty($itemid) ? $input->getInt('Itemid') : $itemid; } } parent::display($cachable, $urlparams); }
/** * 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'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $user = JFactory::getUser(); // get the model $model = JModelLegacy::getInstance('OrderItems', 'CitruscartModel'); $model->setState('limit', $this->params->get('max_number', '5')); $model->setState('filter_userid', $user->id); $model->setState('order', 'created_date'); $model->setState('direction', 'DESC'); $query = $model->getQuery(); $query->select("MAX(o.order_id) AS order_id"); $query->select("MAX(o.created_date) AS created_date"); if ($this->params->get('display_downloads_only')) { $query->join('LEFT', '#__citruscart_productfiles AS files ON tbl.product_id = files.product_id'); $query->where("files.productfile_id IS NOT NULL"); } $query->group('tbl.product_id'); $model->setQuery($query); $router = Citruscart::getClass('CitruscartHelperRoute', 'helpers.route'); $product = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product'); if ($items = $model->getList()) { foreach ($items as $item) { $category = null; if ($categories = $product->getCategories($item->product_id)) { $category = $categories[0]; } $item->link = $router->product($item->product_id, $category); } } return $items; }
/** * Returns an array of user objects * of all users who should receive this email * * @param $data Object * @return array */ private function getEmailRecipients($id, $type = 'order') { $recipients = array(); switch ($type) { case 'subscription_expiring': case 'subscription_expired': case 'subscription_new': case 'new_subscription': case 'subscription': $model = Citruscart::getClass('CitruscartModelSubscriptions', 'models.subscriptions'); $model->setId($id); $subscription = $model->getItem(); $model_order = Citruscart::getClass('CitruscartModelOrders', 'models.orders'); $model_order->setId($subscription->order_id); $order = $model_order->getItem(); if ($subscription->user_id > 0) { $user = JUser::getInstance($subscription->user_id); // string needle NOT found in haystack if (!in_array($user->email, $recipients) && JMailHelper::isEmailAddress($user->email)) { $recipients[] = $user->email; } } else { // add the userinfo email to the list of recipients if (!in_array($order->userinfo_email, $recipients) && JMailHelper::isEmailAddress($order->userinfo_email)) { $recipients[] = $order->userinfo_email; } } // add the order user_email to the list of recipients if (!in_array($order->user_email, $recipients) && JMailHelper::isEmailAddress($order->user_email)) { $recipients[] = $order->user_email; } break; case "new_order": $system_recipients = $this->getSystemEmailRecipients(); foreach ($system_recipients as $r) { if (!in_array($r->email, $recipients)) { $recipients[] = $r->email; } } $additional_recipients = $this->getAdditionalEmailRecipients(); foreach ($additional_recipients as $r) { if (!in_array($r, $recipients)) { $recipients[] = $r; } } $model = Citruscart::getClass('CitruscartModelOrders', 'models.orders'); $model->setId($id); $order = $model->getItem(); jimport('joomla.mail.helper'); // add the userinfo user_email to the list of recipients if (!in_array($order->userinfo_email, $recipients) && JMailHelper::isEmailAddress($order->userinfo_email)) { $recipients[] = $order->userinfo_email; } // add the order user_email to the list of recipients if (!in_array($order->user_email, $recipients) && JMailHelper::isEmailAddress($order->user_email)) { $recipients[] = $order->user_email; } case 'order': default: $model = Citruscart::getClass('CitruscartModelOrders', 'models.orders'); $model->setId($id); $order = $model->getItem(); if ($order->user_id > 0) { $user = JUser::getInstance($order->user_id); // string needle NOT found in haystack if (!in_array($user->email, $recipients)) { $recipients[] = $user->email; } } else { // add the userinfo email to the list of recipients if (!in_array($order->userinfo_email, $recipients) && JMailHelper::isEmailAddress($order->userinfo_email)) { $recipients[] = $order->userinfo_email; } } // add the order user_email to the list of recipients if (!in_array($order->user_email, $recipients) && JMailHelper::isEmailAddress($order->user_email)) { $recipients[] = $order->user_email; } break; } // allow plugins to modify the order email recipient list JFactory::getApplication()->triggerEvent('onGetEmailRecipients', array($id, $type, &$recipients)); return $recipients; }
/** * 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 */ 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; }
<?php /*------------------------------------------------------------------------ # com_citruscart # ------------------------------------------------------------------------ # author Citruscart Team - Citruscart http://www.citruscart.com # copyright Copyright (C) 2014 Citruscart.com All Rights Reserved. # license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://citruscart.com # Technical Support: Forum - http://citruscart.com/forum/index.html -------------------------------------------------------------------------*/ /** ensure this file is being included by a parent file */ defined('_JEXEC') or die('Restricted access'); JHtml::_('script', 'media/citruscart/js/citruscart.js', false, false); $items = $this->product_relations_data->items; $products_model = Citruscart::getClass('CitruscartModelProducts', 'models.products'); ?> <div id="product_relations"> <h4><?php echo JText::_('COM_CITRUSCART_YOU_MAY_ALSO_BE_INTERESTED_IN'); ?> </h4> <?php $k = 0; ?> <ul class="citruscart_products_containers"> <?php foreach ($items as $item) { ?> <li class="citruscart_product_relation_lists">
/*------------------------------------------------------------------------ # com_citruscart # ------------------------------------------------------------------------ # author Citruscart Team - Citruscart http://www.citruscart.com # copyright Copyright (C) 2014 Citruscart.com All Rights Reserved. # license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://citruscart.com # Technical Support: Forum - http://citruscart.com/forum/index.html -------------------------------------------------------------------------*/ /** ensure this file is being included by a parent file */ defined('_JEXEC') or die('Restricted access'); $form = $this->form; $row = $this->row; JFilterOutput::objectHTMLSafe($row); $histories = Citruscart::getClass('CitruscartHelperSubscription', 'helpers.subscription')->getHistory($row->subscription_id); Citruscart::load('CitruscartGrid', 'library.grid'); $menu = CitruscartMenu::getInstance(); ?> <div class='componentheading'> <span><?php echo JText::_('COM_CITRUSCART_SUBSCRIPTION_DETAILS'); ?> </span> </div> <?php if ($menu) { $menu->display(); }
<th class="subcategory_name" style="background-color: #DDDDDD;"> <?php echo $this->cat->category_name; ?> </th> <th class="subcategory_price" style="background-color: #DDDDDD;"> <?php echo JText::_('COM_CITRUSCART_PRICE'); ?> </th> </tr> </thead> <tbody> <?php foreach ($items as $item) { $itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($this->cat->category_id, true); $item->itemid = !empty($itemid) ? $itemid : $app->input->getInt('Itemid', $itemid); ?> <tr> <td> <a href="<?php echo JRoute::_($item->link . "&filter_category=" . $this->cat->category_id . "&Itemid=" . $item->itemid); ?> "> <?php echo $item->product_name; ?> </a> </td> <td class="subcategory_price"> <?php
/** * Gets the order items * * @return array of TableOrderItems objects */ function getItems() { // TODO once all references use this getter, we can do fun things with this method, such as fire a plugin event JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); // if empty($items) && !empty($this->order_id), then this is an order from the db, // so we grab all the orderitems from the db if (empty($this->_items) && !empty($this->order_id)) { // TODO Do this? How will this impact Site::CitruscartControllerCheckout->saveOrderItems()? //retrieve the order's items $model = JModelLegacy::getInstance('OrderItems', 'CitruscartModel'); $model->setState('filter_orderid', $this->order_id); $model->setState('order', 'tbl.orderitem_name'); $model->setState('direction', 'ASC'); $orderitems = $model->getList(); foreach ($orderitems as $orderitem) { unset($table); $table = JTable::getInstance('OrderItems', 'CitruscartTable'); $table->load($orderitem->orderitem_id); $this->addItem($table); } } $items = $this->_items; if (!is_array($items)) { $items = array(); } if (empty($this->_itemschecked)) { // ensure that the items array only has one recurring item in it foreach ($items as $key => $item) { $shipping = Citruscart::getClass("CitruscartHelperProduct", 'helpers.product')->isShippingEnabled($item->product_id); if ($shipping) { $this->order_ships = '1'; } if (empty($this->_recurringItemExists) && $item->orderitem_recurs) { // Only one recurring item allowed per order. // If the item is recurring, // check if there already is a recurring item accounted for in the order // if so, remove this one from the order but leave it in the cart and continue // if not, add its properties $this->_recurringItemExists = true; $this->_recurringItem = $item; $this->recurring_payments = $item->recurring_payments; $this->recurring_period_interval = $item->recurring_period_interval; $this->recurring_period_unit = $item->recurring_period_unit; $this->recurring_trial = $item->recurring_trial; $this->recurring_trial_period_interval = $item->recurring_trial_period_interval; $this->recurring_trial_period_unit = $item->recurring_trial_period_unit; $this->recurring_trial_price = $item->recurring_trial_price; $this->recurring_amount = $item->recurring_price; // TODO Add tax? //$this->recurring_amount = $item->recurring_amount; // TODO Add tax? // TODO Set some kind of _recurring_item property, so it is easy to get the recurring item later? } elseif (!empty($this->_recurringItemExists) && $item->orderitem_recurs) { // Only one recurring item allowed per order. // If the item is recurring, // check if there already is a recurring item accounted for in the order // if so, remove this one from the order but leave it in the cart and continue unset($items[$key]); } } $this->_itemschecked = true; } $this->_items = $items; return $this->_items; }
$js .= "com_citruscart.jbase = '" . Citruscart::getUriRoot() . "';\n"; $doc->addScriptDeclaration($js); JHtml::_('script', 'media/citruscart/js/common.js', false, false); require_once JPATH_SITE . '/libraries/dioscouri/loader.php'; $parentPath = JPATH_ADMINISTRATOR . '/components/com_citruscart/helpers'; DSCLoader::discover('CitruscartHelper', $parentPath, true); $parentPath = JPATH_ADMINISTRATOR . '/components/com_citruscart/library'; DSCLoader::discover('Citruscart', $parentPath, true); $parentPath = JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'; DSCLoader::discover('CitruscartTable', $parentPath, true); // load the plugins JPluginHelper::importPlugin('citruscart'); // Check Json Class Existance if (!function_exists('json_decode')) { // This should load not only the class, but also json_encode / json_decode Citruscart::load('Services_JSON', 'library.json'); } // Create the controller $classname = 'CitruscartController' . $controller; $controller = Citruscart::getClass($classname); // ensure a valid task exists //$task = JRequest::getVar('task'); $task = $app->input->getString('task'); if (empty($task)) { $task = 'display'; } $app->input->set('task', $task); // Perform the requested task $controller->execute($task); // Redirect if set by the controller $controller->redirect();
/** * Migrate the images * * param int $product_id * param string $images */ private function _migrateImages($product_id, $images) { Citruscart::load('CitruscartImage', 'library.image'); foreach ($images->children() as $image) { $check = false; $multiple = false; $image = (string) $image; if (JURI::isInternal($image)) { $internal = true; $int_image = JPATH_SITE . DIRECTORY_SEPARATOR . $image; if (is_dir($int_image)) { $check = JFolder::exists($int_image); $multiple = true; } else { $check = JFile::exists($int_image); } // Now check the extracted images path if (!$check) { $dir = $this->_temp_dir . DIRECTORY_SEPARATOR . 'images' . DS; if (is_dir($dir . $image)) { $check = JFolder::exists($dir . $image); $multiple = true; } else { $check = JFile::exists($dir . $image); } if ($check) { $image = $dir . $image; } } else { $image = $int_image; } } else { $internal = false; $check = $this->url_exists($image); } // Add a single image if (!$multiple) { $images_to_copy = array($image); } else { // Fetch the images from the folder and add them $images_to_copy = Citruscart::getClass("CitruscartHelperProduct", 'helpers.product')->getGalleryImages($image); foreach ($images_to_copy as &$i) { $i = $image . DIRECTORY_SEPARATOR . $i; } } if ($check) { foreach ($images_to_copy as $image_to_copy) { if ($internal) { $img = new CitruscartImage($image_to_copy); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($image_to_copy, 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy, 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy); } Citruscart::load('CitruscartTableProducts', 'tables.products'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); $path = $product->getImagePath(); $type = $img->getExtension(); $img->load(); $img->setDirectory($path); // Save full Image $img->save($path . $img->getPhysicalName()); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); $imgHelper->resizeImage($img, 'product'); } } } }
/** * Verifies the fields in a submitted form. * Then adds the item to the users cart * * @return unknown_type */ function addChildrenToCart() { $input = JFactory::getApplication()->input; JSession::checkToken() or jexit('Invalid Token'); $product_id = $input->getInt('product_id'); $quantities = $input->get('quantities', array(0), 'request', 'array'); $filter_category = $input->getInt('filter_category'); Citruscart::load("CitruscartHelperRoute", 'helpers.route'); $router = new CitruscartHelperRoute(); if (!($itemid = $router->product($product_id, $filter_category, true))) { $itemid = $router->category(1, true); } // set the default redirect URL $redirect = "index.php?option=com_citruscart&view=products&task=view&id=" . $product_id . "&filter_category=" . $filter_category . "&Itemid=" . $itemid; $redirect = JRoute::_($redirect, false); Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); if (!Citruscart::getInstance()->get('shop_enabled', '1')) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_SHOP_DISABLED'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } $items = array(); // this will collect the items to add to the cart // convert elements to array that can be binded $values = $input->getArray($_POST); $attributes_csv = ''; $user = JFactory::getUser(); $cart_id = $user->id; $id_type = "user_id"; if (empty($user->id)) { $session = JFactory::getSession(); $cart_id = $session->getId(); $id_type = "session"; } Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $carthelper = new CitruscartHelperCarts(); $cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type); // TODO get the children // loop thru each child, // get the list JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel'); $model->setState('filter_product', $product_id); $model->setState('filter_relation', 'parent'); if ($children = $model->getList()) { foreach ($children as $child) { $product_qty = $quantities[$child->product_id_to]; // 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($child->product_id_to, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $this->messagetype = 'notice'; $this->message = JText::_(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $product_qty)); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // do the item's charges recur? does the cart already have a subscription in it? if so, fail with notice $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load(array('product_id' => $child->product_id_to)); // if product notforsale, fail if ($product->product_notforsale) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_PRODUCT_NOT_FOR_SALE'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } if ($product->product_recurs && $cart_recurs) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_CART_ALREADY_RECURS'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } if ($product->product_recurs) { $product_qty = '1'; } // create cart object out of item properties $item = new JObject(); $item->user_id = JFactory::getUser()->id; $item->product_id = (int) $child->product_id_to; $item->product_qty = (int) $product_qty; $item->product_attributes = $attributes_csv; $item->vendor_id = '0'; // vendors only in enterprise version // does the user/cart match all dependencies? $canAddToCart = $carthelper->canAddItem($item, $cart_id, $id_type); if (!$canAddToCart) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_CANNOT_ADD_ITEM_TO_CART') . " - " . $carthelper->getError(); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // no matter what, fire this validation plugin event for plugins that extend the checkout workflow $results = array(); $results = JFactory::getApplication()->triggerEvent("onBeforeAddToCart", array($item, $values)); for ($i = 0; $i < count($results); $i++) { $result = $results[$i]; if (!empty($result->error)) { $this->messagetype = 'notice'; $this->message = $result->message; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } } // if here, add to cart $items[] = $item; } } if (!empty($items)) { Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); foreach ($items as $item) { // add the item to the cart $cart_helper = new CitruscartHelperCarts(); $cartitem = $cart_helper->addItem($item); // fire plugin event JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($cartitem, $values)); } $this->messagetype = 'message'; $this->message = JText::_('COM_CITRUSCART_ITEMS_ADDED_TO_YOUR_CART'); } // After login, session_id is changed by Joomla, so store this for reference $session = JFactory::getSession(); $session->set('old_sessionid', $session->getId()); // get the 'success' redirect url // TODO Enable redirect via base64_encoded urls? switch (Citruscart::getInstance()->get('addtocartaction', 'redirect')) { case "redirect": $returnUrl = base64_encode($redirect); $itemid = $router->findItemid(array('view' => 'checkout')); $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $itemid, false); if (strpos($redirect, '?') === false) { $redirect .= "?return=" . $returnUrl; } else { $redirect .= "&return=" . $returnUrl; } break; case "0": case "none": break; case "lightbox": default: // TODO Figure out how to get the lightbox to display even after a redirect break; } $this->setRedirect($redirect, $this->message, $this->messagetype); return; }
/** * * @return unknown_type */ function update() { $input = JFactory::getApplication()->input; $model = $this->getModel(strtolower(CitruscartHelperCarts::getSuffix())); $this->_setModelState(); $user = JFactory::getUser(); $session = JFactory::getSession(); $cids = $input->get('cid', array(0), '', 'ARRAY'); $product_attributes = $input->get('product_attributes', array(0), '', 'ARRAY'); $quantities = $input->get('quantities', array(0), '', 'ARRAY'); $post = $input->getArray($_POST); $msg = JText::_('COM_CITRUSCART_QUANTITIES_UPDATED'); $remove = $input->getString('remove'); if ($remove) { foreach ($cids as $cart_id => $product_id) { $row = $model->getTable(); //main cartitem keys $ids = array('user_id' => $user->id, 'cart_id' => $cart_id); if (empty($user->id)) { $ids['session_id'] = $session->getId(); } if ($return = $row->delete(array('cart_id' => $cart_id))) { $item = new JObject(); $item->product_id = $product_id; $item->product_attributes = $product_attributes[$cart_id]; $item->vendor_id = '0'; // vendors only in enterprise version $item->cart_id = $cart_id; // fire plugin event JFactory::getApplication()->triggerEvent('onRemoveFromCart', array($item)); } } } else { foreach ($quantities as $cart_id => $value) { $carts = JTable::getInstance('Carts', 'CitruscartTable'); $carts->load(array('cart_id' => $cart_id)); $product_id = $carts->product_id; $value = (int) $value; // $keynames = explode('.', $key); // $product_id = $keynames[0]; // $attributekey = $product_id.'.'.$keynames[1]; // $index = $keynames[2]; $vals = array(); $vals['user_id'] = $user->id; $vals['session_id'] = $session->getId(); $vals['product_id'] = $product_id; // fire plugin event: onGetAdditionalCartKeyValues //this event allows plugins to extend the multiple-column primary key of the carts table // $additionalKeyValues = CitruscartHelperCarts::getAdditionalKeyValues( null, $post, $index ); // if (!empty($additionalKeyValues)) // { // $vals = array_merge($vals, $additionalKeyValues); // } // using a helper file,To determine the product's information related to inventory $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $product_attributes[$cart_id]); if ($availableQuantity->product_check_inventory && $value > $availableQuantity->quantity) { JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $value)); $msg = JText::_('COM_CITRUSCART_QUANTITY_UPDATE_FAILED'); continue; } if ($value > 1) { $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load(array('product_id' => $product_id)); if ($product->quantity_restriction) { $min = $product->quantity_min; $max = $product->quantity_max; if ($max) { if ($value > $max) { $msg = JText::_('COM_CITRUSCART_REACHED_MAXIMUM_QUANTITY_FOR_THIS_OBJECT') . $max; $value = $max; } } if ($min) { if ($value < $min) { $msg = JText::_('COM_CITRUSCART_REACHED_MAXIMUM_QUANTITY_FOR_THIS_OBJECT') . $min; $value = $min; } } $remainder = 0; if (!empty($product->quantity_step)) { $remainder = $value % $product->quantity_step; } if (!empty($product->quantity_step) && !empty($remainder)) { $msg = JText::sprintf('COM_CITRUSCART_QUANTITY_MUST_BE_IN_INCREMENTS_OF', $product->quantity_step); $value = $value - $remainder > 0 ? $value - $remainder : $min; } } if ($product->product_recurs) { $value = 1; } } $row = $model->getTable(); $vals['product_attributes'] = $product_attributes[$cart_id]; $vals['product_qty'] = $value; if (empty($vals['product_qty']) || $vals['product_qty'] < 1) { // remove it if ($return = $row->delete($cart_id)) { $item = new JObject(); $item->product_id = $product_id; $item->product_attributes = $product_attributes[$cart_id]; $item->vendor_id = '0'; // vendors only in enterprise version // fire plugin event JFactory::getApplication()->triggerEvent('onRemoveFromCart', array($item)); } } else { $row->load($cart_id); $row->product_qty = $vals['product_qty']; $row->save(); } } } $carthelper = new CitruscartHelperCarts(); $carthelper->fixQuantities(); if (empty($user->id)) { $carthelper->checkIntegrity($session->getId(), 'session_id'); } else { $carthelper->checkIntegrity($user->id); } Citruscart::load("CitruscartHelperRoute", 'helpers.route'); $router = new CitruscartHelperRoute(); $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false); $this->setRedirect($redirect, $msg); }
/** * * Enter description here ... * @param $data * @return unknown_type */ public function _processSubscriptionPayment($data) { // if we're here, a successful payment has been made. // the normal notice that requires action. // create a subscription_id if no subscr_id record exists // set expiration dates // add a sub history entry, email the user? $errors = array(); // Check that custom (orderpayment_id) is present, we need it for payment amount verification if (empty($data['custom'])) { $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID')); return false; } // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'CitruscartTable'); $orderpayment->load($data['custom']); if (empty($data['custom']) || empty($orderpayment->orderpayment_id)) { $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID')); return false; } $orderpayment->transaction_details = $data['transaction_details']; $orderpayment->transaction_id = $data['txn_id']; $orderpayment->transaction_status = $data['payment_status']; if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $order = JTable::getInstance('Orders', 'CitruscartTable'); $order->load($data['item_number']); $items = $order->getItems(); // Update orderitem_status $order_item = $order->getRecurringItem(); $orderitem = JTable::getInstance('OrderItems', 'CitruscartTable'); $orderitem->orderitem_id = $order_item->orderitem_id; $orderitem->orderitem_status = '1'; $orderitem->save(); // TODO Here we need to verify the payment amount // if no subscription exists for this subscr_id, // create new subscription for the user $subscription = JTable::getInstance('Subscriptions', 'CitruscartTable'); $subscription->load(array('transaction_id' => $data['subscr_id'])); if (empty($subscription->subscription_id)) { $date = JFactory::getDate(); // create new subscription // if recurring trial, set it // for the order's recurring_trial_period_interval // using its recurring_trial_period_unit // otherwise, do the normal recurring_period_interval // and the recurring_period_unit $recurring_period_unit = $order->recurring_period_unit; $recurring_period_interval = $order->recurring_period_interval; if (!empty($order->recurring_trial)) { $recurring_period_unit = $order->recurring_trial_period_unit; $recurring_period_interval = $order->recurring_trial_period_interval; } $subscription->user_id = $order->user_id; $subscription->order_id = $order->order_id; $subscription->product_id = $orderitem->product_id; $subscription->orderitem_id = $orderitem->orderitem_id; $subscription->transaction_id = $data['subscr_id']; $subscription->created_datetime = $date->toSql(); $subscription->subscription_enabled = '1'; switch ($recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $query = " SELECT DATE_ADD('{$subscription->created_datetime}', INTERVAL {$recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'CitruscartTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'creation'; $subscriptionhistory->created_datetime = $date->toSql(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION CREATED'); $subscriptionhistory->save(); } else { // subscription exists, just update its expiration date // based on normal interval and period switch ($order->recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $today = $date = JFactory::getDate(); $query = " SELECT DATE_ADD('{$today}', INTERVAL {$order->recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'CitruscartTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'payment'; $subscriptionhistory->created_datetime = $date->toSql(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION PAYMENT RECEIVED'); $subscriptionhistory->save(); } if (count($items) == '1') { // update order status Citruscart::load('CitruscartHelperOrder', 'helpers.order'); Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; // save the order if (!$order->save()) { $errors[] = $order->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } } $error = count($errors) ? implode("\n", $errors) : ''; if (!empty($error)) { $this->setError($error); return false; } return true; }
/** * 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; }
/** * Returns a formatted path for the category * @param $id * @param $format * @return unknown_type */ public static function getPathName($id, $format = 'flat', $linkSelf = false) { $name = ''; if (empty($id)) { return $name; } if (isset($this) && is_a($this, 'CitruscartHelperCategory')) { $helper = $this; } else { $helper = CitruscartHelperBase::getInstance('Category'); } if (empty($helper->categories[$id])) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $helper->categories[$id] = JTable::getInstance('Categories', 'CitruscartTable'); $helper->categories[$id]->load($id); } $item = $helper->categories[$id]; if (empty($item->category_id)) { return $name; } $path = $item->getPath(); switch ($format) { case "array": $name = array(); foreach ($path as $cat) { $include_root = Citruscart::getInstance()->get('include_root_pathway', false); if (!$cat->isroot || $include_root) { $pathway_object = new JObject(); $pathway_object->name = $cat->category_name; $slug = $cat->category_alias ? ":{$cat->category_alias}" : ""; $link = "index.php?option=com_citruscart&view=products&filter_category=" . $cat->category_id . $slug; $pathway_object->link = $link; $pathway_object->id = $cat->category_id; $name[] = $pathway_object; } } // add the item $pathway_object = new JObject(); $pathway_object->name = $item->category_name; $slug = $item->category_alias ? ":{$item->category_alias}" : ""; $link = "index.php?option=com_citruscart&view=products&filter_category=" . $item->category_id . $slug; $pathway_object->link = $link; $pathway_object->id = $item->category_id; $name[] = $pathway_object; break; case "bullet": foreach ($path as $cat) { if (!$cat->isroot) { $name .= '• '; $name .= JText::_($cat->category_name); $name .= "<br/>"; } } $name .= '• '; $name .= JText::_($item->category_name); break; case 'links': // get the root category JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $root = JTable::getInstance('Categories', 'CitruscartTable')->getRoot(); $root_itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($root->category_id, true); $include_root = Citruscart::getInstance()->get('include_root_pathway', false); if ($include_root) { $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $root->category_id . "&Itemid=" . $root_itemid, false); $name .= " <a href='{$link}'>" . JText::_('COM_CITRUSCART_ALL_CATEGORIES') . '</a> '; } foreach ($path as $cat) { if (!$cat->isroot) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($cat->category_id, true))) { $itemid = $root_itemid; } $slug = $cat->category_alias ? ":{$cat->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $cat->category_id . $slug . "&Itemid=" . $itemid, false); if (!empty($name)) { $name .= " > "; } $name .= " <a href='{$link}'>" . JText::_($cat->category_name) . '</a> '; } } if (!empty($name)) { $name .= " > "; } if ($linkSelf) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($item->category_id, true))) { $itemid = $root_itemid; } $slug = $item->category_alias ? ":{$item->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $item->category_id . $slug . "&Itemid=" . $itemid, false); $name .= " <a href='{$link}'>" . JText::_($item->category_name) . '</a> '; } else { $name .= JText::_($item->category_name); } break; default: foreach ($path as $cat) { if (!$cat->isroot) { $name .= " / "; $name .= JText::_($cat->category_name); } } $name .= " / "; $name .= JText::_($item->category_name); break; } return $name; }
</td> </tr> <tr> <td style="width: 100px; text-align: right;" class="key"> <label for="category_full_image"> <?php echo JText::_('COM_CITRUSCART_CURRENT_IMAGE'); ?> : </label> </td> <td> <?php jimport('joomla.filesystem.file'); if (!empty($row->category_full_image) && JFile::exists(Citruscart::getPath('categories_images') . DS . $row->category_full_image)) { echo CitruscartUrl::popup(Citruscart::getClass('CitruscartHelperCategory', 'helpers.category')->getImage($row->category_id, '', '', 'full', true), CitruscartHelperCategory::getImage($row->category_id), array('update' => false, 'img' => true)); } ?> <br /> <input type="text" name="category_full_image" id="category_full_image" size="48" maxlength="250" value="<?php echo $row->category_full_image; ?> " /> </td> </tr> <tr> <td style="width: 100px; text-align: right;" class="key"> <label for="category_full_image_new"> <?php echo JText::_('COM_CITRUSCART_UPLOAD_NEW_IMAGE'); ?>
public function getCategories($id, $refresh = false) { $model = Citruscart::getClass('CitruscartModelProductCategories', 'models.productcategories'); $model->setState('filter_product_id', $id); $result = $model->getList($refresh); return $result; }
/** * Build the route * * @param array An array of URL arguments * @return array The URL arguments to use to assemble the URL */ static function build(&$query) { $segments = array(); $app = JFactory::getApplication(); // get a menu item based on the Itemid or the currently active item // in most versions before v1.0, Citruscart views pass in the current itemid, so this isn't useful yet $menu = $app->getMenu(); if (empty($query['Itemid'])) { $item = $menu->getActive(); $menuItemGiven = false; } else { $item = $menu->getItem($query['Itemid']); $menuItemGiven = true; } $menuView = empty($item->query['view']) ? null : $item->query['view']; $menuTask = empty($item->query['task']) ? null : $item->query['task']; $menuFilterCategory = empty($item->query['filter_category']) ? null : $item->query['filter_category']; $menuId = empty($item->query['id']) ? null : $item->query['id']; $view = empty($query['view']) ? null : $query['view']; $task = empty($query['task']) ? null : $query['task']; $filter_category = empty($query['filter_category']) ? null : $query['filter_category']; $id = empty($query['id']) ? null : $query['id']; //$query['view']='dashboard'; // if the menu item and the query match... if ($menuView == @$query['view'] && $menuTask == @$query['task'] && (int) $menuFilterCategory == (int) @$query['filter_category'] && (int) $menuId == (int) @$query['id']) { // unset all variables and use the menu item's alias set by user unset($query['view']); unset($query['task']); unset($query['filter_category']); unset($query['id']); } // if the filter_category, task, or id are in the menu item, unset them since they don't need to be in the url twice // (they're already implied by virtue of the alias set by the menu item) if ($menuTask == @$query['task']) { unset($query['task']); } if ((int) $menuId == (int) @$query['id']) { unset($query['id']); } if ((int) $menuFilterCategory == (int) @$query['filter_category']) { unset($query['filter_category']); } // If a filter_category is set, make sure we have the category id and the alias if (!empty($query['filter_category']) && strpos($query['filter_category'], ':') === false) { $cmodel = Citruscart::getClass('CitruscartModelCategories', 'models.categories'); $alias = $cmodel->getAlias((int) $query['filter_category']); if (!empty($alias)) { $query['filter_category'] = $query['filter_category'] . ':' . $alias; } } if (!empty($query['view']) && $query['view'] == 'products') { // this is either a products list or detail page if (!empty($query['task']) && $query['task'] == 'view') { // this is a product detail page // Make sure we have the product id and the alias if (strpos(@$query['id'], ':') === false) { $pmodel = Citruscart::getClass('CitruscartModelProducts', 'models.products'); $alias = $pmodel->getAlias((int) @$query['id']); if (!empty($alias)) { $query['id'] = $query['id'] . ':' . $alias; } } } else { // this is a product list page } } // otherwise, create the sef url from the query if (!empty($query['view'])) { $view = $query['view']; $segments[] = $view; unset($query['view']); } if (!empty($query['task'])) { $task = $query['task']; $segments[] = $task; unset($query['task']); } if (!empty($query['filter_category'])) { $filter_category = $query['filter_category']; $segments[] = $filter_category; unset($query['filter_category']); } if (!empty($query['id'])) { $id = $query['id']; $segments[] = $id; unset($query['id']); } return $segments; }
/** * Gets an order, formatted for email * * return html */ public static function getOrderHtmlForEmail($order_id) { $app = JFactory::getApplication(); JPluginHelper::importPlugin('citruscart'); JLoader::register("CitruscartViewOrders", JPATH_SITE . "/components/com_citruscart/views/orders/view.html.php"); // tells JView to load the front-end view, and enable template overrides $config = array(); $config['base_path'] = JPATH_SITE . "/components/com_citruscart"; if ($app->isAdmin()) { // finds the default Site template $db = JFactory::getDBO(); if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $db->setQuery("SELECT `template` FROM #__template_styles WHERE `home` = '1' AND `client_id` = '0';"); } else { // Joomla! 1.5 code here $db->setQuery("SELECT `template` FROM #__templates_menu WHERE `menuid` = '0' AND `client_id` = '0';"); } $template = $db->loadResult(); jimport('joomla.filesystem.file'); if (JFile::exists(JPATH_SITE . '/templates/' . $template . '/html/com_citruscart/orders/email.php')) { // (have to do this because we load the same view from the admin-side Orders view, and conflicts arise) $config['template_path'] = JPATH_SITE . '/templates/' . $template . '/html/com_citruscart/orders'; } } $view = new CitruscartViewOrders($config); $model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $model->setId($order_id); $order = $model->getItem(); $view->set('_controller', 'orders'); $view->set('_view', 'orders'); $view->set('_doTask', true); $view->set('hidemenu', false); $view->setModel($model, true); $view->assign('order', $order); $view->setLayout('email'); // Perform the requested task ob_start(); $view->display(); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * This method occurs after payment is attempted, * and fires the onPostPayment plugin event * * return unknown_type */ function confirmPayment() { $input = JFactory::getApplication()->input; $this->current_step = 3; $orderpayment_type = $input->get('orderpayment_type'); // Get post values $values = $input->getArray($_POST); // get the order_id from the session set by the prePayment $mainframe = JFactory::getApplication(); $order_id = (int) $mainframe->getUserState('citruscart.order_id'); $itemid_string = null; if ($itemid = $this->router->findItemid(array('view' => 'orders'))) { $itemid_string = "&Itemid=" . $itemid; } $order_link = 'index.php?option=com_citruscart&view=orders&task=view&id=' . $order_id . $itemid_string; $pos_order = $mainframe->getUserState('citruscart.pos_order'); $order = $this->_order; $order->load(array('order_id' => $order_id)); //redirect to the backend since we are doing pos order if ($pos_order) { // create POS request record JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $pos_tbl = JTable::getInstance("PosRequests", "CitruscartTable"); $pos_tbl->order_id = 0; $pos_tbl->user_id = 0; $pos_tbl->mode = 2; // mode 2 => front-end $pos_tbl->data = base64_encode(json_encode($values)); $pos_tbl->save(); // generate pos_id and time $pos_tbl->save(); // save the final token (with pos_id -> that's why we need to save it twice) // build URL for POS $uri = JURI::getInstance(); $uriA = $input->get('get'); $uriA['view'] = 'pos'; $uriA['task'] = 'display'; $uriA['subtask'] = 'confirmPayment'; $uriA['pos_id'] = $pos_tbl->pos_id; $uriA['pos_token'] = $pos_tbl->token; $uriA['order_id'] = $order_id; $uriA['user_id'] = $order->user_id; $uriA['nextstep'] = 'step5'; $uriA['Itemid'] = null; $pos_link = $uri->buildQuery(array_filter($uriA)); $mainframe->redirect(JURI::root() . 'administrator/index.php?' . $pos_link); } $dispatcher = JDispatcher::getInstance(); $html = ""; if (!empty($order->order_hash)) { $order_link .= '&h=' . $order->order_hash; } if (!empty($order_id) && (double) $order->order_total == (double) '0.00') { $order->order_state_id = '17'; // PAYMENT RECEIVED $order->save(); // send notice of new order Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $order_model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $order_model->setId($order_id); $order_model_item = $order_model->getItem(); $helper->sendEmailNotices($order_model_item, 'new_order'); Citruscart::load('CitruscartHelperOrder', 'helpers.order'); CitruscartHelperOrder::setOrderPaymentReceived($order_id); } else { // get the payment results from the payment plugin $results = JFactory::getApplication()->triggerEvent("onPostPayment", array($orderpayment_type, $values)); // Display whatever comes back from Payment Plugin for the onPrePayment for ($i = 0; $i < count($results); $i++) { $html .= $results[$i]; } // re-load the order in case the payment plugin updated it $order->load(array('order_id' => $order_id)); } // $order_id would be empty on posts back from Paypal, for example if (!empty($order_id)) { // Set display if (!$this->onepage_checkout) { $progress = $this->getProgress(); } $view = $this->getView('checkout', 'html'); $view->setLayout('postpayment'); $view->set('_doTask', true); $view->assign('order_link', $order_link); $view->assign('plugin_html', $html); if (!$this->onepage_checkout) { $view->assign('progress', $progress); } // Get and Set Model $model = $this->getModel('checkout'); $view->setModel($model, true); // get the articles to display after checkout $articles = array(); $article_id = $this->defines->get('article_checkout'); if (!empty($article_id)) { Citruscart::load('CitruscartArticle', 'library.article'); $articles[] = CitruscartArticle::display($article_id); } switch ($order->order_state_id) { case "2": case "3": case "5": case "17": $articles = array_merge($articles, $this->getOrderArticles($order_id)); // Inject <head> code if ($orders_confirmation_header_code = $this->defines->get('orders_confirmation_header_code')) { Citruscart::load('CitruscartHelperHead', 'helpers.head'); $head_helper = new CitruscartHelperHead(); if ($string_to_inject = $head_helper->processStringForOrder($order_id, $orders_confirmation_header_code)) { $head_helper->injectIntoHead($string_to_inject); } } break; case "7": case "8": case "9": case "10": case "14": $article_id = $this->defines->get('article_default_payment_failure'); Citruscart::load('CitruscartArticle', 'library.article'); $articles = array(CitruscartArticle::display($article_id)); break; } $view->assign('articles', $articles); ob_start(); JFactory::getApplication()->triggerEvent('onBeforeDisplayPostPayment', array($order_id)); $view->assign('onBeforeDisplayPostPayment', ob_get_contents()); ob_end_clean(); ob_start(); JFactory::getApplication()->triggerEvent('onAfterDisplayPostPayment', array($order_id)); $view->assign('onAfterDisplayPostPayment', ob_get_contents()); ob_end_clean(); $view->display(); } // set up user_id for cart items for guest account if ($order->user_id < Citruscart::getGuestIdStart()) { Citruscart::load('CitruscartHelperCarts', 'helpers.cart'); $session = JFactory::getSession(); $helper = new CitruscartHelperCarts(); $helper->mergeSessionCartWithUserCart($session->getId(), $order->user_id); } return; }
<a href="<?php echo $item->link; ?> "> <?php #TODO use dash or hypen instead of dot //echo str_repeat( '_',$item->level -1 ).JText::_($item->name); ?> <?php echo str_repeat('. ', $item->level - 1) . JText::_($item->name); ?> </a> <br/> <?php $layout = Citruscart::getClass('CitruscartHelperCategory', 'helpers.category')->getLayout($item->category_id); if ($layout != 'default') { echo "<b>" . JText::_('COM_CITRUSCART_LAYOUT_OVERRIDE') . "</b>: " . $layout; } ?> </td> <td style="text-align: center;"> <?php Citruscart::load('CitruscartUrl', 'library.url'); ?> <label class="label label-warning"><?php echo $item->products_count . " " . JText::_('COM_CITRUSCART_PRODUCTS'); ?> </label> <br/> <?php