Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * 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 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;
 }