Пример #1
0
 /**
  *
  * @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');
     // get the model
     Citruscart::load('CitruscartModelCategories', 'models.categories');
     $model = new CitruscartModelCategories(array());
     // $model = JModelLegacy::getInstance( 'Categories', 'CitruscartModel' ); doesnt work sometimes without no apparent reason
     // 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.lft');
     // set the states based on the parameters
     // using the set filters, get a list
     $items = $model->getList();
     if (!empty($items)) {
         foreach ($items as $item) {
             Citruscart::load('CitruscartHelperRoute', 'helpers.route');
             $item->itemid = CitruscartHelperRoute::category($item->category_id, true);
             if (empty($item->itemid)) {
                 $item->itemid = $this->params->get('itemid');
             }
         }
     }
     return $items;
 }
Пример #2
0
# 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
# Fork of Tienda
# @license GNU/GPL  Based on Tienda by Dioscouri Design http://www.dioscouri.com.
-------------------------------------------------------------------------*/
/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
JHTML::_('stylesheet', 'menu.css', 'media/citruscart/css/');
JHtml::_('script', 'media/citruscart/js/citruscart.js', false, false);
JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
Citruscart::load('CitruscartGrid', 'library.grid');
$items = $this->items;
$state = $this->state;
Citruscart::load("CitruscartHelperRoute", 'helpers.route');
$router = new CitruscartHelperRoute();
Citruscart::load('CitruscartHelperProduct', 'helpers.product');
$menu = CitruscartMenu::getInstance($this->submenu);
$products_model = $this->getModel('products');
?>

