Esempio n. 1
0
 public function variants()
 {
     hikashop_nocache();
     JRequest::setVar('layout', 'form_variants');
     $product_id = JRequest::getInt('product_id', 0);
     $subtask = JRequest::getCmd('subtask', '');
     if (!empty($subtask)) {
         switch ($subtask) {
             case 'setdefault':
                 $variant_id = JRequest::getInt('variant_id');
                 $productClass = hikashop_get('class.product');
                 $ret = $productClass->setDefaultVariant($product_id, $variant_id);
                 break;
             case 'publish':
                 $variant_id = JRequest::getInt('variant_id');
                 $productClass = hikashop_get('class.product');
                 $ret = $productClass->publishVariant($variant_id);
                 break;
             case 'add':
             case 'duplicate':
                 JRequest::checkToken('request') || die('Invalid Token');
                 JRequest::setVar('layout', 'form_variants_add');
                 break;
             case 'delete':
                 JRequest::checkToken('request') || die('Invalid Token');
                 $cid = JRequest::getVar('cid', array(), '', 'array');
                 if (empty($cid)) {
                     ob_end_clean();
                     echo '0';
                     exit;
                 }
                 $productClass = hikashop_get('class.product');
                 $ret = $productClass->deleteVariants($product_id, $cid);
                 ob_end_clean();
                 if ($ret !== false) {
                     echo $ret;
                 } else {
                     echo '0';
                 }
                 exit;
             case 'populate':
                 JRequest::checkToken('request') || die('Invalid Token');
                 JRequest::setVar('layout', 'form_variants_add');
                 $productClass = hikashop_get('class.product');
                 $data = JRequest::getVar('data', array(), '', 'array');
                 if (isset($data['variant_duplicate'])) {
                     $cid = JRequest::getVar('cid', array(), '', 'array');
                     JArrayHelper::toInteger($cid);
                     $ret = $productClass->duplicateVariant($product_id, $cid, $data);
                 } else {
                     $ret = $productClass->populateVariant($product_id, $data);
                 }
                 if ($ret !== false) {
                     ob_end_clean();
                     echo $ret;
                     exit;
                 }
                 break;
         }
     }
     if (JRequest::getCmd('tmpl', '') == 'component') {
         ob_end_clean();
         parent::display();
         exit;
     }
     return parent::display();
 }
Esempio n. 2
0
 function cart()
 {
     hikashop_nocache();
     $module = hikashop_get('helper.module');
     $module->initialize($this, false);
     $app = JFactory::getApplication();
     $database = JFactory::getDBO();
     $this->assignRef('app', $app);
     $config = hikashop_config();
     $this->assignRef('config', $config);
     $this->loadRef(array('popup' => 'helper.popup'));
     $cartClass = hikashop_get('class.cart');
     $cart_type = $this->params->get('cart_type', 'cart');
     $this->assignRef('cart_type', $cart_type);
     if (!in_array($cart_type, array('cart', 'wishlist'))) {
         $cart_type = 'cart';
     }
     $cart_id = $app->getUserState(HIKASHOP_COMPONENT . '.' . $cart_type . '_id', 0, 'int');
     $cartClass->get($cart_id, true, $cart_type);
     $full = $cartClass->loadFullCart(true, true, true);
     $rows = $full->products;
     $total = new stdClass();
     if (!empty($rows)) {
         $this->loadRef(array('currencyClass' => 'class.currency', 'productClass' => 'class.product', 'imageHelper' => 'helper.image'));
         $this->currencyHelper = $this->currencyClass;
         $this->image = $this->imageHelper;
         foreach ($rows as $k => $row) {
             if ($cart_type != 'wishlist' && $row->cart_product_quantity == 0) {
                 $rows[$k]->hide = 1;
             } else {
                 if ($cart_type == 'wishlist' && $row->product_type == 'variant' && !empty($row->cart_product_parent_id) && isset($rows[$row->cart_product_parent_id])) {
                     $rows[$row->cart_product_parent_id]->hide = 1;
                 }
             }
         }
     }
     if ($this->params->get('show_shipping') || $this->params->get('show_coupon')) {
         $total =& $full->full_total;
     } else {
         $total =& $full->total;
     }
     $this->assignRef('element', $full);
     $this->assignRef('total', $total);
     $this->assignRef('rows', $rows);
     $cartHelper = hikashop_get('helper.cart');
     $this->assignRef('cartHelper', $cartHelper);
     $this->cart = $this->cartHelper;
     $cartHelper->cartCount(true);
     $url = $this->init(true);
     $this->params->set('url', $url);
     ob_start();
     $cartHelper->getJS($url, false);
     $notice_html = ob_get_clean();
     $this->assignRef('notice_html', $notice_html);
     if (hikashop_level(2)) {
         $null = null;
         $fieldsClass = hikashop_get('class.field');
         $this->assignRef('fieldsClass', $fieldsClass);
         $itemFields = $fieldsClass->getFields('frontcomp', $null, 'item', 'checkout&task=state');
         $this->assignRef('itemFields', $itemFields);
     }
     $this->legacyCartInit();
 }
