本文整理汇总了PHP中Magento\Backend\Model\Auth\Session类的典型用法代码示例。如果您正苦于以下问题:PHP Session类的具体用法?PHP Session怎么用?PHP Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requestToShipment
/**
* Prepare and do request to shipment
*
* @param Shipment $orderShipment
* @return \Magento\Framework\DataObject
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function requestToShipment(Shipment $orderShipment)
{
$admin = $this->_authSession->getUser();
$order = $orderShipment->getOrder();
$shippingMethod = $order->getShippingMethod(true);
$shipmentStoreId = $orderShipment->getStoreId();
$shipmentCarrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode());
$baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode();
if (!$shipmentCarrier) {
throw new LocalizedException(__('Invalid carrier: %1', $shippingMethod->getCarrierCode()));
}
$shipperRegionCode = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $shipmentStoreId);
if (is_numeric($shipperRegionCode)) {
$shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode();
}
$originStreet1 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS1, ScopeInterface::SCOPE_STORE, $shipmentStoreId);
$storeInfo = new DataObject((array) $this->_scopeConfig->getValue('general/store_information', ScopeInterface::SCOPE_STORE, $shipmentStoreId));
if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !$shipperRegionCode || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, ScopeInterface::SCOPE_STORE, $shipmentStoreId)) {
throw new LocalizedException(__('We don\'t have enough information to create shipping labels. Please make sure your store information and settings are complete.'));
}
/** @var $request \Magento\Shipping\Model\Shipment\Request */
$request = $this->_shipmentRequestFactory->create();
$request->setOrderShipment($orderShipment);
$address = $order->getShippingAddress();
$this->setShipperDetails($request, $admin, $storeInfo, $shipmentStoreId, $shipperRegionCode, $originStreet1);
$this->setRecipientDetails($request, $address);
$request->setShippingMethod($shippingMethod->getMethod());
$request->setPackageWeight($order->getWeight());
$request->setPackages($orderShipment->getPackages());
$request->setBaseCurrencyCode($baseCurrencyCode);
$request->setStoreId($shipmentStoreId);
return $shipmentCarrier->requestToShipment($request);
}
示例2: requestToShipment
/**
* Prepare and do request to shipment
*
* @param Shipment $orderShipment
* @return \Magento\Framework\Object
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function requestToShipment(Shipment $orderShipment)
{
$admin = $this->_authSession->getUser();
$order = $orderShipment->getOrder();
$address = $order->getShippingAddress();
$shippingMethod = $order->getShippingMethod(true);
$shipmentStoreId = $orderShipment->getStoreId();
$shipmentCarrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode());
$baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode();
if (!$shipmentCarrier) {
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid carrier: %1', $shippingMethod->getCarrierCode()));
}
$shipperRegionCode = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_REGION_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
if (is_numeric($shipperRegionCode)) {
$shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode();
}
$recipientRegionCode = $this->_regionFactory->create()->load($address->getRegionId())->getCode();
$originStreet1 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
$originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId);
$storeInfo = new \Magento\Framework\Object((array) $this->_scopeConfig->getValue('general/store_information', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !$shipperRegionCode || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We don\'t have enough information to create shipping labels. Please make sure your store information and settings are complete.'));
}
/** @var $request \Magento\Shipping\Model\Shipment\Request */
$request = $this->_shipmentRequestFactory->create();
$request->setOrderShipment($orderShipment);
$request->setShipperContactPersonName($admin->getName());
$request->setShipperContactPersonFirstName($admin->getFirstname());
$request->setShipperContactPersonLastName($admin->getLastname());
$request->setShipperContactCompanyName($storeInfo->getName());
$request->setShipperContactPhoneNumber($storeInfo->getPhone());
$request->setShipperEmail($admin->getEmail());
$request->setShipperAddressStreet(trim($originStreet1 . ' ' . $originStreet2));
$request->setShipperAddressStreet1($originStreet1);
$request->setShipperAddressStreet2($originStreet2);
$request->setShipperAddressCity($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
$request->setShipperAddressStateOrProvinceCode($shipperRegionCode);
$request->setShipperAddressPostalCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
$request->setShipperAddressCountryCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId));
$request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
$request->setRecipientContactPersonFirstName($address->getFirstname());
$request->setRecipientContactPersonLastName($address->getLastname());
$request->setRecipientContactCompanyName($address->getCompany());
$request->setRecipientContactPhoneNumber($address->getTelephone());
$request->setRecipientEmail($address->getEmail());
$request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2)));
$request->setRecipientAddressStreet1($address->getStreetLine(1));
$request->setRecipientAddressStreet2($address->getStreetLine(2));
$request->setRecipientAddressCity($address->getCity());
$request->setRecipientAddressStateOrProvinceCode($address->getRegionCode());
$request->setRecipientAddressRegionCode($recipientRegionCode);
$request->setRecipientAddressPostalCode($address->getPostcode());
$request->setRecipientAddressCountryCode($address->getCountryId());
$request->setShippingMethod($shippingMethod->getMethod());
$request->setPackageWeight($order->getWeight());
$request->setPackages($orderShipment->getPackages());
$request->setBaseCurrencyCode($baseCurrencyCode);
$request->setStoreId($shipmentStoreId);
return $shipmentCarrier->requestToShipment($request);
}
示例3: _prepareForm
/**
* {@inheritdoc}
*/
protected function _prepareForm()
{
$userId = $this->_authSession->getUser()->getId();
$user = $this->_userFactory->create()->load($userId);
$user->unsetData('password');
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]);
$fieldset->addField('username', 'text', ['name' => 'username', 'label' => __('User Name'), 'title' => __('User Name'), 'required' => true]);
$fieldset->addField('firstname', 'text', ['name' => 'firstname', 'label' => __('First Name'), 'title' => __('First Name'), 'required' => true]);
$fieldset->addField('lastname', 'text', ['name' => 'lastname', 'label' => __('Last Name'), 'title' => __('Last Name'), 'required' => true]);
$fieldset->addField('user_id', 'hidden', ['name' => 'user_id']);
$fieldset->addField('email', 'text', ['name' => 'email', 'label' => __('Email'), 'title' => __('User Email'), 'required' => true]);
$fieldset->addField('password', 'password', ['name' => 'password', 'label' => __('New Password'), 'title' => __('New Password'), 'class' => 'input-text validate-admin-password']);
$fieldset->addField('confirmation', 'password', ['name' => 'password_confirmation', 'label' => __('Password Confirmation'), 'class' => 'input-text validate-cpassword']);
$fieldset->addField('interface_locale', 'select', ['name' => 'interface_locale', 'label' => __('Interface Locale'), 'title' => __('Interface Locale'), 'values' => $this->_localeLists->getTranslatedOptionLocales(), 'class' => 'select']);
$verificationFieldset = $form->addFieldset('current_user_verification_fieldset', ['legend' => __('Current User Identity Verification')]);
$verificationFieldset->addField(self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'password', ['name' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'label' => __('Your Password'), 'id' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'title' => __('Your Password'), 'class' => 'input-text validate-current-password required-entry', 'required' => true]);
$data = $user->getData();
unset($data[self::IDENTITY_VERIFICATION_PASSWORD_FIELD]);
$form->setValues($data);
$form->setAction($this->getUrl('adminhtml/system_account/save'));
$form->setMethod('post');
$form->setUseContainer(true);
$form->setId('edit_form');
$this->setForm($form);
return parent::_prepareForm();
}
示例4: execute
/**
* Predispath admin action controller
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->backendAuthSession->isLoggedIn()) {
$feedModel = $this->feedFactory->create();
$feedModel->checkUpdate();
}
}
示例5: isDisplayed
/**
* Check whether survey question can show
*
* @return bool
*/
public function isDisplayed()
{
if ($this->_authSession->getHideSurveyQuestion() || false == $this->_authorization->isAllowed(null) || $this->_survey->isSurveyViewed() || false == $this->_survey->isSurveyUrlValid()) {
return false;
}
return true;
}
示例6: testIsLoggedIn
/**
* @dataProvider loginDataProvider
*/
public function testIsLoggedIn($loggedIn)
{
if ($loggedIn) {
$this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
}
$this->assertEquals($loggedIn, $this->authSession->isLoggedIn());
}
示例7: testSwitchBackendInterfaceLocale
/**
* @param string $locale
* @dataProvider switchBackendInterfaceLocaleDataProvider
* @covers \Magento\Backend\Model\Locale\Manager::switchBackendInterfaceLocale
*/
public function testSwitchBackendInterfaceLocale($locale)
{
$this->_model->switchBackendInterfaceLocale($locale);
$userInterfaceLocale = $this->_authSession->getUser()->getInterfaceLocale();
$this->assertEquals($userInterfaceLocale, $locale);
$sessionLocale = $this->_session->getSessionLocale();
$this->assertEquals($sessionLocale, null);
}
示例8: execute
/**
* Predispath admin action controller
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_backendAuthSession->isLoggedIn()) {
$feedModel = $this->_feedFactory->create();
/* @var $feedModel \Magento\AdminNotification\Model\Feed */
$feedModel->checkUpdate();
}
}
示例9: hasAvailableResources
/**
* @return bool
*/
public function hasAvailableResources()
{
$user = $this->_authSession->getUser();
if ($user && $user->getHasAvailableResources()) {
return true;
}
return false;
}
示例10: execute
/**
* Report system cache is flushed to New Relic
*
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
$user = $this->backendAuthSession->getUser();
if ($user->getId()) {
$this->deploymentsFactory->create()->setDeployment('Cache Flush', $user->getUsername() . ' flushed the cache.', $user->getUsername());
}
}
}
示例11: getUserInterfaceLocale
/**
* Get user interface locale stored in session data
*
* @return string
*/
public function getUserInterfaceLocale()
{
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
$userData = $this->_authSession->getUser();
if ($userData && $userData->getInterfaceLocale()) {
$interfaceLocale = $userData->getInterfaceLocale();
}
return $interfaceLocale;
}
示例12: execute
/**
* Log out user and redirect to new admin custom url
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.ExitExpression)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
return;
}
$this->_authSession->destroy();
$adminUrl = $this->_backendData->getHomePageUrl();
$this->_response->setRedirect($adminUrl)->sendResponse();
exit(0);
}
示例13: execute
/**
* Log out user and redirect him to new admin custom url
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
return;
}
$this->_authSession->destroy();
$route = $this->_backendData->getAreaFrontName();
$this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
exit(0);
}
示例14: change
public function change($changeValue, $accountId, $form_key)
{
$req = new \Praxigento\Accounting\Service\Balance\Request\Change();
$req->setCustomerAccountId($accountId);
$req->setChangeValue($changeValue);
$userId = $this->_authSession->getUser()->getId();
$req->setAdminUserId($userId);
$result = $this->_callBalance->change($req);
return $result;
}
示例15: testReportConcurrentAdminsToNewRelic
/**
* Test case when module is enabled and user is logged in
*
* @return void
*/
public function testReportConcurrentAdminsToNewRelic()
{
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
$userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
$this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
$this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
$this->model->execute($eventObserver);
}