<script type="text/javascript">
citruscartJQ(document).ready(function(){
	DisplaySharingOptions( <?php 
echo $this->row->privacy;
?>
, 0 );

    citruscartJQ('.privatize-wishlist').on('change', function(){
        el = citruscartJQ(this);
        privacy = el.val();
Пример #3
0
 /**
  * (non-PHPdoc)
  *
  * see citruscart/site/CitruscartController#view()
  */
 function display($cachable = false, $urlparams = false)
 {
     $app = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $user = $this->user;
     $input->set('view', $this->get('suffix'));
     //check if we have one page checkout
     if ($this->onepage_checkout) {
         if (!$user->id) {
             $session = JFactory::getSession();
             $session->set('old_sessionid', $session->getId());
         }
         // Display the onepage checkout view
         $opc_layout = $this->defines->get('one_page_checkout_layout', 'onepage-opc');
         $input->set('layout', $opc_layout);
         $view = $this->getView($this->get('suffix'), 'html');
         $order = $this->_order;
         $order = $this->populateOrder();
         //get order summarry
         $html = $this->getOrderSummary();
         $view->assign('orderSummary', $html);
         $view->assign('order', $order);
         $view->setTask(true);
         $view->assign('user', $user);
         if (!$user->id) {
             $view->form_user_register = $this->getAdditionalInfoUser();
         }
         //get addresses
         JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
         $model = JModelLegacy::getInstance('addresses', 'CitruscartModel');
         $model->setState("filter_userid", $this->user->id);
         $model->setState("filter_deleted", 0);
         $addresses = $model->getList();
         // Checking whether shipping is required
         $showShipping = false;
         $cartsModel = $this->getModel('carts');
         if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
             $showShipping = true;
         }
         $billingAddress = $order->getBillingAddress();
         $billing_address_form = $this->getAddressForm($this->billing_input_prefix, !$user->id);
         $view->assign('billing_address_form', $billing_address_form);
         $view->assign('showShipping', $showShipping);
         $view->assign('billing_address', $billingAddress);
         if ($showShipping) {
             $shippingAddress = $order->getShippingAddress();
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, !$user->id, true);
             $view->assign('shipping_address', $shippingAddress);
             $view->assign('shipping_address_form', $shipping_address_form);
         }
         Citruscart::load('CitruscartHelperPlugin', 'helpers.plugin');
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('citruscart');
         if ($showShipping) {
             $rates = $this->getShippingRates();
             $default_rate = array();
             if (count($rates) == 1) {
                 $default_rate = $rates[0];
             }
             $shipping_layout = "shipping_yes";
             if (empty($shippingAddress)) {
                 $shipping_layout = "shipping_calculate";
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             $view->assign('rates', $rates);
         }
         $view->assign('payment_options_html', $this->getPaymentOptionsHtml());
         $view->assign('order', $order);
         // are there any enabled coupons?
         $coupons_present = false;
         $model = JModelLegacy::getInstance('Coupons', 'CitruscartModel');
         $model->setState('filter_enabled', '1');
         if ($coupons = $model->getList()) {
             $coupons_present = true;
         }
         $view->assign('coupons_present', $coupons_present);
         // assign userinfo for credits
         $userinfo = JTable::getInstance('UserInfo', 'CitruscartTable');
         $userinfo->load(array('user_id' => $this->user->id));
         $userinfo->credits_total = (double) $userinfo->credits_total;
         $view->assign('userinfo', $userinfo);
         $view->assign('addresses', $addresses);
         $dispatcher = JDispatcher::getInstance();
         ob_start();
         $app->triggerEvent('onBeforeDisplaySelectPayment', array($order));
         $view->assign('onBeforeDisplaySelectPayment', ob_get_contents());
         ob_end_clean();
         ob_start();
         $app->triggerEvent('onAfterDisplaySelectPayment', array($order));
         $view->assign('onAfterDisplaySelectPayment', ob_get_contents());
         ob_end_clean();
     } else {
         $guest_var = $input->getInt('guest', '0');
         $guest = false;
         if ($guest_var == '1') {
             $guest = true;
         }
         $register_var = $input->getInt('register', '0');
         $form_register = '';
         $register = false;
         if ($register_var == '1') {
             $register = true;
             $form_register = $this->getRegisterForm();
         }
         // determine layout based on login status
         // Login / Register / Checkout as a guest
         if (empty($user->id) && !($guest || $register)) {
             // Display a form for selecting either to register or to login
             $input->set('layout', 'form');
             Citruscart::load("CitruscartHelperRoute", 'helpers.route');
             $helper = new CitruscartHelperRoute();
             $view = $this->getView('checkout', 'html');
             $checkout_itemid = $helper->findItemid(array('view' => 'checkout'));
             if (empty($checkout_itemid)) {
                 $checkout_itemid = $input->getInt('Itemid');
             }
             $view->assign('checkout_itemid', $checkout_itemid);
             parent::display();
             return;
         }
         if ($guest && $this->defines->get('guest_checkout_enabled') || $register) {
             // Checkout as a Guest
             $order = $this->_order;
             $order = $this->populateOrder(true);
             // now that the order object is set, get the orderSummary html
             $html = $this->getOrderSummary();
             // Get the current step
             $progress = $this->getProgress();
             // get address forms
             $billing_address_form = $this->getAddressForm($this->billing_input_prefix, true);
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, true, true);
             // get all the enabled shipping plugins
             Citruscart::load('CitruscartHelperPlugin', 'helpers.plugin');
             $plugins = CitruscartHelperPlugin::getPluginsWithEvent('onGetShippingPlugins');
             $dispatcher = JDispatcher::getInstance();
             JPluginHelper::importPlugin('citruscart');
             $rates = array();
             if ($plugins) {
                 foreach ($plugins as $plugin) {
                     $results = JFactory::getApplication()->triggerEvent("onGetShippingRates", array($plugin->element, $order));
                     foreach ($results as $result) {
                         if (is_array($result)) {
                             foreach ($result as $r) {
                                 $rates[] = $r;
                             }
                         }
                     }
                     // endforeach results
                 }
                 // endforeach plugins
             }
             // endif plugins
             // now display the entire checkout page
             $view = $this->getView('checkout', 'html');
             $view->set('hidemenu', false);
             $view->assign('order', $order);
             $view->assign('register', $register);
             $view->assign('form_register', $form_register);
             $view->assign('billing_address_form', $billing_address_form);
             $view->assign('shipping_address_form', $shipping_address_form);
             $view->assign('orderSummary', $html);
             $view->assign('progress', $progress);
             //$view->assign( 'default_billing_address', $default_billing_address );
             //$view->assign( 'default_shipping_address', $default_shipping_address );
             $view->assign('rates', $rates);
             // Checking whether shipping is required
             $showShipping = false;
             $shipping_layout = "shipping_no";
             $cartsModel = $this->getModel('carts');
             if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
                 $showShipping = true;
             }
             if ($showShipping) {
                 $shipping_layout = "shipping_yes";
                 if (empty($shippingAddress)) {
                     $shipping_layout = "shipping_calculate";
                 }
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             $input->set('layout', 'guest');
         } else {
             // Already Logged in, a traditional checkout
             $order = $this->_order;
             $order = $this->populateOrder(false);
             // now that the order object is set, get the orderSummary html
             $html = $this->getOrderSummary();
             // Get the current step
             $progress = $this->getProgress();
             $user_id = $this->user->id;
             $addresses = array();
             JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
             $model = JModelLegacy::getInstance('addresses', 'CitruscartModel');
             if (!empty($user_id)) {
                 $model->setState("filter_userid", $user_id);
                 $model->setState("filter_deleted", 0);
                 $addresses = $model->getList();
             }
             $billingAddress = $order->getBillingAddress();
             $shippingAddress = $order->getShippingAddress();
             // get address forms
             $billing_address_form = $this->getAddressForm($this->billing_input_prefix);
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, false, true);
             // get the default shipping and billing addresses, if possible
             $default_billing_address = $this->getAddressHtml($billingAddress->address_id);
             $default_shipping_address = $this->getAddressHtml($shippingAddress->address_id);
             // now display the entire checkout page
             $view = $this->getView('checkout', 'html');
             $view->set('hidemenu', false);
             $view->assign('order', $order);
             $view->assign('addresses', $addresses);
             $view->assign('billing_address', $billingAddress);
             $view->assign('shipping_address', $shippingAddress);
             $view->assign('billing_address_form', $billing_address_form);
             $view->assign('shipping_address_form', $shipping_address_form);
             $view->assign('orderSummary', $html);
             $view->assign('progress', $progress);
             $view->assign('default_billing_address', $default_billing_address);
             $view->assign('default_shipping_address', $default_shipping_address);
             // Check whether shipping is required
             $showShipping = false;
             $shipping_layout = "shipping_no";
             $cartsModel = $this->getModel('carts');
             if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
                 $showShipping = true;
             }
             if ($showShipping) {
                 $shipping_layout = "shipping_yes";
                 if (empty($shippingAddress)) {
                     $shipping_layout = "shipping_calculate";
                 }
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             $input->set('layout', 'default');
         }
         $dispatcher = JDispatcher::getInstance();
         ob_start();
         JFactory::getApplication()->triggerEvent('onBeforeDisplaySelectShipping', array($order));
         $view->assign('onBeforeDisplaySelectShipping', ob_get_contents());
         ob_end_clean();
         ob_start();
         JFactory::getApplication()->triggerEvent('onAfterDisplaySelectShipping', array($order));
         $view->assign('onAfterDisplaySelectShipping', ob_get_contents());
         ob_end_clean();
     }
     $view->setTask(true);
     $view->assign('default_country', $this->default_country);
     $view->assign('default_country_id', $this->default_country_id);
     parent::display();
     return;
 }
Пример #4
0
/**
 * Parse the url segments
 * Is just a wrapper for CitruscartHelperRoute::parse()
 *
 * @param unknown_type $segments
 * @return unknown_type
 */
function CitruscartParseRoute($segments)
{
    return CitruscartHelperRoute::parse($segments);
}
Пример #5
0
?>
</h5>
                 
<ul id="citruscart_manufacturers_mod" class="unstyled nav nav-tab">
<?php 
foreach ($items as $item) {
    ?>
<li class="manufacturerslist level<?php 
    echo $item->manufacturer_id;
    ?>
">
	<!--  TODO  : Need to check whether field name is missing -->
	<!-- <li class="level<?php 
    echo $item->level;
    ?>
"> -->
		<a href="<?php 
    echo CitruscartHelperRoute::manufacturer($item->manufacturer_id);
    ?>
"><?php 
    echo $item->manufacturer_name;
    ?>
</a>
	</li>
<?php 
}
?>
</ul>
</div><!-- citruscart manufacturers div ends -->

Пример #6
0
 /**
  * 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';
             }
             if (!$product_qty) {
                 // product quantity is zero -> skip this product
                 continue;
             }
             // 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();
             $dispatcher = JDispatcher::getInstance();
             $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)) {
         // add the items to the cart
         Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
         CitruscartHelperCarts::updateCart($items);
         // fire plugin event
         $dispatcher = JDispatcher::getInstance();
         JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($items, $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;
 }
Пример #7
0
 /**
  * Finds the itemid for the set of variables provided in $needles
  *
  * @param array $needles
  * @return unknown_type
  */
 public static function findItemid($needles = array('view' => 'products', 'task' => '', 'filter_category' => '', 'id' => ''))
 {
     // populate the array of menu items for the extension
     if (empty(self::$itemids)) {
         self::$itemids = array();
         // method=upgrade KILLS all of the useful properties in the __menus table,
         // so we need to do this manually
         // $menus      = JApplication::getMenu('site', array());
         // $component  = JComponentHelper::getComponent('com_citruscart');
         // $items      = $menus->getItems('componentid', $component->id);
         $items = self::getItems();
         if (empty($items)) {
             return null;
         }
         // TODO Move this into the getItems() ?
         foreach ($items as $item) {
             if (!empty($item->query) && !empty($item->query['view'])) {
                 // reconstruct each url query, in case admin has created custom URLs
                 $query = "";
                 $view = $item->query['view'];
                 $query .= "&view={$view}";
                 if (!empty($item->query['task'])) {
                     $task = $item->query['task'];
                     $query .= "&task={$task}";
                 }
                 if (!empty($item->query['filter_category'])) {
                     $filter_category = $item->query['filter_category'];
                     $query .= "&filter_category={$filter_category}";
                 }
                 if (!empty($item->query['id'])) {
                     $id = $item->query['id'];
                     $query .= "&id={$id}";
                 }
                 // set the itemid in the cache array
                 if (empty(self::$itemids[$query])) {
                     self::$itemids[$query] = $item->id;
                 }
             }
         }
     }
     // Make this search the array of self::$itemids, matching with the properties of the $needles array
     // return null if nothing found
     // reconstruct query based on needle
     $query = "";
     if (!empty($needles['view'])) {
         $view = $needles['view'];
         $query .= "&view={$view}";
     }
     if (!empty($needles['task'])) {
         $task = $needles['task'];
         $query .= "&task={$task}";
     }
     if (!empty($needles['filter_category'])) {
         $filter_category = $needles['filter_category'];
         $query .= "&filter_category={$filter_category}";
     }
     if (!empty($needles['id'])) {
         $id = $needles['id'];
         $query .= "&id={$id}";
     }
     // if the query exists in the itemid cache, return it
     if (!empty(self::$itemids[$query])) {
         return self::$itemids[$query];
     }
     return null;
 }
Пример #8
0
 public function getItemid($id, $fallback = null, $allow_null = false)
 {
     $input = JFactory::getApplication()->input;
     Citruscart::load('CitruscartHelperRoute', 'helpers.route');
     $return = CitruscartHelperRoute::findItemid(array('view' => 'products', 'task' => '', 'filter_category' => $id));
     if (!$return) {
         $return = CitruscartHelperRoute::findItemid(array('view' => 'products', 'task' => ''));
         if (!$return) {
             if ($fallback) {
                 $return = $fallback;
             }
             if (!$allow_null) {
                 if (!$return) {
                     $return = $input->getInt('Itemid');
                 }
                 if (!$return) {
                     $menu = JFactory::getApplication()->getMenu();
                     if ($default = $menu->getDefault() && !empty($default->id)) {
                         $return = $default->id;
                     }
                 }
             }
         }
     }
     return $return;
 }
Пример #9
0
 public function addToWishlist()
 {
     $input = JFactory::getApplication()->input;
     $values = array();
     $response = new stdClass();
     $response->html = '';
     $response->error = false;
     Citruscart::load("CitruscartHelperRoute", 'helpers.route');
     $router = new CitruscartHelperRoute();
     // verify form submitted by user
     JSession::checkToken('get') or jexit('Invalid Token');
     $values['product_id'] = $input->getInt('pid');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $product = JTable::getInstance('Products', 'CitruscartTable');
     $product->load($values['product_id'], true, false);
     if (empty($product->product_id)) {
         $msg = JText::_('COM_CITRUSCART_INVALID_PRODUCT');
         $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
         $this->setRedirect($redirect, $msg, 'error');
         return;
     }
     $values['product_attributes'] = $input->getString('pa', '');
     // use the wishlist model to add the item to the wishlist, let the model handle all logic
     $session = JFactory::getSession();
     $session_id = $session->getId();
     $session->set('old_sessionid', $session_id);
     $user_id = JFactory::getUser()->id;
     $values['user_id'] = $user_id;
     $values['session_id'] = $session_id;
     $model = $this->getModel('wishlists');
     $msg = '';
     $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
     $type = 'message';
     if (!$model->addItem($values)) {
         $type = 'error';
         $msg = JText::_('COM_CITRUSCART_COULD_NOT_ADD_TO_WISHLIST');
     } else {
         $url = "index.php?option=com_citruscart&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists'));
         $msg = JText::sprintf('COM_CITRUSCART_ADDED_TO_WISHLIST', JRoute::_($url));
     }
     $this->setRedirect($redirect, $msg, $type);
     return;
 }
Пример #10
0
 /**
  *
  * Enter description here ...
  * @return return_type
  */
 public function shareitems()
 {
     $input = JFactory::getApplication()->input;
     JSession::checkToken() or jexit('Invalid Token');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     // get the email addresses, cutting list off at 10 unique emails
     $addresses = $input->get('share_emails', '');
     $cids = $input->get('cid', array(0), '', 'array');
     // explode them to an array
     $recipients = array();
     if ($nlsv = explode("\n", $addresses)) {
         foreach ($nlsv as $email) {
             $email = trim($email);
             if (!empty($email) && !in_array($email, $recipients)) {
                 $recipients[] = $email;
             }
         }
     }
     Citruscart::load("CitruscartHelperRoute", 'helpers.route');
     $router = new CitruscartHelperRoute();
     $redirect = JRoute::_("index.php?option=com_citruscart&view=wishlists&tmpl=component&task=share&cid[]=" . implode(',', $cids), false);
     // if no emails, fail
     if (empty($recipients)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_CITRUSCART_PLEASE_PROVIDE_EMAIL_RECIPIENTS');
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     // create the list of items to be shared, with name & link to each item's detail page
     $model = $this->getModel($this->get('suffix'));
     $model->setState('filter_ids', $cids);
     $model->setState('filter_privacy', array(1, 2));
     $items = $model->getList(true);
     if (!count($items)) {
         $this->messagetype = 'error';
         $this->message = JText::_('COM_CITRUSCART_CANT_SHARE_PRIVATE_WISHLIST');
         $this->setRedirect(JRoute::_("index.php?option=com_citruscart&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false), $this->message, $this->messagetype);
         return;
     }
     $model_items = $this->getModel('wishlistitems');
     $wishlist_items = array();
     foreach ($items as $wishlist) {
         $model_items->setState('filter_wishlist', $wishlist->wishlist_id);
         $w_items = $model_items->getList(true);
         $wishlist_items = array_merge($wishlist_items, $w_items);
     }
     $share_items_html = '';
     if (!empty($wishlist_items)) {
         Citruscart::load('CitruscartHelperProduct', 'helpers.product');
         $products_model = JModelLegacy::getInstance('Products', 'CitruscartModel');
         $share_items_html .= JText::_('COM_CITRUSCART_WISHLIST_EMAIL_LIST_ITEMS') . '<ul>';
         foreach ($wishlist_items as $item) {
             $item->link = "index.php?option=com_citruscart&view=products&task=view&id=" . $item->product_id;
             $attributes = explode(',', $item->product_attributes);
             $tbl = JTable::getInstance('ProductAttributes', 'CitruscartTable');
             $tbl_opt = JTable::getInstance('ProductAttributeOptions', 'CitruscartTable');
             $product_name = $item->product_name;
             $attr_list = array();
             for ($i = 0, $c = count($attributes); $i < $c; $i++) {
                 $tbl_opt->load($attributes[$i]);
                 $tbl->load($tbl_opt->productattribute_id);
                 $item->link .= '&attribute_' . $tbl_opt->productattribute_id . '=' . $attributes[$i];
                 $attr_list[] = $tbl->productattribute_name . ': ' . $tbl_opt->productattributeoption_name;
             }
             if (count($attr_list)) {
                 $product_name .= ' (' . implode('; ', $attr_list) . ')';
             }
             $item->itemid = $products_model->getItemid($item->product_id);
             if (empty($item->itemid)) {
                 $item->itemid = $router->findItemid(array('view' => 'products', 'filter_category' => '1'));
             }
             $item->link = substr(JURI::base(), 0, -1) . JRoute::_($item->link . "&Itemid=" . $item->itemid);
             $share_items_html .= '<li>';
             $share_items_html .= '<a href="' . $item->link . '">';
             $share_items_html .= $product_name;
             $share_items_html .= '</a>';
             $share_items_html .= '</li>';
         }
         $share_items_html .= '</ul>';
     }
     // set the mailfrom & reply-to
     $mainframe = JFactory::getApplication();
     $sitename = $mainframe->getCfg('sitename');
     $siteurl = JURI::base();
     $user = JFactory::getUser();
     $replyto = $user->email;
     $replytoname = $user->name;
     $mailfrom = $replyto;
     $fromname = $replytoname;
     // create body and subject of email
     $site_email = '<a href="' . $siteurl . '" target="_blank">' . $sitename . '</a>';
     $share_message = $input->get('share_message', '');
     $subject = JText::sprintf("COM_CITRUSCART_SHARE_WISHLIST_EMAIL_SUBJECT", $sitename);
     $body = JText::sprintf("COM_CITRUSCART_SHARE_WISHLIST_EMAIL_BODY", $replytoname, $site_email);
     $body .= JText::sprintf("COM_CITRUSCART_MESSAGE_FROM_SENDER", $share_message);
     $body .= $share_items_html;
     $this->use_html = true;
     // foreach email address, send the email
     $max_recipients = '10';
     $count = count($recipients) > $max_recipients ? $max_recipients : count($recipients);
     for ($i = 0; $i < $count; $i++) {
         $recipient = $recipients[$i];
         if (empty($done[$recipient])) {
             $done[$recipient] = $recipient;
             if ($send = $this->_sendMail($mailfrom, $fromname, $recipient, $subject, $body, null, null, null, null, null, $replyto, $replytoname)) {
                 $success = true;
                 $done[$recipient] = $recipient;
             }
         }
     }
     // redirect to wishlist with message
     $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType());
     $view->set('hidemenu', true);
     $view->set('_doTask', true);
     $view->setModel($model, true);
     $view->assign('only_redirect', true);
     $view->setLayout('share');
     $view->display();
     return;
 }
Пример #11
0
 public function getItemid($id, $fallback = null, $allow_null = false)
 {
     $app = JFactory::getApplication();
     Citruscart::load('CitruscartHelperRoute', 'helpers.route');
     $return = CitruscartHelperRoute::findItemid(array('view' => 'products', 'task' => 'view', 'id' => $id));
     if (!$return) {
         $return = CitruscartHelperRoute::findItemid(array('view' => 'products', 'task' => 'view'));
         if (!$return) {
             $return = CitruscartHelperRoute::findItemid(array('view' => 'products'));
             if (!$return) {
                 if ($fallback) {
                     $return = $fallback;
                 }
                 if (!$allow_null) {
                     if ($categories = $this->getCategories($id)) {
                         $count = count($categories);
                         $cat_model = Citruscart::getClass('CitruscartModelCategories', 'models.categories');
                         for ($i = 0; !$return && $i < $count; $i++) {
                             $category = $categories[$i];
                             if ($cat_itemid = $cat_model->getItemid($category->category_id, null, true)) {
                                 $return = $cat_itemid;
                             }
                         }
                     }
                     if (!$return) {
                         $return = $app->input->getInt('Itemid');
                     }
                     if (!$return) {
                         $menu = $app->getMenu();
                         if ($default = $menu->getDefault() && !empty($default->id)) {
                             $return = $default->id;
                         }
                     }
                 }
             }
         }
     }
     return $return;
 }
Пример #12
0
<?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');
if ($this->only_redirect) {
    Citruscart::load("CitruscartHelperRoute", 'helpers.route');
    $router = new CitruscartHelperRoute();
    ?>
<script type="text/javascript">
	citruscartJQ( function() {
		window.parent.location = '<?php 
    echo JRoute::_("index.php?option=com_citruscart&view=wishlists&email=true&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false);
    ?>
';
		window.close();
	});
</script>
<?php 
} else {
    ?>

	<div id='page-title-navigation'>
Пример #13
0
 /**
  *
  * @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) {
             //            	$keynames = explode('.', $key);
             //            	$attributekey = $keynames[0].'.'.$keynames[1];
             //            	$index = $keynames[2];
             $row = $model->getTable();
             //main cartitem keys
             $ids = array('user_id' => $user->id, 'cart_id' => $cart_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)) {
                 $ids = array_merge($ids, $additionalKeyValues);
             }
             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
                 // 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));
                 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;
                         }
                     }
                 }
                 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);
 }