function getObjectInfo($id, $language = null) { $db = JFactory::getDBO(); $query = "SELECT a.product_id as id, a.product_name as title" . "\n , c.category_id" . "\n FROM #__tienda_products AS a" . "\n LEFT JOIN #__tienda_productcategoryxref AS b ON b.product_id = a.product_id" . "\n LEFT JOIN #__tienda_categories AS c ON b.category_id = c.category_id" . "\n WHERE a.product_id = " . intval($id); $db->setQuery($query, 0, 1); $product = $db->loadObject(); $info = new JCommentsObjectInfo(); if (!empty($product)) { $routerHelper = JPATH_ROOT . '/administrator/components/com_tienda/helpers/route.php'; if (is_file($routerHelper)) { require_once $routerHelper; $info->title = $product->title; $info->access = 0; $info->userid = 0; $info->link = JRoute::_(TiendaHelperRoute::product($id, $product->category_id)); } } return $info; }
/** * Displays the Tienda add to cart button * * @param $row * @param $user * @return unknown_type */ function displayCartButton($row, $user) { $params = new DSCParameter(trim($row->params)); $product_id = $params->get('tienda_product_id'); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId($product_id); $product = $model->getItem(); if (!empty($product_id) && !empty($product->product_id)) { Tienda::load('TiendaHelperProduct', 'helpers.product'); if ($this->params->get('redirect_to_tienda') == '1') { Tienda::load("TiendaHelperRoute", 'helpers.route'); $router = new TiendaHelperRoute(); $link = $router->product($eventproduct->product_id); $redirect = JRoute::_($link, false); $app = JFactory::getApplication(); $app->redirect($redirect); return; } // set the redirect if ($this->params->get('redirect_back_to_ambrasubs') == '1') { $uri = JURI::getInstance(); $redirect = $uri->toString(); $return = ''; } else { Tienda::load("TiendaHelperRoute", 'helpers.route'); $router = new TiendaHelperRoute(); $itemid = $router->findItemid(array('view' => 'checkout')); $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $itemid, false); $uri = JURI::getInstance(); $return = $uri->toString(); } $vars->redirect = $redirect; $vars->return = $return; $vars->ambrasubs_type = $row; $vars->product = $product; echo $this->_getLayout('product_buy', $vars, $this->_element, 'ambrasubs'); } }
/** * Generates the xml for the update request * @param unknown_type $product * @param string $etag - etag of the product */ protected function getUpdateXML($product, $etag) { // perform the insertion Tienda::load('TiendaArrayToXML', 'library.xml'); // Populate the xml request $xml = array(); $xml['app:control']['sc:required_destination']['attributes']['dest'] = 'ProductSearch'; // Title, id and description $xml['title'] = $product->product_name; $xml['content']['attributes']['type'] = 'text/html'; $xml['content'] = $product->product_description; $xml['sc:id'] = $product->product_id; // Link to the product Tienda::load('TiendaHelperRoute', 'helpers.route'); $xml['link']['attributes']['rel'] = 'alternate'; $xml['link']['attributes']['type'] = 'text/html'; $baseurl = str_replace("/administrator/", "/", JURI::base()); $xml['link']['attributes']['href'] = $baseurl . TiendaHelperRoute::product($product->product_id); //$xml['link']['attributes']['href'] = 'http://www.weble.it/products/'.$product->product_id; // Condition $xml['scp:condition'] = 'new'; // Price $currency_id = Tienda::getInstance()->get('default_currencyid', '1'); Tienda::load('TiendaTableCurrencies', 'tables.currencies'); $currency = JTable::getInstance('Currencies', 'TiendaTable'); $currency->load((int) $currency_id); $xml['scp:price']['attributes']['unit'] = trim(strtoupper($currency->currency_code)); $xml['scp:price']['@value'] = TiendaHelperBase::number(TiendaHelperProduct::getPrice($product->product_id)->product_price, array('num_decimals', '0')); // Manufacturer Tienda::load('TiendaTableManufacturers', 'tables.manufacturers'); $manufacturer = JTable::getInstance('Manufacturers', 'TiendaTable'); if ($manufacturer->load($product->manufacturer_id)) { $xml['scp:brand'] = $manufacturer->manufacturer_name; } $xml['entry']['attributes']['gd:etag'] = $etag; // Create the request $null = null; $helper = new TiendaArrayToXML(); $ns = array(array('name' => 'app', 'url' => "http://www.w3.org/2007/app"), array('name' => 'gd', 'url' => "http://schemas.google.com/g/2005"), array('name' => 'sc', 'url' => "http://schemas.google.com/structuredcontent/2009"), array('name' => 'scp', 'url' => "http://schemas.google.com/structuredcontent/2009/products")); $xml = $helper->toXml($xml, 'entry', $null, $ns, "http://www.w3.org/2005/Atom"); return $xml; }
/** * Verifies the fields in a submitted form. * Then adds the item to the users cart * * @return unknown_type */ function addChildrenToCart() { JRequest::checkToken() or jexit('Invalid Token'); $product_id = JRequest::getInt('product_id'); $quantities = JRequest::getVar('quantities', array(0), 'request', 'array'); $filter_category = JRequest::getInt('filter_category'); Tienda::load("TiendaHelperRoute", 'helpers.route'); $router = new TiendaHelperRoute(); if (!($itemid = $router->product($product_id, $filter_category, true))) { $itemid = $router->category(1, true); } // set the default redirect URL $redirect = "index.php?option=com_tienda&view=products&task=view&id={$product_id}&filter_category={$filter_category}&Itemid=" . $itemid; $redirect = JRoute::_($redirect, false); Tienda::load('TiendaHelperBase', 'helpers._base'); $helper = TiendaHelperBase::getInstance(); if (!Tienda::getInstance()->get('shop_enabled', '1')) { $this->messagetype = 'notice'; $this->message = JText::_('COM_TIENDA_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 = JRequest::get('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"; } Tienda::load('TiendaHelperCarts', 'helpers.carts'); $carthelper = new TiendaHelperCarts(); $cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type); // TODO get the children // loop thru each child, // get the list JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('ProductRelations', 'TiendaModel'); $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 = Tienda::getClass('TiendaHelperProduct', '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_TIENDA_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', 'TiendaTable'); $product->load(array('product_id' => $child->product_id_to)); // if product notforsale, fail if ($product->product_notforsale) { $this->messagetype = 'notice'; $this->message = JText::_('COM_TIENDA_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_TIENDA_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_TIENDA_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 = $dispatcher->trigger("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)) { Tienda::load('TiendaHelperCarts', 'helpers.carts'); foreach ($items as $item) { // add the item to the cart $cart_helper = new TiendaHelperCarts(); $cartitem = $cart_helper->addItem($item); // fire plugin event $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterAddToCart', array($cartitem, $values)); } $this->messagetype = 'message'; $this->message = JText::_('COM_TIENDA_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 (Tienda::getInstance()->get('addtocartaction', 'redirect')) { case "redirect": $returnUrl = base64_encode($redirect); $itemid = $router->findItemid(array('view' => 'checkout')); $redirect = JRoute::_("index.php?option=com_tienda&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; }