/** * 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; }
/** * Set basic properties for the item, whether in a list or a singleton * * @param unknown_type $item * @param unknown_type $key * @param unknown_type $refresh */ protected function prepareItem(&$item, $key = 0, $refresh = false) { Tienda::load("TiendaHelperProduct", 'helpers.product'); Tienda::load('TiendaHelperSubscription', 'helpers.subscription'); $helper_product = new TiendaHelperProduct(); if (!empty($item->product_recurs)) { $item->recurring_price = $item->price; if ($item->subscription_prorated) { Tienda::load('TiendaHelperSubscription', 'helpers.subscription'); $result = TiendaHelperSubscription::calculateProRatedTrial($item->subscription_prorated_date, $item->subscription_prorated_term, $item->recurring_period_unit, $item->recurring_trial_price, $item->subscription_prorated_charge); $item->price = $result['price']; $item->prorated_price = $result['price']; $item->prorated_interval = $result['interval']; $item->prorated_unit = $result['unit']; // $item->recurring_trial = $result['trial']; } else { if (!empty($item->recurring_trial)) { $item->price = $item->recurring_trial_price; } } } $user_id = $this->getState('user.id', 0); $qty = $this->getState('product.qty', -1); if ($qty > -1) { $user_group = TiendaHelperUser::getUserGroup($user_id, $item->product_id); $price = TiendaHelperProduct::getPrice($item->product_id, $qty, $user_group); $item->price = $price->product_price; } $item->product_parameters = new DSCParameter($item->product_params); $item->slug = $item->product_alias ? ":{$item->product_alias}" : ""; $item->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id; $item->link_edit = 'index.php?option=com_tienda&view=products&task=edit&id=' . $item->product_id; $item->product_categories = $this->getCategories($item->product_id); $item->default_attributes = $helper_product->getDefaultAttributes($item->product_id); $item->product_classes = null; foreach ($item->product_categories as $cat) { $item->product_classes .= " " . $cat->category_alias; } if (!empty($item->product_class_suffix)) { $item->product_classes .= " " . $item->product_class_suffix; } $item->product_classes = trim($item->product_classes); parent::prepareItem($item, $key, $refresh); }
/** * Gets a product's related items * formatted for display * * @param int $address_id * @return string html */ private function getRelationshipsHtml($product_id, $relation_type = 'relates') { $html = ''; $validation = ""; // get the list JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('ProductRelations', 'TiendaModel'); $model->setState('filter_relation', $relation_type); switch ($relation_type) { case "requires": $model->setState('filter_product_from', $product_id); $check_quantity = false; $layout = 'product_requirements'; break; case "parent": case "child": case "children": $model->setState('filter_product_from', $product_id); $check_quantity = true; $validation = "index.php?option=com_tienda&view=products&task=validateChildren&format=raw"; $layout = 'product_children'; break; case "relates": $model->setState('filter_product', $product_id); $check_quantity = false; $layout = 'product_relations'; break; default: return $html; break; } if ($items = $model->getList()) { $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category')); if (empty($filter_category)) { $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($product_id); if (!empty($categories)) { $filter_category = $categories[0]; } } $user = JFactory::getUser(); $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); foreach ($items as $key => $item) { if ($check_quantity) { // TODO Unset $items[$key] if // this is out of stock && // check_inventory && // item for sale } if ($item->product_id_from == $product_id) { // display the _product_to $item->product_id = $item->product_id_to; $item->product_name = $item->product_name_to; $item->product_model = $item->product_model_to; $item->product_sku = $item->product_sku_to; $item->product_price = $item->product_price_to; } else { // display the _product_from $item->product_id = $item->product_id_from; $item->product_name = $item->product_name_from; $item->product_model = $item->product_model_from; $item->product_sku = $item->product_sku_from; $item->product_price = $item->product_price_from; } //get the right price base on the $filter_group $filter_group = TiendaHelperUser::getUserGroup($user->id, $item->product_id); $priceObj = TiendaHelperProduct::getPrice($item->product_id, '1', $filter_group); $item->product_price = $priceObj->product_price; $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($item->product_id, $filter_category, true); $item->itemid = JRequest::getInt('Itemid', $itemid); $item->tax = 0; $item->showtax = $show_tax; if ($show_tax) { Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones($user->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => $config->get('default_tax_geozone'))); $geozones = array($table); } $taxtotal = TiendaHelperProduct::getTaxTotal($item->product_id, $geozones); $tax = $taxtotal->tax_total; $item->taxtotal = $taxtotal; $item->tax = $tax; } } } if (!empty($items)) { $vars = new JObject(); $vars->items = $items; $vars->product_id = $product_id; $vars->filter_category = $filter_category; $vars->validation = $validation; ob_start(); echo $this->_getLayout($layout, $vars); $html = ob_get_contents(); ob_end_clean(); } return $html; }
/** * Sample use of the products model for getting products with certain properties * See admin/models/products.php for all the filters currently built into the model * * @param $parameters * @return unknown_type */ function getProducts() { // Check the registry to see if our Tienda class has been overridden if (!class_exists('Tienda')) { JLoader::register("Tienda", JPATH_ADMINISTRATOR . "/components/com_tienda/defines.php"); } // load the config class Tienda::load('Tienda', 'defines'); Tienda::load('TiendaHelperProduct', 'helpers.product'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); // get the model $model = JModel::getInstance('Products', 'TiendaModel'); // 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->toMysql()); $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 = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $default_user_group = Tienda::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) { Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } foreach ($products as $product) { if ($overide_price) { $filter_group = TiendaHelperUser::getUserGroup(JFactory::getUser()->id, $product->product_id); $price = TiendaHelperProduct::getPrice($product->product_id, '1', $filter_group); $product->price = $price->product_price; } $product->taxtotal = 0; $product->tax = 0; if ($show_tax) { $taxtotal = TiendaHelperProduct::getTaxTotal($product->product_id, $geozones); $product->taxtotal = $taxtotal; $product->tax = $taxtotal->tax_total; } $product->filter_category = ''; $categories = TiendaHelperProduct::getCategories($product->product_id); if (!empty($categories)) { $product->link .= "&filter_category=" . $categories[0]; $product->filter_category = $categories[0]; } $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($product->filter_category, true); if (empty($itemid)) { $product->itemid = $this->params->get('itemid'); } else { $product->itemid = $itemid; } } } return $products; }
/** * 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 Tienda class has been overridden if (!class_exists('Tienda')) { JLoader::register("Tienda", JPATH_ADMINISTRATOR . "/components/com_tienda/defines.php"); } // load the config class Tienda::load('Tienda', 'defines'); Tienda::load('TiendaHelperProduct', 'helpers.product'); Tienda::load('TiendaHelperUser', 'helpers.user'); $helper = new TiendaHelperProduct(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); // get the model $model = JModel::getInstance('OrderItems', 'TiendaModel'); $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 = Tienda::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 = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } } foreach ($products as $product) { $product->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $product->product_id; $filter_group = TiendaHelperUser::getUserGroup(JFactory::getUser()->id, $product->product_id); $price = $helper->getPrice($product->product_id, '1', $filter_group); $product->price = $price->product_price; //product total $product->taxtotal = 0; $product->tax = 0; if ($show_tax) { $taxtotal = TiendaHelperProduct::getTaxTotal($product->product_id, $geozones); $product->taxtotal = $taxtotal; $product->tax = $taxtotal->tax_total; } $product->filter_category = ''; $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($product->product_id); if (!empty($categories)) { $product->link .= "&filter_category=" . $categories[0]; $product->filter_category = $categories[0]; } $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($product->filter_category, true); if (empty($itemid)) { $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->findItemid(array('view' => 'products')); } $product->itemid = $itemid; } } return $products; }