/** * Get _gaq options list * * @return array */ protected function getGaqOptions() { $list = array(sprintf('\'_setAccount\', \'%s\'', \XLite\Core\Config::getInstance()->CDev->GoogleAnalytics->ga_account)); if (2 == \XLite\Core\Config::getInstance()->CDev->GoogleAnalytics->ga_tracking_type) { $list[] = '\'_setDomainName\', \'.\' + self.location.host.replace(/^[^\\.]+\\./, \'\')'; } elseif (3 == \XLite\Core\Config::getInstance()->CDev->GoogleAnalytics->ga_tracking_type) { $list[] = '\'_setDomainName\', \'none\''; $list[] = '\'_setAllowLinker\', true'; } $list[] = '\'_trackPageview\''; $controller = \XLite::getController(); if ($this->isEcommercePartEnabled() && $controller instanceof \XLite\Controller\Customer\CheckoutSuccess) { $orders = \XLite\Core\Session::getInstance()->gaProcessedOrders; if (!is_array($orders)) { $orders = array(); } $order = $this->getOrder(); if ($order->getProfile() && !in_array($order->getOrderId(), $orders)) { $bAddress = $order->getProfile()->getBillingAddress(); $city = $bAddress ? $bAddress->getCity() : ''; $state = $bAddress && $bAddress->getState() ? $bAddress->getState()->getState() : ''; $country = $bAddress && $bAddress->getCountry() ? $bAddress->getCountry()->getCountry() : ''; $tax = $order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_TAX); $shipping = $order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_SHIPPING); $list[] = '\'_addTrans\', ' . '\'' . $order->getOrderNumber() . '\', ' . '\'' . $this->escapeJavascript(\XLite\Core\Config::getInstance()->Company->company_name) . '\', ' . '\'' . $order->getTotal() . '\', ' . '\'' . $tax . '\', ' . '\'' . $shipping . '\', ' . '\'' . $this->escapeJavascript($city) . '\', ' . '\'' . $this->escapeJavascript($state) . '\', ' . '\'' . $this->escapeJavascript($country) . '\''; foreach ($order->getItems() as $item) { $list[] = '\'_addItem\', ' . '\'' . $order->getOrderNumber() . '\', ' . '\'' . $this->escapeJavascript($item->getSku()) . '\', ' . '\'' . $this->escapeJavascript($item->getName()) . '\', ' . '\'\', ' . '\'' . $item->getPrice() . '\', ' . '\'' . $item->getAmount() . '\''; } $list[] = '\'_trackTrans\''; $orders[] = $order->getOrderId(); \XLite\Core\Session::getInstance()->gaProcessedOrders = $orders; } } return $list; }
/** * Validate return from Canada Post merchant registration process * * @return void */ protected function capostValidateMerchant() { $token = \XLite\Core\Request::getInstance()->{'token-id'}; $status = \XLite\Core\Request::getInstance()->{'registration-status'}; if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_SUCCESS === $status) { // Registration is complete // Send request to Canada Post server to retrieve merchant details $data = \XLite\Module\XC\CanadaPost\Core\Service\Platforms::getInstance()->callGetMerchantRegistrationInfoByToken($token); if (isset($data->merchantInfo)) { // Update Canada Post settings $this->updateCapostMerchantSettings($data->merchantInfo); // Disable wizard $this->disableCapostWizard(); \XLite\Core\TopMessage::getInstance()->addInfo('Registration process has been completed successfully.'); } else { foreach ($data->errors as $err) { \XLite\Core\TopMessage::getInstance()->addError('ERROR: [' . $err->code . '] ' . $err->description); } } } else { // An error occurred if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_CANCELLED === $status) { \XLite\Core\TopMessage::getInstance()->addError('Registration process has been canceled.'); } else { \XLite\Core\TopMessage::getInstance()->addError('Failure to finish registration process.'); } } // Remove token from the session \XLite\Core\Session::getInstance()->capost_token_id = null; \XLite\Core\Session::getInstance()->capost_token_ts = null; // Redirect back to the Canada Post settings page $this->setReturnURL($this->buildURL('capost')); }
/** * Search total amount * * @return \Doctrine\ORM\PersistentCollection */ protected function getSearchTotals() { // Get search conditions $name = \XLite\View\ItemsList\Model\Order\Admin\Search::getSessionCellName(); $cnd = new \XLite\Core\CommonCell(\XLite\Core\Session::getInstance()->{$name}); return \XLite\Core\Database::getRepo('XLite\\Model\\Order')->getSearchTotal($cnd); }
/** * Return full URL for the resource * * @param string $url URL part to add OPTIONAL * @param boolean $isSecure Use HTTP or HTTPS OPTIONAL * @param array $params URL parameters OPTIONAL * @param string $output URL output type OPTIONAL * @param boolean $isSession Use session ID parameter OPTIONAL * @param boolean $isProtoRelative Use protocol-relative URL OPTIONAL * * @return string */ public static function getShopURL($url = '', $isSecure = null, array $params = array(), $output = null, $isSession = null, $isProtoRelative = false) { $url = trim($url); if (!preg_match('/^https?:\\/\\//Ss', $url)) { // We are using the protocol-relative URLs for resources $protocol = true === $isSecure || is_null($isSecure) && static::isHTTPS() ? 'https' : 'http'; if (!isset($output)) { $output = static::URL_OUTPUT_FULL; } $hostDetails = static::getOptions('host_details'); $host = $hostDetails[$protocol . '_host']; if ($host) { if ('/' != substr($url, 0, 1)) { $url = $hostDetails['web_dir_wo_slash'] . '/' . $url; } $isSession = !isset($isSession) ? true === $isSecure && !static::isHTTPS() : $isSession; if ($isSession) { $session = \XLite\Core\Session::getInstance(); $url .= (false !== strpos($url, '?') ? '&' : '?') . $session->getName() . '=' . $session->getID(); } foreach ($params as $name => $value) { $url .= (false !== strpos($url, '?') ? '&' : '?') . $name . '=' . $value; } if (static::URL_OUTPUT_FULL == $output) { if (substr($url, 0, 2) != '//') { $url = '//' . $host . $url; } $url = ($isProtoRelative ? '' : $protocol . ':') . $url; } } } return $url; }
/** * Handles the request. * Parses the request variables if necessary. Attempts to call the specified action function * * @return void */ public function handleRequest() { if (\XLite\Core\Session::getInstance()->inContextRedirect) { unset(\XLite\Core\Session::getInstance()->inContextRedirect); } parent::handleRequest(); }
/** * Preprocessor for no-action ren * * @return void */ protected function doNoAction() { parent::doNoAction(); if (!\XLite\Core\Request::getInstance()->isAJAX()) { \XLite\Core\Session::getInstance()->productListURL = $this->getURL(); } }
/** * Return full URL for the resource * * @param string $url URL part to add OPTIONAL * @param boolean $isSecure Use HTTP or HTTPS OPTIONAL * @param array $params URL parameters OPTIONAL * @param string $output URL output type OPTIONAL * @param boolean $isSession Use session ID parameter OPTIONAL * * @return string */ public static function getShopURL($url = '', $isSecure = null, array $params = array(), $output = null, $isSession = null) { if (!preg_match('/^https?:\\/\\//Ss', $url)) { if (!isset($isSecure)) { $isSecure = static::isHTTPS(); } if (!isset($output)) { $output = static::URL_OUTPUT_FULL; } $hostDetails = \Includes\Utils\ConfigParser::getOptions('host_details'); $host = $hostDetails['http' . ($isSecure ? 's' : '') . '_host']; if ($host) { $proto = ($isSecure ? 'https' : 'http') . '://'; if ('/' != substr($url, 0, 1)) { $url = $hostDetails['web_dir_wo_slash'] . '/' . $url; } $isSession = is_null($isSession) ? $isSecure : $isSession; if ($isSession) { $session = \XLite\Core\Session::getInstance(); $url .= (false !== strpos($url, '?') ? '&' : '?') . $session->getName() . '=' . $session->getID(); } foreach ($params as $name => $value) { $url .= (false !== strpos($url, '?') ? '&' : '?') . $name . '=' . $value; } if (static::URL_OUTPUT_FULL == $output) { $url = $proto . $host . $url; } } } return $url; }
/** * Preprocessor for no-action run * * @return void */ protected function doNoAction() { if (\XLite\Core\Session::getInstance()->inContextRedirect) { unset(\XLite\Core\Session::getInstance()->inContextRedirect); echo <<<HTML <html><head></head><body> <script type="text/javascript"> (function(d, s, id){ var js, ref = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)){ js = d.createElement(s); js.id = id; js.async = true; js.src = "//www.paypalobjects.com/js/external/paypal.v1.js"; ref.parentNode.insertBefore(js, ref); } }(document, "script", "paypal-js")); </script> </body></html> HTML; exit; } elseif (\XLite\Core\Session::getInstance()->cancelUrl) { $this->setReturnURL(\XLite\Core\Session::getInstance()->cancelUrl); unset(\XLite\Core\Session::getInstance()->cancelUrl); } else { parent::doNoAction(); } }
/** * Define widget parameters * * @return void */ protected function defineWidgetParams() { parent::defineWidgetParams(); $this->widgetParams[self::PARAM_PARAMS]->setValue(array('target' => 'order_list', 'mode' => 'search')); $this->widgetParams[self::PARAM_SORT_CRITERIONS]->setValue(array('order_id' => 'Order id', 'date' => 'Date', 'status' => 'Status', 'total' => 'Total')); $this->widgetParams[self::PARAM_CELL]->setValue(\XLite\Core\Session::getInstance()->orders_search); }
/** * Preprocessor for no-action ren * * @return void */ protected function doNoAction() { parent::doNoAction(); if (!\XLite\Core\Request::getInstance()->isAJAX()) { \XLite\Core\Session::getInstance()->continueShoppingURL = $this->getURL(); } }
/** * Add codes from csv file * * @return void */ protected function doActionImport() { $stream = fopen(\XLite\Core\Session::getInstance()->pinCodesImportFile, 'r'); $this->addFromStreamAction($stream); if ($stream) { fclose($stream); } $this->setReturnUrl($this->buildUrl('product', '', array('product_id' => \XLite\Core\Request::getInstance()->product_id, 'page' => 'pin_codes'))); }
/** * Get search conditions * * @return array */ protected function getConditions() { $cellName = \XLite\View\ItemsList\Model\AttributeOption::getSessionCellName(); $searchParams = \XLite\Core\Session::getInstance()->{$cellName}; if (!is_array($searchParams)) { $searchParams = array(); } return $searchParams; }
/** * Change template * * @return void */ protected function doActionChangeTemplate() { \XLite\Core\Request::getInstance()->switch = $this->getSwitchData(); unset(\XLite\Core\Session::getInstance()->returnURL); $controller = new \XLite\Controller\Admin\AddonsListInstalled(\XLite\Core\Request::getInstance()->getData()); $controller->init(); $controller->doActionSwitch(); $this->setReturnURL($this->buildURL('layout', '', array('moduleId' => \Xlite\Core\Request::getInstance()->template))); }
/** * Get filter values * * @return array */ protected function getFilterValues() { $filterValues = array(); if ('category_filter' == $this->getTarget()) { $cellName = \XLite\Module\XC\ProductFilter\View\ItemsList\Product\Customer\Category\CategoryFilter::getSessionCellName(); $filterValues = \XLite\Core\Session::getInstance()->{$cellName}; $filterValues = is_array($filterValues) && isset($filterValues['filter']) && is_array($filterValues['filter']) ? $filterValues['filter'] : array(); } return $filterValues; }
/** * Get continue URL * * @return string */ protected function getContinueURL() { if (\XLite\Core\Session::getInstance()->continueShoppingURL) { $url = $this->getURL(\XLite\Core\Session::getInstance()->continueShoppingURL); } elseif (isset($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; } else { $url = $this->buildURL(); } return $url; }
/** * Add language subquery with language code relation * * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder * @param string $alias Main model alias OPTIONAL * @param string $code Language code OPTIONAL * * @return \Doctrine\ORM\QueryBuilder */ protected function addLanguageQuery(\Doctrine\ORM\QueryBuilder $queryBuilder, $alias = null, $code = null, $translationsAlias = 'translations') { if (!isset($alias)) { $alias = $this->getMainAlias($queryBuilder); } if (!isset($code)) { $code = !\XLite::isCacheBuilding() && \XLite\Core\Session::getInstance()->getLanguage() ? \XLite\Core\Session::getInstance()->getLanguage()->getCode() : 'en'; } $queryBuilder->leftJoin($alias . '.translations', $translationsAlias, \Doctrine\ORM\Query\Expr\Join::WITH, $translationsAlias . '.code = :lng')->setParameter('lng', $code); return $queryBuilder; }
/** * Return URL to redirect to * * @return string */ protected function getAdminAreaURLArgs() { $query = ''; if (\XLite\Core\Auth::getInstance()->isAdmin()) { $query .= '?' . \XLite\Core\Session::getInstance()->getName(); $query .= '=' . \XLite\Core\Session::getInstance()->getId(); $query .= '&' . static::PARAM_DRUPAL_RETURN_URL; $query .= '=' . urlencode(\Includes\Utils\URLManager::getCurrentURL()); } return $query; }
protected function doActionGetTree() { $treeKey = \XLite\Core\Request::getInstance()->treeKey; $session = \XLite\Core\Session::getInstance(); if ($treeKey && $session->{$treeKey}) { header('Content-type: application/json'); echo $session->{$treeKey}; unset($session->{$treeKey}); exit; } }
/** * Handles the request. * Parses the request variables if necessary. Attempts to call the specified action function * * @return void */ public function handleRequest() { \XLite\Core\Session::getInstance()->iframePaymentData = null; // security check on return page $orderId = \XLite\Core\Request::getInstance()->order_id; if ($orderId != \XLite\Core\Session::getInstance()->last_order_id && $orderId != $this->getCart()->getOrderId()) { $this->redirect($this->buildURL('cart')); } else { parent::handleRequest(); } }
/** * Get continue URL * * @return string */ public function getContinueURL() { $url = \XLite\Core\Session::getInstance()->continueURL; if (!$url && isset($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; } if (!$url) { $url = $this->buildURL('main'); } return $url; }
/** * Return false if Express Checkout shortcut is selected by customer * * @return boolean */ protected function isNeedReplaceLabel() { $result = parent::isNeedReplaceLabel(); if ($result) { $cart = $this->getCart(); if ($cart->isExpressCheckout($cart->getPaymentMethod()) && ExpressCheckoutProcessor::EC_TYPE_SHORTCUT == \XLite\Core\Session::getInstance()->ec_type) { $result = false; } } return $result; }
/** * Search labels * * @return void */ protected function doActionSearch() { $search = array(); $searchParams = \XLite\View\ItemsList\Model\Country::getSearchParams(); foreach ($searchParams as $modelParam => $requestParam) { if (isset(\XLite\Core\Request::getInstance()->{$requestParam})) { $search[$requestParam] = \XLite\Core\Request::getInstance()->{$requestParam}; } } $name = \XLite\View\ItemsList\Model\Country::getSessionCellName(); \XLite\Core\Session::getInstance()->{$name} = $search; }
/** * Get stored profiel id * * @return integer */ protected function getStoredProfileId() { $profileId = parent::getStoredProfileId(); if (!$profileId && \XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS() && !empty($GLOBALS['user']) && !empty($GLOBALS['user']->uid)) { $profileId = \XLite\Module\CDev\DrupalConnector\Handler::getInstance()->getProfileIdByCMSId($GLOBALS['user']->uid); if ($profileId) { // Save profile Id in session \XLite\Core\Session::getInstance()->profile_id = $profileId; } } return $profileId; }
/** * Find labels by language code * * @param string $code Language code OPTIONAL * * @return array */ public function findLabelsByCode($code = null) { if (!isset($code)) { $code = \XLite\Core\Session::getInstance()->getLanguage()->getCode(); } $data = $this->getFromCache('all_by_code', array('code' => $code)); if (!isset($data)) { $data = $this->defineLabelsByCodeQuery($code)->getResult(); $data = $this->postprocessLabelsByCode($data, $code); $this->saveToCache($data, 'all_by_code', array('code' => $code)); } return $data; }
/** * Get a list of JS files required to display the widget properly * FIXME - decompose these files * * @return array */ public function getJSFiles() { $list = parent::getJSFiles(); $list[] = 'checkout/controller.js'; $list[] = 'button/js/login.js'; if ($checkoutCanceled = \XLite\Core\Session::getInstance()->checkoutCanceled && \XLite\Core\Request::getInstance()->checkoutCanceled) { $list[] = 'back_from_payment/controller.js'; } if (!$this->isCheckoutAvailable()) { $list[] = 'checkout/login.js'; } return $list; }
/** * Define Open Graph meta tags * * @return array */ protected function defineOpenGraphMetaTags() { $language = \XLite\Core\Session::getInstance()->getLanguage(); $list = array('og:title' => $this->getName(), 'og:type' => 'article', 'og:url' => '[PAGE_URL]', 'og:site_name' => \XLite\Core\Config::getInstance()->Company->company_name, 'og:description' => $this->getBriefDescription(), 'og:locale' => 'en_US'); if ($this->getImage()) { $list['og:image'] = '[IMAGE_URL]'; } if (\XLite\Core\Config::getInstance()->CDev->GoSocial->fb_app_id) { $list['fb:app_id'] = \XLite\Core\Config::getInstance()->CDev->GoSocial->fb_app_id; } elseif (\XLite\Core\Config::getInstance()->CDev->GoSocial->fb_admins) { $list['fb:admins'] = \XLite\Core\Config::getInstance()->CDev->GoSocial->fb_admins; } return $list; }
/** * Do action filter * * @return void */ protected function doActionFilter() { $sessionCell = $this->isAJAX() ? \XLite\Module\XC\ProductFilter\View\ItemsList\Product\Customer\Category\CategoryFilter::getSessionCellName() : \XLite\View\ItemsList\Product\Customer\Category\Main::getSessionCellName(); $data = \XLite\Core\Session::getInstance()->{$sessionCell}; if (!is_array($data)) { $data = array(); } $data['filter'] = \XLite\Core\Request::getInstance()->filter; if (!$this->isAJAX()) { $sessionCell = \XLite\Module\XC\ProductFilter\View\ItemsList\Product\Customer\Category\CategoryFilter::getSessionCellName(); } \XLite\Core\Session::getInstance()->{$sessionCell} = $data; $this->setReturnURL($this->buildURL('category_filter', '', array('category_id' => \XLite\Core\Request::getInstance()->category_id))); }
/** * Get data atttributes * * @return array */ protected function getDataAtttributes() { $total = $this->getCart()->getCurrency()->roundValue($this->getCart()->getFirstOpenPaymentTransaction()->getValue()); $method = $this->getCart()->getPaymentMethod(); $suffix = $method->getProcessor()->isTestMode($method) ? 'Test' : ''; $description = static::t('X items ($)', array('count' => $this->getCart()->countQuantity(), 'total' => $this->formatPrice($total, $this->getCart()->getCurrency()))); $data = array('data-key' => $this->getCart()->getPaymentMethod()->getSetting('publishKey' . $suffix), 'data-name' => \XLite\Core\Config::getInstance()->Company->company_name, 'data-description' => $description, 'data-total' => $this->getCart()->getCurrency()->roundValueAsInteger($total), 'data-currency' => $this->getCart()->getCurrency()->getCode()); if (\XLite\Core\Session::getInstance()->checkoutEmail) { $data['data-email'] = \XLite\Core\Session::getInstance()->checkoutEmail; } elseif ($this->getCart()->getProfile()) { $data['data-email'] = $this->getCart()->getProfile()->getLogin(); } return $data; }
protected function getTestSession() { $id = \XLite\Core\Session::getInstance()->getID(); foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Session')->findAll() as $s) { if ($s->getSid() != $id) { \XLite\Core\Database::getEM()->remove($s); } } \XLite\Core\Database::getEM()->flush(); $session = new \XLite\Model\Session(); $session->map($this->testSession); \XLite\Core\Database::getEM()->persist($session); \XLite\Core\Database::getEM()->flush(); return $session; }
/** * Handles the request. * Parses the request variables if necessary. Attempts to call the specified action function * * @return void */ public function handleRequest() { if (\XLite\Core\Session::getInstance()->xpc_order_create_profile && $this->getOrder() && $this->getOrder()->getOrderId() && (!\XLite\Core\Session::getInstance()->last_order_id || !$this->getCart()->getOrderId())) { $this->getCart()->setOrderId($this->getOrder()->getOrderId()); \XLite\Core\Session::getInstance()->last_order_id = $this->getOrder()->getOrderId(); parent::handleRequest(); $this->getCart()->setOrderId(null); \XLite\Core\Session::getInstance()->last_order_id = null; \XLite\Core\Session::getInstance()->xpc_order_create_profile = null; // Cleanup fake carts from session \XLite\Module\CDev\XPaymentsConnector\Core\ZeroAuth::cleanupFakeCarts($this->getProfile()); } else { parent::handleRequest(); } }