Пример #1
0
 function getCart()
 {
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     JModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models');
     // determine whether we're working with a session or db cart
     $suffix = TiendaHelperCarts::getSuffix();
     $model = JModel::getInstance('Carts', 'TiendaModel');
     $session = JFactory::getSession();
     $user = JFactory::getUser();
     $model->setState('filter_user', $user->id);
     if (empty($user->id)) {
         $model->setState('filter_session', $session->getId());
     }
     $list = $model->getList(false, false);
     Tienda::load('Tienda', 'defines');
     $config = Tienda::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $this->using_default_geozone = false;
     if ($show_tax) {
         Tienda::load('TiendaHelperUser', 'helpers.user');
         $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id);
         if (empty($geozones)) {
             // use the default
             $this->using_default_geozone = true;
             $table = JTable::getInstance('Geozones', 'TiendaTable');
             $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone')));
             $geozones = array($table);
         }
         Tienda::load("TiendaHelperProduct", 'helpers.product');
         foreach ($list as &$item) {
             $taxtotal = TiendaHelperProduct::getTaxTotal($item->product_id, $geozones);
             $item->product_price = $item->product_price + $taxtotal->tax_total;
             $item->taxtotal = $taxtotal;
         }
     }
     return $list;
 }
Пример #2
0
 /**
  * Calculate taxes on list of products
  *
  * @param $products						Array of products
  * @param $source						Source of tax calculation (final_price '1', product_price '2', orderitem_price '3')
  * @param $billing_address		Actual customer's billing address
  * @param $shipping_address		Actual customer's shipping address
  * @param $tax_type						for the future use
  *
  * @return Associative array with indexes product_id of products with arrays with list of their tax rates (names and rates)
  */
 public static function calculateTax($products, $source = 1, $billing_address = null, $shipping_address = null, $tax_type = null)
 {
     $result = new stdClass();
     $result->tax_total = 0.0;
     $result->tax_rate_rates = array();
     $result->tax_class_rates = array();
     $result->product_taxes = array();
     if (!is_array($products)) {
         return $result;
     }
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     Tienda::load('TiendaQuery', 'library.query');
     Tienda::load('TiendaTools', 'library.tools');
     if ($billing_address) {
         $billing_zones = TiendaHelperShipping::getGeoZones($billing_address->zone_id, '1', $billing_address->postal_code);
     } else {
         $billing_zones = array();
     }
     if (!empty($billing_zones)) {
         foreach ($billing_zones as $key => $value) {
             $billing_zones[$key] = $value->geozone_id;
         }
     }
     //load the default geozones when user is logged out and the config is to show tax
     if (empty($billing_zones)) {
         $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id);
         if (empty($geozones)) {
             // use the default
             $billing_zones = array(Tienda::getInstance()->get('default_tax_geozone'));
         } else {
             foreach ($geozones as $key => $value) {
                 $billing_zones[$key] = $value->geozone_id;
             }
         }
     }
     return TiendaHelperTax::calculateGeozonesTax($products, $source, $billing_zones);
 }
