/** * Method to add/remove the geozone to plugin parameter */ function plugin_switch() { $app = JFactory::getApplication(); $error = false; $this->messagetype = ''; $this->message = ''; $type = $app->input->get('type'); Citruscart::load("CitruscartHelperPlugin", 'helpers.plugin'); $suffix = CitruscartHelperPlugin::getSuffix($type); $id = $app->input->get('id', 0); $cids = $app->input->get('cid', array(0), 'request', 'array'); $task = $app->input->getString('task'); $vals = explode('_', $task); $field = $vals['0']; $action = $vals['1']; switch (strtolower($action)) { case "switch": $switch = '1'; break; case "disable": $enable = '0'; $switch = '0'; break; case "enable": $enable = '1'; $switch = '0'; break; default: $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_INVALID_TASK'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; break; } $model = $this->getModel($suffix); $keynames = array(); foreach ($cids as $cid) { $row = $model->getTable(); if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $keynames["extension_id"] = $cid; } else { // Joomla! 1.5 code here $keynames["id"] = $cid; } $row->load($keynames); $params = new DSCParameter($row->params); $geozones = explode(',', $params->get('geozones')); if ($switch) { if (in_array($id, $geozones)) { $geozones = explode(',', $params->get('geozones')); $geozones = array_diff($geozones, array($id)); } else { $geozones[] = $id; } } else { switch ($enable) { case "1": $geozones[] = $id; break; case "0": default: $geozones = explode(',', $params->get('geozones')); $geozones = array_diff($geozones, array($id)); break; } } $geozones = array_filter($geozones, 'strlen'); //remove empty values $params->set('geozones', implode(',', array_unique($geozones))); //remove duplicate $row->params = trim($params->__toString()); if (!$row->save()) { $this->message .= $cid . ': ' . $row->getError() . '<br/>'; $this->messagetype = 'notice'; $error = true; } } $model->clearCache(); if ($error) { $this->message = JText::_('COM_CITRUSCART_ERROR') . ": " . $this->message; } $redirect = JRoute::_("index.php?option=com_citruscart&controller=geozones&task=selectplugins&type={$type}&tmpl=component&id=" . $id, false); $this->setRedirect($redirect, $this->message, $this->messagetype); }
/** * Verifies the fields in a submitted form. * Then adds the item to the users cart * * @return unknown_type */ function addToCart() { $input = JFactory::getApplication()->input; JSession::checkToken() or jexit('Invalid Token'); $product_id = $input->getInt('product_id'); $product_qty = $input->getInt('product_qty'); $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); if (!$itemid) { $itemid = $input->getInt('Itemid', 0); } } // 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; } // convert elements to array that can be binded $values = $input->getArray($_POST); if (isset($values['elements'])) { $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $values['elements'])); unset($values['elements']); // convert elements to array that can be binded $values = array_merge(CitruscartHelperBase::elementsToArray($elements), $values); $intpu->set($values, 'POST'); } $files = $input->files->get('files'); $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) { $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' => $product_id), true, false); // 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; } $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); 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) $product_id; $item->product_qty = (int) $product_qty; $item->product_attributes = $attributes_csv; $item->vendor_id = '0'; // vendors only in enterprise version // if ther is another product_url, put it into the cartitem_params, to allow custom redirect if (array_key_exists('product_url', $values)) { $params = new DSCParameter(trim(@$item->cartitem_params)); $params->set('product_url', $values['product_url']); $item->cartitem_params = trim($params->__toString()); } // onAfterCreateItemForAddToCart: plugin can add values to the item before it is being validated /added // once the extra field(s) have been set, they will get automatically saved $dispatcher = JDispatcher::getInstance(); $results = JFactory::getApplication()->triggerEvent("onAfterCreateItemForAddToCart", array($item, $values, $files)); foreach ($results as $result) { foreach ($result as $key => $value) { $item->set($key, $value); } } // 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 // After login, session_id is changed by Joomla, so store this for reference $session = JFactory::getSession(); $session->set('old_sessionid', $session->getId()); // add the item to the cart Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $cart_helper = new CitruscartHelperCarts(); $cartitem = $cart_helper->addItem($item); // fire plugin event $dispatcher = JDispatcher::getInstance(); JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($cartitem, $values)); // get the 'success' redirect url switch (Citruscart::getInstance()->get('addtocartaction', 'redirect')) { case "checkout": // if a base64_encoded url is present as return, use that as the return url // otherwise return == the product view page $returnUrl = base64_encode($redirect); if ($return_url = $input->getBase64('return')) { $return_url = base64_decode($return_url); if (JURI::isInternal($return_url)) { $returnUrl = base64_encode($return_url); } } // if a base64_encoded url is present as redirect, redirect there, // otherwise redirect to the checkout $itemid_checkout = $router->findItemid(array('view' => 'checkout')); $itemid_opc = $router->findItemid(array('view' => 'opc')); $checkout_view = "checkout"; $itemid = null; if ($itemid_opc) { $itemid = $itemid_opc; $checkout_view = "opc"; } elseif ($itemid_checkout) { $itemid = $itemid_checkout; } if (!$itemid) { $itemid = $input->getInt('Itemid', 0); } $redirect = JRoute::_("index.php?option=com_citruscart&view=" . $checkout_view . "&Itemid=" . $itemid, false); if ($redirect_url = $input->getBase64('redirect')) { $redirect_url = base64_decode($redirect_url); if (JURI::isInternal($redirect_url)) { $redirect = $redirect_url; } } if (strpos($redirect, '?') === false) { $redirect .= "?return=" . $returnUrl; } else { $redirect .= "&return=" . $returnUrl; } break; case "0": case "none": // redirects back to product page break; case "samepage": // redirects back to the page it came from (category, content, etc) // Take only the url without the base domain (index.php?option.....) if ($return_url = $input->getBase64('return')) { $return_url = base64_decode($return_url); $uri = JURI::getInstance(); $uri->parse($return_url); $redirect = $uri->__toString(array('path', 'query', 'fragment')); $redirect = JRoute::_($redirect, false); } break; case "lightbox": case "redirect": default: // if a base64_encoded url is present as return, use that as the return url // otherwise return == the product view page $returnUrl = base64_encode($redirect); if ($return_url = $input->getBase64('return')) { $return_url = base64_decode($return_url); if (JURI::isInternal($return_url)) { $returnUrl = base64_encode($return_url); } } // if a base64_encoded url is present as redirect, redirect there, // otherwise redirect to the cart $itemid = $router->findItemid(array('view' => 'carts')); if (!$itemid) { $itemid = $input->getInt('Itemid', 0); } $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $itemid, false); if ($redirect_url = $input->getBase64('redirect')) { $redirect_url = base64_decode($redirect_url); if (JURI::isInternal($redirect_url)) { $redirect = $redirect_url; } } //$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; } $this->messagetype = 'message'; $this->message = JText::_('COM_CITRUSCART_ITEM_ADDED_TO_YOUR_CART'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; }
/** * Returns a DSCParameter Formatted string representing the currency * * @param $currency_id currency_id * @return $string DSCParameter formatted string */ public static function currencyToParameters($currency_id) { if (!is_numeric($currency_id)) { return false; } JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('Currencies', 'CitruscartModel'); $table = $model->getTable(); // Load the currency if (!$table->load($currency_id)) { return false; } // Convert this into a DSCParameter formatted string // a bit rough, but works smoothly and is extensible (works even if you add another parameter to the curremcy table $currency_parameters = $table; unset($table); unset($currency_parameters->currency_id); unset($currency_parameters->created_date); unset($currency_parameters->modified_date); unset($currency_parameters->currency_enabled); $param = new DSCParameter(''); $param->loadObject($currency_parameters); return $param->__toString(); }
/** * * A separate space for working through all the different integrations */ function prepareParameters(&$row) { $app = JFactory::getApplication(); // this row's product_params has already been set from the textarea's POST // so we need to add to it $params = new DSCParameter(trim($row->product_params)); $params->set('amigos_commission_override', $app->input->get('amigos_commission_override')); $params->set('billets_ticket_limit_increase', $app->input->get('billets_ticket_limit_increase')); $params->set('billets_ticket_limit_exclusion', $app->input->get('billets_ticket_limit_exclusion')); $params->set('billets_hour_limit_increase', $app->input->get('billets_hour_limit_increase')); $params->set('billets_hour_limit_exclusion', $app->input->get('billets_hour_limit_exclusion')); $params->set('juga_group_csv_add', $app->input->get('juga_group_csv_add')); $params->set('juga_group_csv_remove', $app->input->get('juga_group_csv_remove')); $params->set('juga_group_csv_add_expiration', $app->input->get('juga_group_csv_add_expiration')); $params->set('juga_group_csv_remove_expiration', $app->input->get('juga_group_csv_remove_expiration')); $params->set('core_user_change_gid', $app->input->get('core_user_change_gid')); $params->set('core_user_new_gid', $app->input->get('core_user_new_gid')); $params->set('ambrasubs_type_id', $app->input->get('ambrasubs_type_id')); $params->set('hide_quantity_input', $app->input->get('param_hide_quantity_input')); $params->set('default_quantity', $app->input->get('param_default_quantity')); $params->set('hide_quantity_cart', $app->input->get('param_hide_quantity_cart')); $params->set('show_product_compare', $app->input->getInt('param_show_product_compare', 1)); $row->product_params = trim($params->__toString()); return $row; }
/** * Event is triggered after product is saved in Citruscart * and updates the AS subscription type's record * * @param $product * @return unknown_type */ function onAfterSaveProducts($product) { $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setId($product->product_id); $product = $model->getItem(); $ambrasubs_type_id = $product->product_parameters->get('ambrasubs_type_id'); if (!empty($ambrasubs_type_id)) { $db = JFactory::getDBO(); $db->setQuery("SELECT * FROM #__ambrasubs_types WHERE `id` = '{$ambrasubs_type_id}';"); $type = $db->loadObject(); $params = new DSCParameter(trim($type->params)); $params->set('citruscart_product_id', $product->product_id); $type_params = $db->escape(trim($params->__toString())); $db->setQuery("UPDATE #__ambrasubs_types SET `params` = '{$type_params}' WHERE `id` = '{$ambrasubs_type_id}';"); $db->query(); } }