public function testGetTotalRate() { $tax = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax')->getTax(); foreach ($tax->getRates() as $rate) { \XLite\Core\Database::getEM()->remove($rate); } $tax->getRates()->clear(); $tax->setEnabled(true); $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate(); $rate->setValue(10); $rate->setPosition(1); \XLite\Core\Database::getEM()->persist($rate); $tax->addRates($rate); $rate->setTax($tax); $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate(); $rate->setValue(20); $rate->setPosition(0); \XLite\Core\Database::getEM()->persist($rate); $tax->addRates($rate); $rate->setTax($tax); $memberships = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll(); $membership = array_shift($memberships); $rate->setMembership($membership); $tax->setVATMembership($membership); \XLite\Core\Database::getEM()->flush(); $method = new \XLite\Model\Shipping\Method(); $method->setEnabled(true); $rate = new \XLite\Model\Shipping\Rate(); $rate->setBaseRate(10); $rate->setMarkupRate(10); $rate->setMethod($method); $this->assertEquals(16.67, \XLite::getInstance()->getCurrency()->formatValue($rate->getTotalRate()), 'check cost'); }
/** * 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; }
/** * Get prepared pages array for tabber * * @return void */ protected function getTabberPages() { $pages = array(); $url = $this->get('url'); $switch = $this->getParam(self::PARAM_SWITCH); $functionName = $this->getParam(self::PARAM_TAB_PAGES); // $functionName - from PARAM_TAB_PAGES parameter $dialogPages = \XLite::getController()->{$functionName}(); if (is_array($dialogPages)) { foreach ($dialogPages as $page => $title) { $p = new \XLite\Base(); $pageURL = preg_replace('/' . $switch . '=(\\w+)/', $switch . '=' . $page, $url); $p->set('url', $pageURL); $p->set('title', $title); $pageSwitch = sprintf($switch . '=' . $page); $p->set('selected', preg_match('/' . preg_quote($pageSwitch) . '(\\Z|&)/Ss', $url)); $pages[] = $p; } } // if there is only one tab page, set it as a seleted with the default URL if (1 == count($pages) || 'default' === $this->getPage()) { $pages[0]->set('selected', $url); } return $pages; }
/** * Adds additional condition to the query for checking if method is enabled * * @param \Doctrine\ORM\QueryBuilder $qb Query builder object * @param string $alias Entity alias OPTIONAL * * @return \Doctrine\ORM\QueryBuilder */ protected function addEnabledCondition(\Doctrine\ORM\QueryBuilder $qb, $alias = 'm') { if (!\XLite::getInstance()->isAdminZone()) { $qb->andWhere($alias . '.enabled = 1'); } return $qb; }
protected function getMarketplaceURL($module) { list(, $limit) = $this->getWidget(array(), 'XLite\\View\\Pager\\Admin\\Module\\Install')->getLimitCondition()->limit; $pageId = $module->getRepository()->getMarketplacePageId($module->getAuthor(), $module->getName(), $limit); $params = array('clearCnd' => 1, 'clearSearch' => 1, \XLite\View\Pager\APager::PARAM_PAGE_ID => $pageId, \XLite\View\ItemsList\AItemsList::PARAM_SORT_BY => \XLite\View\ItemsList\Module\AModule::SORT_OPT_ALPHA); return \XLite::getInstance()->getShopURL(sprintf('%s#%s', \XLite\Core\Converter::buildURL('addons_list_marketplace', '', $params), $module->getName())); }
/** * Connect * * @return void */ public function connect() { if (\XLite::isAdminZone()) { \Includes\Utils\ConfigParser::registerConfigFile('config.demo.php'); } parent::connect(); }
/** * Return list of the "Button" widgets * * @return array */ protected function getFormButtons() { $result = parent::getFormButtons(); if ($this->getModule() && 'CDev\\Bestsellers' == $this->getModule()->getActualName()) { $result['sales_calculation'] = new \XLite\View\Button\Link(array(\XLite\View\Button\AButton::PARAM_LABEL => 'Sales calculation', \XLite\View\Button\Link::PARAM_LOCATION => $this->buildURL('sales_calculation', 'sales', array(\XLite::FORM_ID => \XLite::getFormId())), \XLite\View\Button\AButton::PARAM_STYLE => 'action always-enabled')); } return $result; }
/** * get Shipping Method name * for Canada Post add '(Canada Post)' (except admin area, shipping methods page) * * @return string */ public function getName() { $name = parent::getName(); if ('capost' == $this->getProcessor() && !(\XLite::isAdminZone() && \XLite::getController() instanceof \XLite\Controller\Admin\ShippingMethods)) { $name = 'Canada Post ' . $name; } return $name; }
/** * Return widget default template * * @return string */ protected function getDefaultTemplate() { if (!\XLite::isAdminZone() && method_exists('\\XLite\\Core\\Request', 'isMobileDevice') && \XLite\Core\Request::isMobileDevice()) { return 'modules/Amazon/PayWithAmazon/checkout_mobile.tpl'; } else { return 'modules/Amazon/PayWithAmazon/checkout.tpl'; } }
/** * Return list of required CSS files * * @return array */ public function getCSSFiles() { $list = parent::getCSSFiles(); if (!\XLite::isAdminZone()) { $list[] = 'common/grid-list.css'; } return $list; }
/** * Return list of the form default parameters * * @return array */ protected function getDefaultParams() { $params = array(); if (\XLite::isAdminZone()) { $params = array('profile_id' => \XLite\Core\Request::getInstance()->profile_id); } return $params; }
/** * Get total rate * * @return float */ public function getTotalRate() { $total = parent::getTotalRate(); if (!\XLite::isAdminZone() && $this->getMethod()) { $total = \XLite\Module\CDev\VAT\Logic\Shipping\Tax::getInstance()->calculateRateCost($this, $total); } return $total; }
/** * Return list of the form default parameters * * @return array */ protected function getDefaultParams() { $params = array(); if (\XLite::isAdminZone()) { $params = array('amount' => \XLite\Core\Request::getInstance()->amount, 'order_number' => \XLite\Core\Request::getInstance()->order_number); } return $params; }
/** * Get required fields by address type * * @param string $atype Address type code * * @return array */ public function getRequiredFieldsByType($atype) { $list = parent::getRequiredFieldsByType($atype); if ('express_checkout_return' === \XLite::getController()->getAction()) { $list = array_diff($list, array('phone')); } return $list; }
/** * Return common data to send to JS * * @return array */ protected function getCommonJSData() { $data = parent::getCommonJSData(); if (!\XLite::isAdminZone()) { $data += $this->getCloudSearchInitData(); } return $data; }
/** * Register CloudSearch if it has been scheduled * * @return void */ public function registerIfScheduled() { if ($this->isScheduled() && !\XLite::isCacheBuilding()) { $apiClient = ServiceApiClient::getInstance(); $this->unschedule(); $apiClient->register(); } }
/** * Dispatch request * * @return string */ protected static function dispatchRequest() { $result = parent::dispatchRequest(); if (strlen(\XLite\Core\Request::getInstance()->response_order_id) > 2 && isset(\XLite\Core\Request::getInstance()->response_order_id) && isset(\XLite\Core\Request::getInstance()->result) && isset(\XLite\Core\Request::getInstance()->trans_name) && isset(\XLite\Core\Request::getInstance()->cardholder) && isset(\XLite\Core\Request::getInstance()->message)) { $result = 'payment_return'; } return $result; }
/** * We make the full location path for the provided URL * * @return string */ protected function getLocationURL() { $repo = \XLite\Core\Database::getRepo('XLite\\Model\\Module'); $module = $repo->find($this->getParam(static::PARAM_MODULE_ID)); $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getInstalledPageId($module->getAuthor(), $module->getName(), \XLite\View\Pager\Admin\Module\Manage::getInstance()->getItemsPerPage()); $params = array('clearCnd' => 1, \XLite\View\Pager\APager::PARAM_PAGE_ID => $pageId); return \XLite::getInstance()->getShopURL(sprintf('%s#%s', $this->buildURL('addons_list_installed', '', $params), $module->getName())); }
/** * Return list of allowed targets * * @return array */ public static function getAllowedTargets() { $targets = parent::getAllowedTargets(); $targets[] = 'order'; if (!\XLite::isAdminZone()) { $targets[] = 'checkoutSuccess'; } return $targets; }
/** * Get pages static * * @return array */ public static function getPagesStatic() { $list = array(); if (\XLite::isFreeLicense() && \XLite\Core\Auth::getInstance()->isPermissionAllowed(\XLite\Model\Role\Permission::ROOT_ACCESS)) { $list['volume_discounts'] = array('name' => static::t('Volume discounts'), 'tpl' => 'promotions/volume_discounts.tpl'); $list['coupons'] = array('name' => static::t('Coupons'), 'tpl' => 'promotions/coupons.tpl'); } return $list; }
/** * Check if product can be purchased * * @return boolean */ public function isOutOfStock() { $result = parent::isOutOfStock(); if (!$result) { $membership = \XLite::getController() instanceof \XLite\Controller\ACustomer ? \XLite::getController()->getCart()->getProfile()->getMembership() : null; $result = $this->getAvailableAmount() < $this->getProduct()->getMinQuantity($membership); } return $result; }
/** * Define buttons widgets * * @return array */ protected function defineButtons() { $list = parent::defineButtons(); if (\XLite::getController()->isOrderEditable()) { $list['sendNotification'] = $this->getSendNotificationWidget(); $list['recalculate'] = $this->getRecalculateButton(); } return $list; }
/** * getJSFiles * * @return array */ public function getJSFiles() { $list = parent::getJSFiles(); if (!\XLite::isAdminZone() && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable()) { $list[] = 'modules/CDev/Paypal/button/in_context.js'; } else { $list[] = 'modules/CDev/Paypal/button/default.js'; } return $list; }
/** * Request probe script * * @return void */ protected function requestProbe() { $url = \XLite::getInstance()->getShopURL(\XLite\Core\Converter::buildURL('', '', array('key' => \XLite\Core\Config::getInstance()->Internal->probe_key), 'probe.php')); set_time_limit(0); $request = new \XLite\Core\HTTP\Request($url); $response = $request->sendRequest(); if (200 != $response->code) { \XLite\Core\TopMessage::addError('Measuring productivity in manual mode failed.'); } }
/** * Return theme common files * * @param boolean $adminZone Admin zone flag OPTIONAL * * @return array */ protected function getThemeFiles($adminZone = null) { $list = parent::getThemeFiles($adminZone); if (!(null === $adminZone ? \XLite::isAdminZone() : $adminZone)) { $list[static::RESOURCE_CSS][] = \XLite\Module\XC\ColorSchemes\Main::getColorSchemeCSS(); if (!\XLite\Module\XC\ColorSchemes\Main::isDefaultColorScheme()) { $list[static::RESOURCE_CSS][] = array('file' => \XLite\Module\XC\ColorSchemes\Main::getColorSchemeLess(), 'media' => 'screen', 'merge' => 'bootstrap/css/bootstrap.less'); } } return $list; }
/** * Get a list of JS files required to display the widget properly * * @return array */ public function getJSFiles() { $list = parent::getJSFiles(); if (!\XLite::isAdminZone()) { $list[] = 'modules/QSL/CloudSearch/loader.js'; $list[] = 'modules/QSL/CloudSearch/init.js'; $list[] = 'modules/QSL/CloudSearch/lib/handlebars.min.js'; $list[] = 'modules/QSL/CloudSearch/lib/jquery.hoverIntent.min.js'; } return $list; }
/** * 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; }
/** * Returns current currency code * * @return string */ protected function getCurrentCurrencyId() { if (!isset($this->currency)) { if (\XLite\Core\Request::getInstance()->currency) { $this->currency = \XLite\Core\Database::getRepo('XLite\\Model\\Currency')->find(\XLite\Core\Request::getInstance()->currency); } if (!$this->currency) { $this->currency = \XLite::getInstance()->getCurrency(); } } return $this->currency->getCurrencyId(); }
/** * Get default options for selector * * @return array */ protected function getDefaultOptions() { $list = array(); /** @var \XLite\Model\Shipping\Method $method */ $method = \XLite::getController()->getMethod(); $processor = $method->getProcessorObject(); $packageBoxTypeOptions = $processor->getPackageBoxTypeOptions(); foreach ($packageBoxTypeOptions as $option) { $list[$option['code']] = $option['name']; } return $list; }
/** * testLoading * * @return void * @see ____func_see____ * @since 1.0.12 */ public function testLoading() { \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments'); $product = $this->getProduct(); $attach = new \XLite\Module\CDev\FileAttachments\Model\Product\Attachment(); $product->addAttachments($attach); $attach->setProduct($product); $storage = $attach->getStorage(); // Success $this->assertTrue($storage->loadFromLocalFile(__DIR__ . LC_DS . '..' . LC_DS . 'max_ava.png'), 'check loading'); $this->assertEquals('application/octet-stream', $storage->getMime(), 'check mime'); $this->assertEquals('max_ava.png', $storage->getFileName(), 'check file name'); $this->assertEquals(12673, $storage->getSize(), 'check size'); $this->assertEquals(file_get_contents(__DIR__ . '/../max_ava.png'), $storage->getBody(), 'check body'); $this->assertRegExp('/^http:\\/\\//Ss', $storage->getURL(), 'check URL'); $this->assertEquals($storage->getURL(), $storage->getFrontURL(), 'check front url'); $this->assertEquals('png', $storage->getExtension(), 'check extension'); $this->assertEquals('mime-icon-png', $storage->getMimeClass(), 'check MIME class'); $this->assertEquals('png file type', $storage->getMimeName(), 'check MIME name'); // Fail $this->assertFalse($storage->loadFromLocalFile(__DIR__ . LC_DS . '..' . LC_DS . 'wrong.png'), 'check loading (fail)'); // Duplicate $this->assertTrue($storage->loadFromLocalFile(__DIR__ . LC_DS . '..' . LC_DS . 'max_ava.png'), 'check loading (dup)'); $this->assertRegExp('/^max_ava.png$/Ss', $storage->getFileName(), 'check file name (rename)'); // Forbid extension $this->assertFalse($storage->loadFromLocalFile(__FILE__), 'check loading (forbid ext)'); $this->assertEquals('extension', $storage->getLoadError(), 'check load error code'); // Duplicate \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments'); $s1 = $this->getTestStorage(); $s2 = $this->getTestStorage(); $path = LC_DIR_FILES . 'attachments' . LC_DS . $s1->getPath(); $this->assertTrue($s2->loadFromLocalFile($path), 'check duplicate loading'); \XLite\Core\Database::getEM()->flush(); $pid = $s1->getAttachment()->getProduct()->getProductId(); $url = XLite::getInstance()->getShopURL('files/attachments/' . $pid . '/' . basename($path)); $this->assertEquals($url, $s1->getFrontURL(), 'check 1 storage URL'); $this->assertEquals($url, $s2->getFrontURL(), 'check 2 storage URL'); $body = file_get_contents($path); $this->assertEquals(md5($body), md5($s1->getBody()), 'check 1 body'); $this->assertEquals(md5($body), md5($s2->getBody()), 'check 2 body'); ob_start(); $s1->readOutput(); $b1 = ob_get_contents(); ob_end_clean(); ob_start(); $s2->readOutput(); $b2 = ob_get_contents(); ob_end_clean(); $this->assertEquals($body, $b1, 'check 1 output'); $this->assertEquals($body, $b2, 'check 2 output'); }