Пример #3
0
 /**
  * Get the cart button form for a specific product
  *
  * @param int $product_id 	The id of the product
  * @return html	The add to cart form
  */
 public static function getCartButton($product_id, $layout = 'product_buy', $values = array(), &$callback_js = '')
 {
     if (is_array($values) && !count($values)) {
         $values = JRequest::get('request');
     }
     $html = '';
     $page = JRequest::getVar('page', 'product');
     $isPOS = $page == 'pos';
     if ($isPOS) {
         JLoader::register("TiendaViewPOS", JPATH_ADMINISTRATOR . "/components/com_tienda/views/pos/view.html.php");
         $view = new TiendaViewPOS();
     } else {
         JLoader::register("TiendaViewProducts", JPATH_SITE . "/components/com_tienda/views/products/view.html.php");
         $view = new TiendaViewProducts();
     }
     $model = JModel::getInstance('Products', 'TiendaModel');
     $model->setId($product_id);
     $model->setState('task', 'product_buy');
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper_product = TiendaHelperBase::getInstance('Product');
     Tienda::load('TiendaHelperUser', 'helpers.user');
     $user_id = JFactory::getUser()->id;
     if ($isPOS) {
         $user_id = JRequest::getInt('user_id', $user_id);
     }
     $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id);
     $qty = isset($values['product_qty']) && !empty($values['product_qty']) ? $values['product_qty'] : 1;
     $model->setState('filter_group', $filter_group);
     $model->setState('product.qty', $qty);
     $model->setState('user.id', $user_id);
     $row = $model->getItem(false, true, false);
     if ($row->product_notforsale || Tienda::getInstance()->get('shop_enabled') == '0') {
         return $html;
     }
     // This enable this helper method to be used outside of tienda
     if ($isPOS) {
         $view->set('_controller', 'pos');
         $view->set('_view', 'pos');
     } else {
         $view->addTemplatePath(JPATH_SITE . '/components/com_tienda/views/products/tmpl');
         $view->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication('site')->getTemplate() . '/html/com_tienda/products/');
         // add extra templates
         $view->addTemplatePath(Tienda::getPath('product_buy_templates'));
         $view->set('_controller', 'products');
         $view->set('_view', 'products');
     }
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->setLayout($layout);
     $view->product_id = $product_id;
     $view->values = $values;
     $filter_category = $model->getState('filter_category', JRequest::getInt('filter_category', (int) @$values['filter_category']));
     $view->filter_category = $filter_category;
     if ($isPOS) {
         $view->validation = "index.php?option=com_tienda&view=pos&task=validate&format=raw";
     } else {
         $view->validation = "index.php?option=com_tienda&view=products&task=validate&format=raw";
     }
     $config = Tienda::getInstance();
     // 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);
         $view->shipping_cost_link = $shipping_cost_link;
     }
     $quantity_min = 1;
     if ($row->quantity_restriction) {
         $quantity_min = $row->quantity_min;
     }
     $invalidQuantity = '0';
     $attributes = array();
     $attr_orig = array();
     if (empty($values)) {
         $product_qty = $quantity_min;
         // get the default set of attribute_csv
         if (!isset($row->default_attributes)) {
             $default_attributes = $helper_product->getDefaultAttributes($product_id);
         } else {
             $default_attributes = $row->default_attributes;
         }
         sort($default_attributes);
         $attributes_csv = implode(',', $default_attributes);
         $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
         $attr_orig = $attributes = $default_attributes;
     } else {
         $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : $quantity_min;
         // TODO only display attributes available based on the first selected attribute?
         foreach ($values as $key => $value) {
             if (substr($key, 0, 10) == 'attribute_') {
                 if (empty($value)) {
                     $attributes[$key] = 0;
                 } else {
                     $attributes[$key] = $value;
                 }
             }
         }
         if (!count($attributes)) {
             // no attributes are selected -> use default
             if (!isset($row->default_attributes)) {
                 $attributes = $helper_product->getDefaultAttributes($product_id);
             } else {
                 $attributes = $row->default_attributes;
             }
         }
         $attr_orig = $attributes;
         sort($attributes);
         // Add 0 to attributes to include all the root attributes
         //$attributes[] = 0;//remove this one. its causing the getAvailableQuantity to not get quantity because of wrong csv
         // For getting child opts
         $view->selected_opts = json_encode(array_merge($attributes, array('0')));
         $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 = $helper_product->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
     }
     // adjust the displayed price based on the selected or default attributes
     TiendaHelperProduct::calculateProductAttributeProperty($row, $attr_orig, 'price', 'product_weight');
     $show_tax = $config->get('display_prices_with_tax');
     $show_product = $config->get('display_category_cartbuttons');
     $view->show_tax = $show_tax;
     $row->tax = '0';
     $row->taxtotal = '0';
     if ($show_tax) {
         // finish TiendaHelperUser::getGeoZone -- that's why this isn't working
         Tienda::load('TiendaHelperUser', 'helpers.user');
         $geozones_user = TiendaHelperUser::getGeoZones($user_id);
         if (empty($geozones_user)) {
             $geozones = array(Tienda::getInstance()->get('default_tax_geozone'));
         } else {
             $geozones = array();
             foreach ($geozones_user as $value) {
                 $geozones[] = $value->geozone_id;
             }
         }
         Tienda::load('TiendaHelperTax', 'helpers.tax');
         $product = new stdClass();
         $product->product_price = $row->price;
         $product->product_id = $product_id;
         $tax = TiendaHelperTax::calculateGeozonesTax(array($product), 2, $geozones);
         $row->taxtotal = $tax->tax_total;
         $row->tax = $tax->tax_total;
     }
     $row->_product_quantity = $product_qty;
     if ($page == 'product' || $isPOS) {
         $display_cartbutton = Tienda::getInstance()->get('display_product_cartbuttons', '1');
     } else {
         $display_cartbutton = Tienda::getInstance()->get('display_category_cartbuttons', '1');
     }
     $view->page = $page;
     $view->display_cartbutton = $display_cartbutton;
     $view->availableQuantity = $availableQuantity;
     $view->invalidQuantity = $invalidQuantity;
     if ($isPOS) {
         $view->product = $row;
     } else {
         $view->item = $row;
     }
     $dispatcher = JDispatcher::getInstance();
     ob_start();
     $dispatcher->trigger('onDisplayProductAttributeOptions', array($row->product_id));
     $view->onDisplayProductAttributeOptions = ob_get_contents();
     ob_end_clean();
     $html = $view->loadTemplate();
     if (isset($view->callback_js) && !empty($view->callback_js)) {
         $callback_js = $view->callback_js;
     }
     return $html;
 }
