Example #1
0
 public function getVoucherTotals()
 {
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $cart_helper = J2store::cart();
     $params = J2Store::config();
     $items = $this->getItems();
     $voucher = FOFModel::getTmpInstance('Vouchers', 'J2StoreModel')->getVoucher($session->get('voucher', '', 'j2store'));
     if ($voucher === false) {
         $session->clear('voucher', 'j2store');
         $app->enqueueMessage(JText::_('J2STORE_INVALID_VOUCHER'), 'notice');
     }
     /* 	//check agianst the email
     		if(JString::strtolower($voucher->voucher_to_email) != JString::strtolower($this->user_email) && $session->has('voucher', 'j2store')) {
     			$voucher = false;
     			$app->enqueueMessage(JText::_('J2STORE_VOUCHER_WILL_APPLY_AFTER_LOGIN_OR_PROVIDING_BILLING_ADDRESS'), 'notice');
     		} */
     //voucher is validated. Apply it
     $voucher_total = 0;
     if ($voucher) {
         $voucher_total = $voucher->amount > $this->order_subtotal + $this->order_tax ? $this->order_subtotal + $this->order_tax : $voucher->amount;
         $voucherHistoryTable = F0FTable::getAnInstance('Voucherhistories', 'J2StoreTable');
         $voucherHistoryTable->voucher_id = $voucher->voucher_id;
         $voucherHistoryTable->voucher_code = $voucher->voucher_code;
         $voucherHistoryTable->voucher_to_email = $voucher->voucher_to_email;
         $voucherHistoryTable->amount = -$voucher_total;
         $this->_ordervouchers[$voucher->voucher_code] = $voucherHistoryTable;
         J2Store::plugin()->event("CalculateVoucherTotals", array($this));
     }
     return $voucher_total;
 }