Esempio n. 3
0
 public function updatecart()
 {
     hikashop_nocache();
     $app = JFactory::getApplication();
     $product_id = (int) JRequest::getCmd('product_id', 0);
     $module_id = (int) JRequest::getCmd('module_id', 0);
     $cart_type = JRequest::getString('hikashop_cart_type_' . $product_id . '_' . $module_id, 'null');
     if ($cart_type == 'null') {
         $cart_type = JRequest::getString('hikashop_cart_type_' . $module_id, 'null');
     }
     if ($cart_type == 'null') {
         $cart_type = JRequest::getString('cart_type', 'cart');
     }
     $cart_type_id = $cart_type . '_id';
     $class = hikashop_get('class.cart');
     $class->cart_type = $cart_type;
     $cart_id = 0;
     if ($class->hasCart(JRequest::getInt('cart_id', 0, 'GET'))) {
         $cart_id = $class->cart->cart_id;
     }
     $addTo = JRequest::getString('add_to', '');
     if ($addTo != '') {
         $from_id = $cart_id;
         if ($addTo == 'cart') {
             JRequest::setVar('from_id', $cart_id);
         }
         $cart_id = $app->getUserState(HIKASHOP_COMPONENT . '.' . $addTo . '_id', 0);
         $cart_type_id = $addTo . '_id';
         JRequest::setVar('cart_type', $addTo);
     } else {
         JRequest::setVar('cart_type', $cart_type);
     }
     JRequest::setVar($cart_type_id, $cart_id);
     $char = JRequest::getString('characteristic', '');
     if (!empty($char)) {
         return $this->show();
     }
     $tmpl = JRequest::getCmd('tmpl', 'index');
     $add = JRequest::getCmd('add', '');
     if (!empty($add)) {
         $add = 1;
     } else {
         $add = 0;
     }
     if (empty($product_id)) {
         $product_id = JRequest::getCmd('cid', 0);
     }
     $cart_product_id = JRequest::getCmd('cart_product_id', 0);
     $quantity = JRequest::getInt('quantity', 1);
     if (hikashop_loadUser() != null || $cart_type != 'wishlist') {
         if (!empty($product_id)) {
             $type = JRequest::getWord('type', 'product');
             if ($type == 'product') {
                 $product_id = (int) $product_id;
             }
             $status = $class->update($product_id, $quantity, $add, $type);
         } elseif (!empty($cart_product_id)) {
             $status = $class->update($cart_product_id, $quantity, $add, 'item');
         } else {
             $formData = JRequest::getVar('item', array(), '', 'array');
             if (!empty($formData)) {
                 $class->update($formData, 0, $add, 'item');
             } else {
                 $formData = JRequest::getVar('data', array(), '', 'array');
                 if (!empty($formData)) {
                     $class->update($formData, 0, $add);
                 }
             }
         }
     }
     $app->setUserState(HIKASHOP_COMPONENT . '.' . $cart_type . '_new', '1');
     if (@$class->errors && $tmpl != 'component') {
         if (!empty($_SERVER['HTTP_REFERER'])) {
             if (strpos($_SERVER['HTTP_REFERER'], HIKASHOP_LIVE) === false && preg_match('#^https?://.*#', $_SERVER['HTTP_REFERER'])) {
                 return false;
             }
             $app->redirect(str_replace('&popup=1', '', $_SERVER['HTTP_REFERER']));
         } else {
             echo '<html><head><script type="text/javascript">history.back();</script></head><body></body></html>';
             exit;
         }
     }
     $app->setUserState(HIKASHOP_COMPONENT . '.shipping_method', null);
     $app->setUserState(HIKASHOP_COMPONENT . '.shipping_id', null);
     $app->setUserState(HIKASHOP_COMPONENT . '.shipping_data', null);
     $app->setUserState(HIKASHOP_COMPONENT . '.payment_method', null);
     $app->setUserState(HIKASHOP_COMPONENT . '.payment_id', null);
     $app->setUserState(HIKASHOP_COMPONENT . '.payment_data', null);
     $config =& hikashop_config();
     $checkout = JRequest::getString('checkout', '');
     if (!empty($checkout)) {
         global $Itemid;
         $url = 'checkout';
         if (!empty($Itemid)) {
             $url .= '&Itemid=' . $Itemid;
         }
         $url = hikashop_completeLink($url, false, true);
         $this->setRedirect($url);
     } else {
         if ($cart_type == 'wishlist') {
             $app->setUserState(HIKASHOP_COMPONENT . '.popup_cart_type', 'wishlist');
             if (hikashop_loadUser() == null) {
                 $url = JRequest::getVar('return_url', '');
                 if (!empty($url)) {
                     $url = base64_decode(urldecode($url));
                 }
                 $url = str_replace(array('&popup=1', '?popup=1'), '', $url);
                 if ($config->get('redirect_url_after_add_cart', 'stay_if_cart') != 'ask_user') {
                     $app->enqueueMessage(JText::_('LOGIN_REQUIRED_FOR_WISHLISTS'));
                 }
                 if ($tmpl != 'component') {
                     if (!empty($_SERVER['HTTP_REFERER'])) {
                         if (strpos($_SERVER['HTTP_REFERER'], HIKASHOP_LIVE) === false && preg_match('#^https?://.*#', $_SERVER['HTTP_REFERER'])) {
                             return false;
                         }
                         if ($config->get('redirect_url_after_add_cart', 'stay_if_cart') == 'ask_user') {
                             $app->enqueueMessage(JText::_('LOGIN_REQUIRED_FOR_WISHLISTS'));
                         }
                         $app->redirect(str_replace('&popup=1', '', $_SERVER['HTTP_REFERER']));
                     }
                 } else {
                     echo 'notLogged';
                     exit;
                 }
             } else {
                 $redirectConfig = $config->get('redirect_url_after_add_cart', 'stay_if_cart');
                 $url = '';
                 $stay = 0;
                 switch ($redirectConfig) {
                     case 'ask_user':
                         $url = JRequest::getVar('return_url', '');
                         if (!empty($url)) {
                             $url = base64_decode(urldecode($url));
                         }
                         $url = str_replace(array('&popup=1', '?popup=1'), '', $url);
                         if (JRequest::getInt('popup', 0) && empty($_COOKIE['popup']) || JRequest::getInt('quantity', 0)) {
                             if (strpos($url, '?')) {
                                 $url .= '&';
                             } else {
                                 $url .= '?';
                             }
                             $url .= 'popup=1';
                             $app->setUserState(HIKASHOP_COMPONENT . '.popup', '1');
                         }
                         JRequest::setVar('cart_type', 'wishlist');
                         break;
                     case 'stay':
                         $stay = 1;
                         break;
                         //$stay = 1; && $url ='';
                     //$stay = 1; && $url ='';
                     case 'checkout':
                         break;
                         //$stay = 0; && $url ='';
                     //$stay = 0; && $url ='';
                     case 'stay_if_cart':
                     default:
                         $module = JModuleHelper::getModule('hikashop_wishlist', false);
                         if ($module != null) {
                             $stay = 1;
                         }
                         break;
                 }
                 if ($redirectConfig != 'checkout') {
                     $module = JModuleHelper::getModule('hikashop_wishlist', false);
                     $params = new HikaParameter(@$module->params);
                     if (!empty($module)) {
                         $module_options = $config->get('params_' . $module->id);
                     }
                     if (empty($module_options)) {
                         $module_options = $config->get('default_params');
                     }
                     $data = $params->get('hikashopwishlistmodule');
                     if (HIKASHOP_J30 && (empty($data) || !is_object($data))) {
                         $db = JFactory::getDBO();
                         $query = 'SELECT params FROM ' . hikashop_table('modules', false) . ' WHERE id = ' . (int) $module->id;
                         $db->setQuery($query);
                         $itemData = json_decode($db->loadResult());
                         if (!empty($itemData->hikashopwishlistmodule) && is_object($itemData->hikashopwishlistmodule)) {
                             $data = $itemData->hikashopwishlistmodule;
                             $params->set('hikashopwishlistmodule', $data);
                         }
                     }
                     if (!empty($data) && is_object($data)) {
                         foreach ($data as $k => $v) {
                             $module_options[$k] = $v;
                         }
                     }
                     foreach ($module_options as $key => $optionElement) {
                         $params->set($key, $optionElement);
                     }
                     if (!empty($module)) {
                         foreach (get_object_vars($module) as $k => $v) {
                             if (!is_object($v)) {
                                 $params->set($k, $v);
                             }
                         }
                         $params->set('from', 'module');
                     }
                     $params->set('return_url', $url);
                     $params->set('cart_type', 'wishlist');
                     $js = '';
                     hikashop_getLayout('product', 'cart', $params, $js);
                 }
             }
             if (empty($url)) {
                 global $Itemid;
                 if (isset($from_id)) {
                     $cart_id = $from_id;
                 }
                 if (JRequest::getInt('new_' . $cart_type . '_id', 0) != 0 && JRequest::getInt('delete', 0) == 0) {
                     $cart_id = JRequest::getInt('new_' . $cart_type . '_id', 0);
                 }
                 $cart = $class->get($cart_id, false, $cart_type);
                 if (!empty($cart) && (int) $cart_id != 0) {
                     $url = 'cart&task=showcart&cart_type=wishlist&cart_id=' . $cart_id . '&Itemid=' . $Itemid;
                 } else {
                     $url = 'cart&task=showcarts&cart_type=wishlist&Itemid=' . $Itemid;
                 }
                 $url = hikashop_completeLink($url, false, true);
             }
             if (!isset($stay)) {
                 $stay = JRequest::getInt('stay', 0);
             }
             if ($stay == 0) {
                 if (hikashop_disallowUrlRedirect($url)) {
                     return false;
                 }
                 if (JRequest::getVar('from_form', true)) {
                     JRequest::setVar('cart_type', 'wishlist');
                     $this->setRedirect($url);
                     return false;
                 } else {
                     ob_clean();
                     echo 'URL|' . $url;
                     exit;
                 }
             } else {
                 echo '<html><head><script type="text/javascript">history.back();</script></head><body></body></html>';
                 exit;
             }
         } else {
             $app->setUserState(HIKASHOP_COMPONENT . '.popup_cart_type', 'cart');
             $url = JRequest::getVar('return_url', '');
             if (empty($url)) {
                 $url = JRequest::getVar('url', '');
                 $url = urldecode($url);
             } else {
                 $url = base64_decode(urldecode($url));
             }
             $url = str_replace(array('&popup=1', '?popup=1'), '', $url);
             if (hikashop_disallowUrlRedirect($url)) {
                 $url = '';
             }
             if (empty($url)) {
                 global $Itemid;
                 $url = 'checkout';
                 if (!empty($Itemid)) {
                     $url .= '&Itemid=' . $Itemid;
                 }
                 $url = hikashop_completeLink($url, false, true);
             }
             $params = new HikaParameter(@$module->params);
             if ($tmpl == 'component' && $config->get('redirect_url_after_add_cart', 'stay_if_cart') != 'checkout') {
                 $js = '';
                 jimport('joomla.application.module.helper');
                 global $Itemid;
                 if (isset($Itemid) && empty($Itemid)) {
                     $Itemid = null;
                     JRequest::setVar('Itemid', null);
                 }
                 $module = JModuleHelper::getModule('hikashop_cart', false);
                 $config =& hikashop_config();
                 $params = new HikaParameter(@$module->params);
                 if (!empty($module)) {
                     $module_options = $config->get('params_' . $module->id);
                 }
                 if (empty($module_options)) {
                     $module_options = $config->get('default_params');
                 }
                 $data = $params->get('hikashopcartmodule');
                 if (HIKASHOP_J30 && (empty($data) || !is_object($data))) {
                     $db = JFactory::getDBO();
                     $query = 'SELECT params FROM ' . hikashop_table('modules', false) . ' WHERE id = ' . (int) $module->id;
                     $db->setQuery($query);
                     $itemData = json_decode($db->loadResult());
                     if (!empty($itemData->hikashopcartmodule) && is_object($itemData->hikashopcartmodule)) {
                         $data = $itemData->hikashopcartmodule;
                         $params->set('hikashopcartmodule', $data);
                     }
                 }
                 if (!empty($data) && is_object($data)) {
                     foreach ($data as $k => $v) {
                         $module_options[$k] = $v;
                     }
                 }
                 foreach ($module_options as $key => $optionElement) {
                     $params->set($key, $optionElement);
                 }
                 if (!empty($module)) {
                     foreach (get_object_vars($module) as $k => $v) {
                         if (!is_object($v)) {
                             $params->set($k, $v);
                         }
                     }
                     $params->set('from', 'module');
                 }
                 $params->set('return_url', $url);
                 hikashop_getLayout('product', 'cart', $params, $js);
                 return true;
             } else {
                 $config =& hikashop_config();
                 $url = str_replace(array('&popup=1', '?popup=1'), '', $url);
                 if (JRequest::getInt('popup', 0) || @JRequest::getInt('quantity', 0) && $config->get('redirect_url_after_add_cart', 'stay_if_cart') == 'ask_user') {
                     if (strpos($url, '?')) {
                         $url .= '&';
                     } else {
                         $url .= '?';
                     }
                     $url .= 'popup=1';
                     $app->setUserState(HIKASHOP_COMPONENT . '.popup', '1');
                 }
                 if (JRequest::getInt('hikashop_ajax', 0) == 0) {
                     // $config->get('ajax_add_to_cart','1') == '0'){
                     $this->setRedirect($url);
                     return false;
                 } else {
                     ob_clean();
                     if ($params->get('from', 'module') != 'module' || $config->get('redirect_url_after_add_cart', 'stay_if_cart') == 'checkout') {
                         echo 'URL|' . $url;
                         exit;
                     } else {
                         $this->setRedirect($url);
                         return false;
                     }
                 }
             }
         }
     }
 }