Пример #4
0
 /**
  * Gets a product's add to cart section
  * formatted for display
  *
  * @param int $address_id
  * @return string html
  */
 function getAddToCart($product_id, $values = array())
 {
     $html = '';
     $view = $this->getView('products', 'html');
     //$model  = $this->getModel( $this->get('suffix') );
     $model = JModel::getInstance('Products', 'TiendaModel');
     $model->setId($product_id);
     Tienda::load('TiendaHelperUser', 'helpers.user');
     $user_id = JFactory::getUser()->id;
     $filter_group = TiendaHelperUser::getUserGroup($user_id);
     $model->setState('filter_group', $filter_group);
     //$model->_item = '';
     $row = $model->getItem(false);
     if ($row->product_notforsale || Tienda::getInstance()->get('shop_enabled') == '0') {
         return $html;
     }
     $view->set('_controller', 'products');
     $view->set('_view', 'products');
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->setLayout('product_buy');
     $view->assign('item', $row);
     $view->assign('product_id', $product_id);
     $view->assign('values', $values);
     $filter_category = $model->getState('filter_category', JRequest::getInt('filter_category', (int) @$values['filter_category']));
     $view->assign('filter_category', $filter_category);
     $view->assign('validation', "index.php?option=com_tienda&view=products&task=validate&format=raw");
     $config = Tienda::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $view->assign('show_tax', $show_tax);
     $view->assign('tax', 0);
     $view->assign('taxtotal', '');
     $view->assign('shipping_cost_link', '');
     $row->tax = '0';
     if ($show_tax) {
         // finish TiendaHelperUser::getGeoZone -- that's why this isn't working
         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);
         }
         $taxtotal = TiendaHelperProduct::getTaxTotal($product_id, $geozones);
         $tax = $taxtotal->tax_total;
         $row->taxtotal = $taxtotal;
         $row->tax = $tax;
         $view->assign('taxtotal', $taxtotal);
         $view->assign('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);
         $view->assign('shipping_cost_link', $shipping_cost_link);
     }
     $invalidQuantity = '0';
     if (empty($values)) {
         $product_qty = '1';
         // get the default set of attribute_csv
         $default_attributes = TiendaHelperProduct::getDefaultAttributes($product_id);
         sort($default_attributes);
         $attributes_csv = implode(',', $default_attributes);
         $availableQuantity = Tienda::getClass('TiendaHelperProduct', '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'] : JRequest::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 = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
         // adjust the displayed price based on the selected attributes
         $table = JTable::getInstance('ProductAttributeOptions', 'TiendaTable');
         $attrs = array();
         foreach ($attributes as $attrib_id) {
             // load the attrib's object
             $table->load($attrib_id);
             // update the price
             //$row->price = $row->price + floatval( "$table->productattributeoption_prefix"."$table->productattributeoption_price");
             // is not + or -
             if ($table->productattributeoption_prefix == '=') {
                 $row->price = floatval($table->productattributeoption_price);
             } else {
                 $row->price = $row->price + floatval("{$table->productattributeoption_prefix}" . "{$table->productattributeoption_price}");
             }
             $attrs[] = $table->productattributeoption_id;
         }
         $row->sku = TiendaHelperProduct::getProductSKU($row, $attrs);
         $view->assign('item', $row);
     }
     $view->assign('availableQuantity', $availableQuantity);
     $view->assign('invalidQuantity', $invalidQuantity);
     $dispatcher = JDispatcher::getInstance();
     ob_start();
     $dispatcher->trigger('onDisplayProductAttributeOptions', array($row->product_id));
     $view->assign('onDisplayProductAttributeOptions', ob_get_contents());
     ob_end_clean();
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
Пример #5
0
 /**
  * Generates a selectlist for the specified Product Attribute 
  *
  * @param unknown_type $productattribute_id 
  * @param unknown_type $selected
  * @param unknown_type $name
  * @param unknown_type $attribs
  * @param unknown_type $idtag
  * @return unknown_type
  */
 public static function productattributeoptions($productattribute_id, $selected, $name = 'filter_pao', $attribs = array('class' => 'inputbox'), $idtag = null, $opt_selected = array(), $user_id = 0)
 {
     $uid = $user_id == 0 ? JFactory::getUser()->id : $user_id;
     $list = array();
     $pid = !empty($attribs['pid']) ? $attribs['pid'] : null;
     $changed_attr = !empty($attribs['changed_attr']) ? $attribs['changed_attr'] : -1;
     $changed_pao = !empty($attribs['changed_pao']) ? $attribs['changed_pao'] : -1;
     if (empty($pid)) {
         $items = array();
     } else {
         $items = TiendaHelperProduct::getAvailableAttributeOptions($pid, $productattribute_id, $changed_attr, $changed_pao, $opt_selected);
     }
     $geozones = array();
     $shipping = false;
     if (count($items)) {
         $shipping = $items[0]->product_ships;
         if ($shipping) {
             Tienda::load('TiendaHelperProduct', 'helpers.product');
             Tienda::load('TiendaHelperUser', 'helpers.user');
             $geozones = TiendaHelperUser::getGeoZones($uid);
             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 (@$items as $item) {
         if ($shipping) {
             $tax = TiendaHelperProduct::getTaxTotal($item->product_id, $geozones, $item->productattributeoption_price);
             $item->productattributeoption_price += $tax->tax_total;
         }
         // Do not display the prefix if it is "=" (it's not good to see =�13, better �13)
         if ($item->productattributeoption_prefix != '=') {
             $display_suffix = $item->productattributeoption_price > '0' ? ": " . $item->productattributeoption_prefix . TiendaHelperBase::currency($item->productattributeoption_price) : '';
         } else {
             $display_suffix = $item->productattributeoption_price > '0' ? ": " . TiendaHelperBase::currency($item->productattributeoption_price) : '';
         }
         $display_name = JText::_($item->productattributeoption_name) . $display_suffix;
         if ($item->is_blank) {
             $list[] = self::option(0, $display_name);
         } else {
             $list[] = self::option($item->productattributeoption_id, $display_name);
         }
     }
     return self::genericlist($list, $name, $attribs, 'value', 'text', $selected, $idtag);
 }
Пример #6
0
Tienda::load('TiendaHelperCarts', 'helpers.carts');
$items = TiendaHelperCarts::getProductsInfo();
$num = count($items);
// Convert the cart to a "fake" order, to show totals and others things
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
$orderTable = JTable::getInstance('Orders', 'TiendaTable');
foreach ($items as $item) {
    $orderTable->addItem($item);
}
$items = $orderTable->getItems();
Tienda::load('Tienda', 'defines');
$config = Tienda::getInstance();
$show_tax = $config->get('display_prices_with_tax');
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);
    }
    $orderTable->setGeozones($geozones);
}
// order calculation can happen after all items are added to order object
$orderTable->calculateTotals();
// format the subtotal
//$order_subtotal = TiendaHelperBase::currency($orderTable->order_total);
if (!empty($items) || empty($items) && $params->get('display_null')) {
    require JModuleHelper::getLayoutPath('mod_tienda_cart', $params->get('layout', 'default'));
} else {
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 /**
  * 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())
 {
     $html = '';
     Tienda::load('TiendaModelProducts', 'models.products');
     $model = JModel::getInstance('Products', 'TiendaModel');
     $user = JFactory::getUser();
     Tienda::load('TiendaHelperUser', 'helpers.user');
     $filter_group = TiendaHelperUser::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 || Tienda::getInstance()->get('shop_enabled') == '0') {
         return $html;
     }
     $vars->item = $row;
     $vars->product_id = $product_id;
     $vars->values = $values;
     $vars->validation = "index.php?option=com_tienda&view=products&task=validate&format=raw";
     $vars->params = $params;
     $config = Tienda::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 TiendaHelperUser::getGeoZone -- that's why this isn't working
         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);
         }
         $taxtotal = TiendaHelperProduct::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 = TiendaHelperProduct::getDefaultAttributes($product_id);
         sort($default_attributes);
         $attributes_csv = implode(',', $default_attributes);
         $availableQuantity = Tienda::getClass('TiendaHelperProduct', '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'] : JRequest::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 = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
     }
     $vars->availableQuantity = $availableQuantity;
     $vars->invalidQuantity = $invalidQuantity;
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('tienda');
     ob_start();
     $dispatcher->trigger('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;
 }
Пример #9
0
 /**
  * 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;
 }