Example #2
0
                $variant_model->setState('product_type', $item->product_type);
                $variants = $variant_model->product_id($item->j2store_product_id)->is_master(0)->getList();
                if (isset($variants) && count($variants)) {
                    foreach ($variants as $variant) {
                        ?>
										<tr class="variants-list">
											<td><?php 
                        echo J2Store::product()->getVariantNamesByCSV($variant->variant_name);
                        ?>
</td>
											<td><?php 
                        echo $variant->sku;
                        ?>
</td>
											<td><?php 
                        echo J2store::currency()->format($variant->price);
                        ?>
</td>
											<td><?php 
                        echo isset($variant->shipping) && $variant->shipping ? JText::_('J2STORE_YES') : JText::_('J2STORE_NO');
                        ?>
</td>
											<td><?php 
                        echo $variant->quantity;
                        ?>
</td>
										</tr>
										<?php 
                    }
                    ?>
										<?php 
Example #3
0
 private function processCustomFields($row, $type, $text)
 {
     if ($type == 'billing') {
         $field = 'all_billing';
     } elseif ($type == 'shipping') {
         $field = 'all_shipping';
     } elseif ($type == 'payment') {
         $field = 'all_payment';
     }
     $fields = array();
     if (!empty($row->{$field}) && JString::strlen($row->{$field}) > 0) {
         $custom_fields = $this->getDecodedFields($row->{$field});
         if (isset($custom_fields) && count($custom_fields)) {
             foreach ($custom_fields as $namekey => $field) {
                 if (!property_exists($row, $type . '_' . $namekey) && !property_exists($row, 'user_' . $namekey) && $namekey != 'country_id' && $namekey != 'zone_id' && $namekey != 'option' && $namekey != 'task' && $namekey != 'view') {
                     $fields[$namekey] = $field;
                 }
             }
         }
     }
     if (isset($fields) && count($fields)) {
         foreach ($fields as $namekey => $field) {
             $string = '';
             if (is_array($field['value'])) {
                 foreach ($field['value'] as $value) {
                     $string .= '-' . JText::_($value) . '\\n';
                 }
             } elseif (is_object($field['value'])) {
                 // convert the object into an array
                 $obj_array = JArrayHelper::fromObject($field['value']);
                 $string .= '\\n';
                 foreach ($obj_array as $value) {
                     $string .= '- ' . JText::_($value) . '\\n';
                 }
             } elseif (is_string($field['value']) && J2store::utilities()->isJson(stripslashes($field['value']))) {
                 $json_values = json_decode(stripslashes($field['value']));
                 if (is_array($json_values)) {
                     foreach ($json_values as $value) {
                         $string .= '-' . JText::_($value) . '\\n';
                     }
                 } else {
                     $string .= JText::_($field['value']);
                 }
             } else {
                 $string = JText::_($field['value']);
             }
             $value = JText::_($field['label']) . ' : ' . $string;
             $tag_value = '[CUSTOM_' . strtoupper($type) . '_FIELD:' . strtoupper($namekey) . ']';
             $text = str_replace($tag_value, $value, $text);
         }
     }
     return $text;
 }
Example #4
0
 public function view()
 {
     $product_id = $this->input->getInt('id');
     if (!$product_id) {
         $this->setRedirect(JRoute::_('index.php'));
         return;
     }
     //first clear cache
     J2Store::utilities()->nocache();
     J2Store::utilities()->clear_cache();
     $app = JFactory::getApplication();
     $view = $this->getThisView();
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     $ns = 'com_j2store.' . $this->getName();
     $params = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getMergedParams();
     if ($params->get('item_show_vote', 0)) {
         $params->set('show_vote', 1);
     }
     $product_helper = J2Store::product();
     //get product
     $product = $product_helper->setId($product_id)->getProduct();
     F0FModel::getTmpInstance('Products', 'J2StoreModel')->runMyBehaviorFlag(true)->getProduct($product);
     if ($product->visibility != 1 || $product->enabled != 1) {
         $this->setRedirect(JRoute::_('index.php'), JText::_('J2STORE_PRODUCT_NOT_ENABLED_CONTACT_SITE_ADMIN_FOR_MORE_DETAILS'), 'warning');
         return;
     }
     //run plugin events
     $model->executePlugins($product->source, $params, 'com_content.article.productlist');
     $product->product_short_desc = $model->runPrepareEventOnDescription($product->product_short_desc, $product->product_source_id, $params, 'com_content.article.productlist');
     $product->product_long_desc = $model->runPrepareEventOnDescription($product->product_long_desc, $product->product_source_id, $params, 'com_content.article.productlist');
     //get filters / specs by product
     $filters = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getProductFilters($product->j2store_product_id);
     //upsells
     $up_sells = array();
     if ($params->get('item_show_product_upsells', 0) && !empty($product->up_sells)) {
         $up_sells = $product_helper->getUpsells($product);
     }
     //cross sells
     $cross_sells = array();
     if ($params->get('item_show_product_cross_sells', 0) && !empty($product->cross_sells)) {
         $cross_sells = $product_helper->getCrossSells($product);
     }
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     // Look for template files in component folders
     $view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates');
     $view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates/default');
     // Look for overrides in template folder (J2 template structure)
     $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates');
     $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (Joomla! template structure)
     $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'default');
     $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store');
     // Look for specific J2 theme files
     if ($params->get('subtemplate')) {
         $view->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $params->get('subtemplate'));
         $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . $params->get('subtemplate'));
         $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . $params->get('subtemplate'));
     }
     //set up document
     // Check for layout override only if this is not the active menu item
     // If it is the active menu item, then the view and category id will match
     $active = $app->getMenu()->getActive();
     $menus = $app->getMenu();
     $pathway = $app->getPathway();
     $document = JFactory::getDocument();
     // Because the application sets a default page title,
     // we need to get it from the menu item itself
     $menu = $menus->getActive();
     $params->def('page_heading', $product->product_name);
     $params->set('page_title', $product->product_name);
     $title = $params->get('page_title', '');
     // Check for empty title and add site name if param is set
     if (empty($title)) {
         $title = $app->get('sitename');
     } elseif ($app->get('sitename_pagetitles', 0) == 1) {
         $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
     } elseif ($app->get('sitename_pagetitles', 0) == 2) {
         $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
     }
     $document->setTitle($title);
     if ($product->source->metadesc) {
         $document->setDescription($product->source->metadesc);
     } else {
         $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $product->source->introtext . ' ' . $product->source->fulltext);
         $metaDescItem = strip_tags($metaDescItem);
         $metaDescItem = J2Store::utilities()->characterLimit($metaDescItem, 150);
         $document->setDescription(html_entity_decode($metaDescItem));
     }
     if ($product->source->metakey) {
         $document->setMetadata('keywords', $product->source->metakey);
     } else {
         $keywords = $params->get('menu-meta_keywords');
         $document->setMetaData('keywords', $keywords);
     }
     $metadata = json_decode($product->source->metadata);
     if (isset($metadata->robots)) {
         $document->setMetaData('robots', $metadata->robots);
     } else {
         $robots = $params->get('robots');
         $document->setMetaData('robots', $robots);
     }
     // Set Facebook meta data
     $uri = JURI::getInstance();
     $document->setMetaData('og:title', $document->getTitle());
     $document->setMetaData('og:site_name', $app->get('sitename'));
     $document->setMetaData('og:description', strip_tags($document->getDescription()));
     $document->setMetaData('og:url', $uri->toString());
     $document->setMetaData('og:type', 'product');
     if (isset($product->main_image)) {
         $facebookImage = $product->main_image;
     } else {
         $facebookImage = $product->thumb_image;
     }
     if (!empty($facebookImage)) {
         if (JFile::exists(JPATH_SITE . '/' . $facebookImage)) {
             $image = substr(JURI::root(), 0, -1) . '/' . str_replace(JURI::root(true), '', $facebookImage);
             $document->setMetaData('og:image', $image);
             $document->setMetaData('image', $image);
         }
     }
     //set canonical url
     foreach ($document->_links as $key => $value) {
         if (is_array($value)) {
             if (array_key_exists('relation', $value)) {
                 if ($value['relation'] == 'canonical') {
                     // we found the document link that contains the canonical url
                     // change it!
                     $canonicalUrl = $uri->toString();
                     $document->_links[$canonicalUrl] = $value;
                     unset($document->_links[$key]);
                     break;
                 }
             }
         }
     }
     $back_link = $app->getMenu()->getActive()->link;
     $back_link_title = $app->getMenu()->getActive()->title;
     if (isset($back_link) && !empty($back_link_title)) {
         $view->assign('back_link', JRoute::_($back_link));
         $view->assign('back_link_title', $back_link_title);
     }
     //add a pathway
     $pathway = $app->getPathway();
     $path = array(array('title' => $product->product_name, 'link' => ''));
     if (isset($product->source->category_title)) {
         $path[] = array('title' => $product->source->category_title, 'link' => '');
         //JRoute::_('index.php?option=com_j2store&view=products&Itemid='.$app->getMenu()->getActive()->id)
     }
     $path = array_reverse($path);
     foreach ($path as $item) {
         $pathway->addItem($item['title'], $item['link']);
     }
     //add custom styles
     $custom_css = $params->get('custom_css', '');
     $document->addStyleDeclaration(strip_tags($custom_css));
     //allow plugins to modify the data
     J2Store::plugin()->event('ViewProduct', array(&$product, &$view));
     $view->assign('product', $product);
     $view->assign('filters', $filters);
     $view->assign('up_sells', $up_sells);
     $view->assign('cross_sells', $cross_sells);
     $view->assign('product_helper', $product_helper);
     $view->assign('params', $params);
     $view->assign('currency', J2store::currency());
     $view->setLayout('view');
     $view->display();
 }