本文整理汇总了PHP中Magento\Backend\Model\Auth\Session::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getUser方法的具体用法?PHP Session::getUser怎么用?PHP Session::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Backend\Model\Auth\Session
的用法示例。
在下文中一共展示了Session::getUser方法的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: getAclRoleId
/**
* Retrieve current role
*
* @return string|null
*/
public function getAclRoleId()
{
if ($this->_session->hasUser()) {
return $this->_session->getUser()->getAclRole();
}
return null;
}
示例3: 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);
}
示例4: _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();
}
示例5: 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);
}
示例6: hasAvailableResources
/**
* @return bool
*/
public function hasAvailableResources()
{
$user = $this->_authSession->getUser();
if ($user && $user->getHasAvailableResources()) {
return true;
}
return false;
}
示例7: 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;
}
示例8: 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());
}
}
}
示例9: 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;
}
示例10: execute
/**
* Adds New Relic custom parameters per adminhtml request for current admin user, if applicable
*
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
if ($this->backendAuthSession->isLoggedIn()) {
$user = $this->backendAuthSession->getUser();
$this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER_ID, $user->getId());
$this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUsername());
$this->newRelicWrapper->addCustomParameter(Config::ADMIN_NAME, $user->getFirstname() . ' ' . $user->getLastname());
}
}
}
示例11: execute
/**
* Reports concurrent admins to the database reporting_users table
*
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
if ($this->backendAuthSession->isLoggedIn()) {
$user = $this->backendAuthSession->getUser();
$jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()];
$modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)];
/** @var \Magento\NewRelicReporting\Model\Users $usersModel */
$usersModel = $this->usersFactory->create();
$usersModel->setData($modelData);
$usersModel->save();
}
}
}
示例12: getCollectionForLogoutOtherUserSessions
/**
* Collection getter with filters populated for testLogoutOtherUserSessions() method
*
* @param AdminSessionInfo $session
* @return ResourceModel\AdminSessionInfo\Collection
*/
protected function getCollectionForLogoutOtherUserSessions(\Magento\Security\Model\AdminSessionInfo $session)
{
/** @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection $collection */
$collection = $session->getResourceCollection();
$collection->filterByUser($this->authSession->getUser()->getId(), \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $this->authSession->getSessionId())->filterExpiredSessions(100)->load();
return $collection;
}
示例13: getCacheKeyInfo
/**
* Get Key pieces for caching block content
*
* @return array
*/
public function getCacheKeyInfo()
{
$cacheKeyInfo = ['admin_top_nav', $this->getActive(), $this->_authSession->getUser()->getId(), $this->_localeResolver->getLocale()];
// Add additional key parameters if needed
$newCacheKeyInfo = $this->getAdditionalCacheKeyInfo();
if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) {
$cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo);
}
return $cacheKeyInfo;
}
示例14: _isCollapseState
/**
* Collapsed or expanded fieldset when page loaded?
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return bool
*/
protected function _isCollapseState($element)
{
if ($element->getExpanded()) {
return true;
}
$extra = $this->_authSession->getUser()->getExtra();
if (isset($extra['configState'][$element->getId()])) {
return $extra['configState'][$element->getId()];
}
return false;
}
示例15: _isCollapseState
/**
* Collapsed or expanded fieldset when page loaded?
*
* @param AbstractElement $element
* @return bool
*/
protected function _isCollapseState($element)
{
if ($element->getExpanded() || $element->getForm() && $element->getForm()->getElements()->count() === 1) {
return true;
}
$extra = $this->_authSession->getUser()->getExtra();
if (isset($extra['configState'][$element->getId()])) {
return $extra['configState'][$element->getId()];
}
return $this->isCollapsedDefault;
}