public static function getUserToolbarItems($types = null, $filter = null, $order = 'ASC') { if ($filter == null) { $filter = new ARSelectFilter(); } $filter->mergeCondition(eq(f(__CLASS__ . '.ownerID'), SessionUser::getUser()->getID())); $filter->setOrder(f(__CLASS__ . '.position'), $order); $m = array(BackendToolbarItem::TYPE_MENU => '', BackendToolbarItem::TYPE_PRODUCT => '', BackendToolbarItem::TYPE_USER => '', BackendToolbarItem::TYPE_ORDER => ''); if (is_array($types) == false) { $types = array($types); } $conditions = array(); foreach ($types as $type) { switch ($type) { case BackendToolbarItem::TYPE_MENU: $conditions[] = isnotnull(f(__CLASS__ . '.menuID')); break; case BackendToolbarItem::TYPE_PRODUCT: $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.productID')), isnotnull(f('Product.ID')))); // fake inner join break; case BackendToolbarItem::TYPE_USER: $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.userID')), isnotnull(f('User.ID')))); break; case BackendToolbarItem::TYPE_ORDER: $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.orderID')), isnotnull(f('CustomerOrder.ID')))); break; } } if (count($conditions)) { $filter->mergeCondition(new OrChainCondition($conditions)); } return self::getRecordSetArray(__CLASS__, $filter, true); }
public static function run($accessString) { if (empty($accessString)) { return true; } if (preg_match_all('/([\\w\\.]+)(?:\\(([\\w\\.]*)(?:\\/(\\w*))?\\))?,?/', $accessString, $roles)) { ClassLoader::import('application.model.user.SessionUser'); $currentUser = SessionUser::getUser(); $controller = Controller::getCurrentController(); $rolesParser = $controller->getRoles(); $currentControllerName = $controller->getRequest()->getControllerName(); $currentActionName = $controller->getRequest()->getActionName(); $rolesCount = count($roles[0]); for ($i = 0; $i < $rolesCount; $i++) { $roleString = $roles[0][$i]; $roleName = $roles[1][$i]; $roleControllerName = empty($roles[3][$i]) ? $currentControllerName : $roles[2][$i]; $roleActionName = empty($roles[3][$i]) ? empty($roles[2][$i]) ? $currentActionName : $roles[2][$i] : $currentActionName; if ($roleControllerName == $currentControllerName && $roleActionName == $currentActionName) { $aRoleName = $rolesParser->getRole($roleActionName); if ($currentUser->hasAccess($aRoleName) && $currentUser->hasAccess($roleName)) { return true; } } } return false; } throw new ApplicationException('Access string ("' . $accessString . '") has illegal format'); }
/** * Get CustomerOrder instance from session * * @return CustomerOrder */ public static function getOrder() { if (self::$instance) { return self::$instance; } $session = new Session(); $id = $session->get('CustomerOrder'); if ($id) { try { $instance = CustomerOrder::getInstanceById($id, true); if (!$instance->getOrderedItems()) { $instance->loadItems(); } $instance->isSyncedToSession = true; } catch (ARNotFoundException $e) { unset($instance); } } if (!isset($instance)) { $userId = SessionUser::getUser()->getID(); // get the last unfinalized order by this user if ($userId > 0) { $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userId)); $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true)); $f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC'); $f->setLimit(1); $orders = ActiveRecordModel::getRecordSet('CustomerOrder', $f); if ($orders->size()) { $instance = $orders->get(0); } } } if (!isset($instance)) { $instance = CustomerOrder::getNewInstance(User::getNewInstance(0)); $instance->user->set(NULL); } if (!$instance->user->get() && SessionUser::getUser()->getID() > 0) { $instance->setUser(SessionUser::getUser()); $instance->save(); } if ($instance->isFinalized->get()) { $session->unsetValue('CustomerOrder'); return self::getOrder(); } // fixes issue when trying to add OrderedItem to unsaved(without ID) CustomerOrder. // ~ but i don't know if returning unsaved CustomerOrder is expected behaviour. if ($instance->isExistingRecord() == false) { $instance->save(true); } self::setOrder($instance); return $instance; }
/** * Tab * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_tab($params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { ClassLoader::import('application.helper.AccessStringParser'); if (!empty($params['role']) && !AccessStringParser::run($params['role'])) { return false; } $user = SessionUser::getUser(); $userPref = $user->getPreference('tab_' . $params['id']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $content = ' <li id="' . $params['id'] . '" rel="' . $params['help'] . '" class="tab ui-state-default ui-corner-top inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . '</li>'; return $content; } }
/** * Tab * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_tab($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { ClassLoader::import('application.helper.AccessStringParser'); if (!empty($params['role']) && !AccessStringParser::run($params['role'])) { return false; } $user = SessionUser::getUser(); $userPref = $user->getPreference('tab_' . $params['id']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $content = ' <li id="' . $params['id'] . '" class="tab inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . ' <span> </span> <span class="tabHelp">' . $params['help'] . '</span> </li>'; return $content; } }
/** * Language forms * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_language($params, $content, Smarty_Internal_Template $smarty, &$repeat) { //$smarty = $smarty->smarty; $app = $smarty->smarty->getApplication(); if (!$app->getLanguageSetArray()) { return false; } if ($repeat) { $app->languageBlock = $app->getLanguageSetArray(); $smarty->assign('languageBlock', $app->languageBlock); $smarty->assign('lang', array_shift($app->languageBlock)); $app->langHeadDisplayed = false; $user = SessionUser::getUser(); foreach ($app->getLanguageSetArray() as $lang) { $userPref = $user->getPreference('tab_lang_' . $lang['ID']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $classNames[$lang['ID']] = $isHidden ? 'hidden' : ''; } $app->langClassNames = $classNames; } else { if (!trim($content)) { $repeat = false; return false; } if ($app->languageBlock) { $repeat = true; } $contentLang = $smarty->getTemplateVars('lang'); $content = '<tab class="lang_' . $contentLang['ID'] . '" heading="' . $contentLang['originalName'] . '">' . $content . '</tab>'; if (!$app->langHeadDisplayed) { $smarty->assign('classNames', $app->langClassNames); $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content; $app->langHeadDisplayed = true; } $smarty->assign('lang', array_shift($app->languageBlock)); // form footer if (!$repeat) { $content .= $smarty->fetch('block/backend/langFormFoot.tpl'); } return $content; } }
/** * Language forms * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_language($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$smarty->getApplication()->getLanguageSetArray()) { return false; } if ($repeat) { $smarty->languageBlock = $smarty->getApplication()->getLanguageSetArray(); $smarty->assign('languageBlock', $smarty->languageBlock); $smarty->assign('lang', array_shift($smarty->languageBlock)); $smarty->langHeadDisplayed = false; $user = SessionUser::getUser(); foreach ($smarty->getApplication()->getLanguageSetArray() as $lang) { $userPref = $user->getPreference('tab_lang_' . $lang['ID']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $classNames[$lang['ID']] = $isHidden ? 'hidden' : ''; } $smarty->langClassNames = $classNames; } else { if (!trim($content)) { $repeat = false; return false; } if ($smarty->languageBlock) { $repeat = true; } $contentLang = $smarty->get_template_vars('lang'); $content = '<div class="languageFormContainer languageFormContainer_' . $contentLang['ID'] . ' ' . $smarty->langClassNames[$contentLang['ID']] . '">' . $content . '</div>'; if (!$smarty->langHeadDisplayed) { $smarty->assign('langFormId', 'langForm_' . uniqid()); $smarty->assign('classNames', $smarty->langClassNames); $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content; $smarty->langHeadDisplayed = true; } $smarty->assign('lang', array_shift($smarty->languageBlock)); // form footer if (!$repeat) { $content .= $smarty->fetch('block/backend/langFormFoot.tpl'); } return $content; } }
public static function getUserToolbarItems($types = null, $filter = null, $order = 'ASC') { if ($filter == null) { $filter = new ARSelectFilter(); } $filter->mergeCondition(eq(f(__CLASS__ . '.ownerID'), SessionUser::getUser()->getID())); $filter->setOrder(f(__CLASS__ . '.position'), $order); $m = array(BackendToolbarItem::TYPE_MENU => 'menuID', BackendToolbarItem::TYPE_PRODUCT => 'productID', BackendToolbarItem::TYPE_USER => 'userID', BackendToolbarItem::TYPE_ORDER => 'orderID'); if (is_array($types) == false) { $types = array($types); } $conditions = array(); foreach ($types as $type) { if (array_key_exists($type, $m)) { $conditions[] = isnotnull(f(__CLASS__ . '.' . $m[$type])); } } if (count($conditions)) { $filter->mergeCondition(new OrChainCondition($conditions)); } return self::getRecordSetArray(__CLASS__, $filter, true); }
protected function processRecord(CustomerOrder $order) { $order->processMass_history = new OrderHistory($order, SessionUser::getUser()); switch ($this->getAction()) { case 'setNew': $status = CustomerOrder::STATUS_NEW; break; case 'setProcessing': $status = CustomerOrder::STATUS_PROCESSING; break; case 'setAwaitingShipment': $status = CustomerOrder::STATUS_AWAITING; break; case 'setShipped': $status = CustomerOrder::STATUS_SHIPPED; break; case 'setReturned': $status = CustomerOrder::STATUS_RETURNED; break; case 'setUnfinalized': $order->isFinalized->set(0); break; case 'setCancel': $order->cancel(); break; case 'setFinalized': if (!$order->isFinalized->get() && $order->user->get()) { $order->finalize(); } break; } if (isset($status) && $status != $order->status->get()) { $order->setStatus($status); $this->params['controller']->sendStatusNotifyEmail($order); } }
/** * Handles LiveCart update process when called from command line * * @author Integry Systems */ // change to application root directory chdir('..'); // initialize LiveCart include_once 'application/Initialize.php'; ClassLoader::import('application.LiveCart'); session_start(); $livecart = new LiveCart(); // process update ClassLoader::import('application.controller.backend.UpdateController'); $user = SessionUser::getUser(); $user->allowBackendAccess(); $user->setID(1); SessionUser::setUser($user); $controller = new UpdateController($livecart); $response = $controller->update(); if ($response instanceof RawResponse) { echo $response->getContent() . "\n"; } elseif ($response instanceof ActionResponse) { foreach ($response->get('progress') as $key => $value) { echo $key . ': OK' . "\n"; } if ($response->get('errors')) { echo "\n" . 'Errors:' . "\n\n"; foreach ($response->get('errors') as $key => $value) { echo $key . ': ' . $value . "\n";
public function getBusinessRuleController() { if (!$this->businessRuleController) { $context = new BusinessRuleContext(); if ($items = SessionOrder::getOrderItems()) { $context->setOrder($items); } if (SessionUser::getUser()) { $context->setUser(SessionUser::getUser()); } $this->businessRuleController = new BusinessRuleController($context); if ($this->isBackend()) { $this->businessRuleController->disableDisplayDiscounts(); } } return $this->businessRuleController; }
public function testUserCheckoutWithDifferentAddresses() { $this->order->addProduct($this->products[0], 1); $this->order->save(); $this->assertTrue($this->order->isShippingRequired()); $this->controller->setOrder($this->reloadOrder($this->order)); $request = $this->controller->getRequest(); $request->set('sameAsBilling', ''); $request->set('email', '*****@*****.**'); // shipping address not entered at all $request->set('billing_firstName', 'First'); $request->set('billing_lastName', 'Last'); $request->set('billing_companyName', 'CMP'); $request->set('billing_address1', 'Address 1'); $request->set('billing_state_text', 'State'); $request->set('billing_city', 'Some City'); $request->set('billing_country', 'LV'); $request->set('billing_postalCode', 'LV-1234'); $request->set('billing_phone', '1234'); $response = $this->controller->processCheckoutRegistration(); // last name was not entered, so we get back to user/checkout // with a bunch of errors for each shipping address field $this->assertIsA($response, 'ActionRedirectResponse'); $this->assertEqual($response->getControllerName(), 'user'); $this->assertEqual($response->getActionName(), 'checkout'); $this->assertTrue(1 < count($this->controller->checkout()->get('form')->getValidator()->getErrorList())); // let's forget the last name again $request->set('shipping_firstName', 'Recipient'); $request->set('shipping_companyName', 'CMP'); $request->set('shipping_address1', 'Rec Street'); $request->set('shipping_city', 'Rec City'); $request->set('shipping_state_text', 'State'); $request->set('shipping_country', 'LT'); $request->set('shipping_postalCode', 'LT-4321'); $request->set('shipping_phone', '4321'); $this->assertEqual($response->getControllerName(), 'user'); $this->assertEqual($response->getActionName(), 'checkout'); // enter that last name at last $request->set('shipping_lastName', 'Last'); $response = $this->controller->processCheckoutRegistration(); $this->assertIsA($response, 'ActionRedirectResponse'); $this->assertEqual($response->getControllerName(), 'checkout'); $this->assertEqual($response->getActionName(), 'shipping'); // verify user data $user = SessionUser::getUser(); $user->reload(true); $this->assertEquals($user->firstName->get(), 'First'); $this->assertEquals($user->defaultShippingAddress->get()->userAddress->get()->firstName->get(), 'Recipient'); $this->assertEquals($user->defaultBillingAddress->get()->userAddress->get()->countryID->get(), 'LV'); $this->assertEquals($user->defaultShippingAddress->get()->userAddress->get()->countryID->get(), 'LT'); // order address ActiveRecord::clearPool(); $order = CustomerOrder::getInstanceByID($this->order->getID(), true); $order->loadAll(); $this->assertEquals($order->shippingAddress->get()->countryID->get(), 'LT'); }
public function getUser() { if (empty($this->user)) { ClassLoader::import('application.model.user.SessionUser'); $sessionUser = new SessionUser(); $this->user = $sessionUser->getUser(); } return $this->user; }
private function buildSharingValidator(Product $product) { ClassLoader::import('application.helper.check.IsUniqueEmailCheck'); $validator = $this->getValidator('productSharingValidator', $this->getRequest()); if (!$this->config->get('ENABLE_PRODUCT_SHARING')) { $validator->addCheck(md5(time() . mt_rand()), new IsNotEmptyCheck($this->translate('_feature_disabled'))); } $validator->addCheck('friendemail', new IsNotEmptyCheck($this->translate('_err_enter_email'))); $validator->addCheck('friendemail', new IsValidEmailCheck($this->translate('_err_invalid_email'))); if (SessionUser::getUser()->isAnonymous()) { if (!$this->config->get('ENABLE_ANONYMOUS_PRODUCT_SHARING')) { $validator->addCheck(md5(time() . mt_rand()), new IsNotEmptyCheck($this->translate('_feature_disabled_for_anonymous'))); } $validator->addCheck('nickname', new IsNotEmptyCheck($this->translate('_err_enter_nickname'))); } return $validator; }
private function isSessionCacheUsable() { if (!$this->user) { return false; } return $this->user->getID() == SessionUser::getUser()->getID(); }