/** * Update coupon * * @return void */ public function doActionUpdate() { $this->getModelForm()->performAction('modify'); if ($this->getModelForm()->isValid()) { $this->setReturnURL(\XLite\Core\Converter::buildURL('promotions', '', array('page' => \XLite\Controller\Admin\Promotions::PAGE_COUPONS))); } }
/** * Get order actions * * @param \XLite\Model\Order $entity Order * * @return array */ protected function getOrderActions(\XLite\Model\Order $entity) { $list = array(); foreach ($this->defineOrderActions($entity) as $action) { $parameters = empty($action[static::ACTION_PARAMS]) || !is_array($action[static::ACTION_PARAMS]) ? array() : $action[static::ACTION_PARAMS]; $parameters['entity'] = $entity; // Build URL if (!empty($action[static::ACTION_ACTION]) && empty($action[static::ACTION_URL])) { $action[static::ACTION_URL] = \XLite\Core\Converter::buildURL('order', $action[static::ACTION_ACTION], array('order_number' => $entity->getOrderNumber())); } if (!isset($action[static::ACTION_CLASS]) && !isset($action[static::ACTION_TEMPLATE])) { // Define widget as link-button $action[static::ACTION_CLASS] = 'XLite\\View\\Button\\Link'; $parameters['label'] = $action[static::ACTION_NAME]; $parameters['location'] = $action[static::ACTION_URL]; } elseif (!empty($action[static::ACTION_CLASS])) { // Prepare widget parameters if (!empty($action[static::ACTION_URL])) { $parameters['url'] = $action[static::ACTION_URL]; } if (!empty($action[static::ACTION_ACTION])) { $parameters['action'] = $action[static::ACTION_ACTION]; } } if (!empty($action[static::ACTION_TEMPLATE])) { $parameters['template'] = $action[static::ACTION_TEMPLATE]; } $list[] = empty($action[static::ACTION_CLASS]) ? $this->getWidget($parameters) : $this->getWidget($parameters, $action[static::ACTION_CLASS]); } return $list; }
/** * Preprocessor for no-action reaction * * @return void */ protected function doNoAction() { parent::doNoAction(); $content = \XLite\Core\Request::getInstance()->id ? \XLite\Core\Database::getRepo('XLite\\Model\\IframeContent')->find(\XLite\Core\Request::getInstance()->id) : null; if ($content) { $method = $content->getMethod(); $url = $content->getUrl(); $body = $this->assembleFormBody($content); $html = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body onload="javascript: document.getElementById('payment_form').submit();"> <form method="{$method}" id="payment_form" name="payment_form" action="{$url}"> <fieldset style="display: none;"> {$body} </fieldset> </form> </body> </html> HTML; print $html; exit; } else { $this->redirect(\XLite\Core\Converter::buildURL('checkout')); } }
/** * Update coupon * * @return void */ public function doActionUpdate() { $this->getModelForm()->performAction('modify'); if ($this->getModelForm()->getModelObject()->getId()) { $this->setReturnUrl(\XLite\Core\Converter::buildURL('roles')); } }
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())); }
/** * doActionStartExpressCheckout * * @return void */ protected function doActionStartExpressCheckout() { if (Paypal\Main::isExpressCheckoutEnabled()) { $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $this->getCart()->setPaymentMethod($paymentMethod); $this->updateCart(); \XLite\Core\Session::getInstance()->ec_type = Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; $processor = $paymentMethod->getProcessor(); $token = $processor->doSetExpressCheckout($paymentMethod); if (isset($token)) { \XLite\Core\Session::getInstance()->ec_token = $token; \XLite\Core\Session::getInstance()->ec_date = \XLite\Core\Converter::time(); \XLite\Core\Session::getInstance()->ec_payer_id = null; $processor->redirectToPaypal($token); exit; } else { if (\XLite\Core\Request::getInstance()->inContext) { \XLite\Core\Session::getInstance()->cancelUrl = \XLite\Core\Request::getInstance()->cancelUrl; \XLite\Core\Session::getInstance()->inContextRedirect = true; $this->setReturnURL($this->buildURL('checkout_failed')); } \XLite\Core\TopMessage::getInstance()->addError($processor->getErrorMessage() ?: 'Failure to redirect to PayPal.'); } } }
/** * Return converted into user time current timestamp * * @return integer */ public static function getUserTime() { if (!isset(static::$userTime)) { static::$userTime = \XLite\Core\Converter::convertTimeToUser(); } return static::$userTime; }
/** * testCreate * * @return void * @access public * @see ____func_see____ * @since 1.0.0 */ public function testCreate() { $c = new \XLite\Model\Country(); foreach ($this->entityData as $field => $testValue) { $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $c->{$setterMethod}($testValue); $value = $c->{$getterMethod}(); $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')'); } $s = new \XLite\Model\State(); $s->setState('test state'); $s->setCode('ttt'); $c->addStates($s); $em = \XLite\Core\Database::getEM(); $em->persist($c); $em->flush(); $em->clear(); $c = \XLite\Core\Database::getEM()->merge($c); foreach ($this->entityData as $field => $testValue) { $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $this->assertEquals($testValue, $c->{$getterMethod}(), 'Creation checking (' . $field . ') #2'); } $this->assertEquals($s->getStateId(), $c->getStates()->get(0)->getStateId(), 'check state'); $em->remove($c); $em->flush(); }
/** * testCreate * * @return void * @access public * @see ____func_see____ * @since 1.0.0 */ public function testCreate() { $c = new \XLite\Model\Category(); foreach ($this->categoryData as $field => $testValue) { $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $c->{$setterMethod}($testValue); $value = $c->{$getterMethod}(); $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')'); } $qf = new \XLite\Model\Category\QuickFlags(); $qf->setCategory($c); $c->setQuickFlags($qf); $this->assertEquals($qf, $c->getQuickFlags(), 'test quick flags'); $m = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll(); $c->setMembership($m[0]); $this->assertEquals($m[0], $c->getMembership(), 'check membership'); $i = new \XLite\Model\Image\Category\Image(); $c->setImage($i); $this->assertEquals($i, $c->getImage(), 'check image'); $cp = new \XLite\Model\CategoryProducts(); $c->addCategoryProducts($cp); $this->assertEquals($cp, $c->getCategoryProducts()->get(0), 'check category products'); $this->assertEquals(1, count($c->getCategoryProducts()), 'check category products length'); $child = new \XLite\Model\Category(); $c->addChildren($child); $child->setParent($c); $this->assertEquals($child, $c->getChildren()->get(0), 'check childs'); $this->assertEquals(1, count($c->getChildren()), 'check childs length'); $this->assertEquals($c, $child->getParent(), 'check parent'); }
/** * Get view value * * @param array $field Field * * @return mixed */ protected function getViewValue(array $field) { $value = parent::getViewValue($field); if (is_scalar($value)) { $value = \XLite\Core\Converter::formatDate($value); } return $value; }
public function testCreate() { $session = $this->getTestSession(); $this->assertTrue(0 < $session->getId(), 'check session id'); foreach ($this->testSession as $k => $v) { $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k); $this->assertEquals($v, $session->{$m}(), 'Check ' . $k); } }
/** * Return the current page title (for the content area) * * @return string */ public function getTitle() { if ($this->checkAccess()) { $title = static::t('Order #X, Y', array('id' => $this->getOrderNumber(), 'date' => \XLite\Core\Converter::getInstance()->formatTime($this->getOrder()->getDate()))); } else { $title = static::t('Order not found'); } return $title; }
/** * testCreate * * @return void * @see ____func_see____ * @since 1.0.22 */ public function testCreate() { $method = $this->getTestMethod(); $this->assertTrue(0 < $method->getMethodId(), 'check method id'); foreach ($this->testMethod as $k => $v) { $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k); $this->assertEquals($v, $method->{$m}(), 'Check ' . $k); } }
/** * Get order aActions * * @param \XLite\Model\Order $entity Order * * @return array */ protected function getOrderActions(\XLite\Model\Order $entity) { $list = array(); foreach ($this->defineOrderActions($entity) as $action) { $parameters = array('label' => ucfirst($action), 'location' => \XLite\Core\Converter::buildURL('order', $action, array('order_id' => $this->getOrder()->getOrderId()))); $list[] = $this->getWidget($parameters, 'XLite\\View\\Button\\Link'); } 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.'); } }
/** * Validate * * @param mixed $data Data * * @return void */ public function validate($data) { if (!\XLite\Core\Converter::isEmptyString($data)) { $entity = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->findOneBySku($this->sanitize($data)); // DO NOT use "!==" here if ($entity && (empty($this->productId) || $entity->getProductId() != $this->productId)) { $this->throwSKUError(); } } }
/** * doActionBackup * * @return void */ protected function doActionBackup() { $destFile = LC_DIR_BACKUP . sprintf('sqldump.backup.%d.sql', \XLite\Core\Converter::time()); $this->startDownload('db_backup.sql'); // Make database backup and store it in $this->sqldumpFile file \XLite\Core\Database::getInstance()->exportSQLToFile($destFile, false); readfile($destFile); \Includes\Utils\FileManager::deleteFile($destFile); exit; }
/** * Validate * * @param mixed $data Data * * @return void */ public function validate($data) { parent::validate($data); if (!\XLite\Core\Converter::isEmptyString($data)) { $entity = \XLite\Core\Database::getRepo('XLite\\Module\\XC\\ProductVariants\\Model\\ProductVariant')->findOneBySku($this->sanitize($data)); if ($entity) { $this->throwVariantSKUError(); } } }
/** * Get default options * * @return array */ protected function getDefaultOptions() { $time = \XLite\Core\Converter::time(); $allowedDateFormats = \XLite\Core\Converter::getAvailableDateFormats(); $options = array(); foreach ($allowedDateFormats as $phpFormat => $formats) { $options[$phpFormat] = \XLite\Core\Converter::formatDate($time, $phpFormat); } return $options; }
/** * Preprocessor for no-action run * * @return void */ protected function doNoAction() { $dictionary = \XLite\Core\Request::getInstance()->dictionary; if ($dictionary) { $method = 'assembleDictionary' . \XLite\Core\Converter::convertToCamelCase($dictionary); if (method_exists($this, $method)) { $this->data = $this->processData($this->{$method}(strval(\XLite\Core\Request::getInstance()->erm))); } } $this->silent = true; }
/** * testCreate * * @return void * @access public * @see ____func_see____ * @since 1.0.0 */ public function testCreate() { $c = new \XLite\Model\Membership(); foreach ($this->entityData as $field => $testValue) { $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $c->{$setterMethod}($testValue); $value = $c->{$getterMethod}(); $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')'); } }
/** * Get entity value * * @return mixed */ protected function getEntityValue() { $result = null; $entity = $this->getEntity(); $method = 'get' . \XLite\Core\Converter::convertToCamelCase($this->getParam(static::PARAM_FIELD_NAME)); if (method_exists($entity, $method)) { // $method assembled from 'get' + field short name $result = $this->getEntity()->{$method}(); } return $result; }
/** * URL to redirect if action is forbidden * * @return string */ protected function getForbidInDemoModeRedirectURL() { if ('delete' == \XLite\Core\Request::getInstance()->action) { // Redirect for delete action $url = \XLite\Core\Converter::buildURL('users', '', array('mode' => 'search')); } elseif ($this->getProfile()->getProfileId()) { // Redirect if profile found $url = \XLite\Core\Converter::buildURL('profile', '', array('profile_id' => $this->getProfile()->getProfileId())); } else { $url = \XLite\Core\Converter::buildURL('profile', '', array('mode' => 'register')); } return $url; }
/** * Update model * * @return void */ protected function doActionUpdate() { if ($this->getModelForm()->performAction('modify')) { if (\Xlite\Core\Request::getInstance()->isCreate) { echo <<<HTML <script type="text/javascript">window.opener.location.reload();window.close()</script> HTML; exit; } else { $this->setReturnUrl(\XLite\Core\Converter::buildURL('theme_tweaker_templates')); } } }
/** * Validate * * @param mixed $data Data * * @return void * @throws \XLite\Core\Validator\Exception */ public function validate($data) { $data = $this->sanitize($data); if (!\XLite\Core\Converter::isEmptyString($data)) { parent::validate($data); /** @var \XLite\Model\Repo\CleanURL $repo */ $repo = \XLite\Core\Database::getRepo('XLite\\Model\\CleanURL'); $postedData = \XLite\Core\Request::getInstance()->postedData; if (!isset($postedData['forceCleanURL']) && !$repo->isURLUnique($data, $this->class, $this->id)) { $this->throwCleanURLError($data); } } }
public function testCreate() { $group = $this->getTestGroup(); $this->assertEquals(3, count($group->getOptions()), 'Check options count'); $options = $group->getOptions(); $option = $options[0]; foreach ($this->testOption as $k => $v) { $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k); $this->assertEquals($v, $option->{$m}(), 'Check ' . $k . ' (option)'); } $this->assertEquals(10, $options[2]->getSurcharge('price')->getModifier(), 'Check modifier'); $this->assertEquals('$', $options[2]->getSurcharge('price')->getModifierType(), 'Check modifier type'); $this->assertEquals(1, $options[2]->getExceptions()->count(), 'Check exceptions'); }
/** * Measure enviroment * * @param boolean $force Force run OPTIONAL * * @return boolean */ public function measure($force = false) { $result = false; if ($force || $this->checkAccess()) { set_time_limit(0); $measure = new \XLite\Model\Measure(); $measure->setDate(\XLite\Core\Converter::time()); $measure->setFsTime(intval($this->measureFilesystem() * 1000)); $measure->setDbTime(intval($this->measureDatabase() * 1000)); $measure->setCpuTime(intval($this->measureComputation() * 1000)); \XLite\Core\Database::getEM()->persist($measure); \XLite\Core\Database::getEM()->flush(); $result = true; } return $result; }
/** * Register event to the order * * @param integer $orderId Order identificator * @param string $code Event code * @param string $description Event description * @param array $data Data for event description OPTIONAL * @param string $comment Event comment OPTIONAL * @param array $details Event details OPTIONAL * * @return void */ public function registerEvent($orderId, $code, $description, array $data = array(), $comment = '', $details = array()) { $order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderId); if (!$order->isRemoving()) { $event = new \XLite\Model\OrderHistoryEvents(array('date' => \XLite\Core\Converter::time(), 'code' => $code, 'description' => $description, 'data' => $data, 'comment' => $comment)); if (!empty($details)) { $event->setDetails($details); } if (\XLite\Core\Auth::getInstance()->getProfile()) { $event->setAuthor(\XLite\Core\Auth::getInstance()->getProfile()); } $event->setOrder($order); $order->addEvents($event); $this->insert($event); } }
/** * testCreate * * @return void * @access public * @see ____func_see____ * @since 1.0.0 */ public function testCreate() { $c = new \XLite\Model\ViewList(); foreach ($this->entityData as $field => $testValue) { $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field); $c->{$setterMethod}($testValue); $value = $c->{$getterMethod}(); $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')'); } \XLite\Core\Database::getEM()->persist($c); \XLite\Core\Database::getEM()->flush(); $this->assertTrue(0 < $c->getListId(), 'check list id'); \XLite\Core\Database::getEM()->remove($c); \XLite\Core\Database::getEM()->flush(); }
/** * Get products list * * @param integer $productId Current product ID * @param array $productIds Product ID which must be excluded from the search result * @param integer $maxCount Maximum number of products * * @return array */ public function getSourceRelatedProducts($productId, $productIds, $maxCount) { $result = array(); $cnd = new \XLite\Core\CommonCell(); if ($productIds) { $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_EXCL_PRODUCT_ID} = $productIds; } $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_PARENT_PRODUCT_ID} = $productId; $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_DATE} = \XLite\Core\Converter::getDayEnd(\XLite\Base\SuperClass::getUserTime()); $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_LIMIT} = array(0, $maxCount + 1); $products = \XLite\Core\Database::getRepo('XLite\\Module\\XC\\Upselling\\Model\\UpsellingProduct')->search($cnd, false); foreach ($products as $product) { $result[] = $product->getProduct(); } return $result; }