当前位置: 首页>>代码示例>>PHP>>正文


PHP Customer::getId方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\Customer::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::getId方法的具体用法?PHP Customer::getId怎么用?PHP Customer::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\Customer的用法示例。


在下文中一共展示了Customer::getId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSameAsBillingForBillingAddress

 /**
  * same_as_billing must be equal 0 if billing address is being saved
  *
  * @param bool $unsetId
  * @dataProvider unsetAddressIdDataProvider
  */
 public function testSameAsBillingForBillingAddress($unsetId)
 {
     $this->_quote->setCustomer($this->_customer);
     $address = $this->_quote->getBillingAddress();
     if ($unsetId) {
         $address->setId(null);
     }
     /** @var \Magento\Customer\Service\V1\CustomerAddressServiceInterface $addressService */
     $addressService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAddressServiceInterface');
     $customerAddressData = $addressService->getDefaultBillingAddress($this->_customer->getId());
     $address->setSameAsBilling(0)->setCustomerAddressData($customerAddressData)->save();
     $this->assertEquals(0, $this->_quote->getBillingAddress()->getSameAsBilling());
 }
开发者ID:aiesh,项目名称:magento2,代码行数:19,代码来源:AddressTest.php

示例2: loadSelf

 /**
  * Load customer user info
  *
  * @throws \Magento\Framework\Exception
  * @return \Inchoo\SocialConnect\Model\Facebook\Info\User
  */
 public function loadSelf()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         if (!$this->_customer->getId()) {
             throw new \Magento\Framework\Exception(__('Could not load self since customer isn\'t logged in'));
         }
     }
     $this->_customer = $this->_customerSession->getCustomer();
     if (!$this->_customer->getId()) {
         throw new \Magento\Framework\Exception(__('Could not load by customer id'));
     }
     if (!($socialconnectFid = $this->_customer->getInchooSocialconnectFid()) || !($socialconnectFtoken = $this->_customer->getInchooSocialconnectFtoken())) {
         throw new \Magento\Framework\Exception(__('Could not retrieve token by customer id'));
     }
     $this->setAccessToken($socialconnectFtoken);
     $this->_load();
     return $this;
 }
开发者ID:LavoWeb,项目名称:Magento2-Inchoo_SocialConnect,代码行数:24,代码来源:User.php

示例3: changePasswordForCustomer

 /**
  * Change customer password.
  *
  * @param CustomerModel $customer
  * @param string $currentPassword
  * @param string $newPassword
  * @return bool true on success
  * @throws InputException
  * @throws InvalidEmailOrPasswordException
  */
 private function changePasswordForCustomer($customer, $currentPassword, $newPassword)
 {
     $customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
     $hash = $customerSecure->getPasswordHash();
     if (!$this->encryptor->validateHash($currentPassword, $hash)) {
         throw new InvalidEmailOrPasswordException(__('The password doesn\'t match this account.'));
     }
     $customerSecure->setRpToken(null);
     $customerSecure->setRpTokenCreatedAt(null);
     $this->checkPasswordStrength($newPassword);
     $customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
     $this->customerRepository->save($customer);
     // FIXME: Are we using the proper template here?
     try {
         $this->sendPasswordResetNotificationEmail($customer);
     } catch (MailException $e) {
         $this->logger->critical($e);
     }
     return true;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:30,代码来源:AccountManagement.php

示例4: _saveAddresses

 /**
  * Save/delete customer address
  *
  * @param \Magento\Customer\Model\Customer $customer
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _saveAddresses(\Magento\Customer\Model\Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     $this->saveAttribute($customer, 'default_billing');
     $this->saveAttribute($customer, 'default_shipping');
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:38,代码来源:Customer.php

示例5: loadByCustomer

 /**
  * Loading quote data by customer
  *
  * @param \Magento\Customer\Model\Customer|int $customer
  * @return $this
  */
 public function loadByCustomer($customer)
 {
     /* @TODO: remove this if after external usages of loadByCustomerId are refactored in MAGETWO-19935 */
     if ($customer instanceof \Magento\Customer\Model\Customer || $customer instanceof CustomerInterface) {
         $customerId = $customer->getId();
     } else {
         $customerId = (int) $customer;
     }
     $this->_getResource()->loadByCustomerId($this, $customerId);
     $this->_afterLoad();
     return $this;
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:18,代码来源:Quote.php

示例6: setCustomer

 /**
  * Set customer model and the customer id in session
  *
  * @param   Customer $customerModel
  * @return  $this
  * @deprecated use setCustomerId() instead
  */
 public function setCustomer(Customer $customerModel)
 {
     $this->_customerModel = $customerModel;
     $this->_httpContext->setValue(\Magento\Customer\Helper\Data::CONTEXT_GROUP, $customerModel->getGroupId(), \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
     $this->setCustomerId($customerModel->getId());
     if (!$customerModel->isConfirmationRequired() && $customerModel->getConfirmation()) {
         $customerModel->setConfirmation(null)->save();
     }
     /**
      * The next line is a workaround.
      * It is used to distinguish users that are logged in from user data set via methods similar to setCustomerId()
      */
     $this->unsIsCustomerEmulated();
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:22,代码来源:Session.php

示例7: push

 /**
  * Replace existing customer model with a new one.
  *
  * @param Customer $customer
  * @return $this
  */
 public function push(Customer $customer)
 {
     $this->customerRegistryById[$customer->getId()] = $customer;
     $emailKey = $this->getEmailKey($customer->getEmail(), $customer->getWebsiteId());
     $this->customerRegistryByEmail[$emailKey] = $customer;
     return $this;
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:13,代码来源:CustomerRegistry.php

示例8: getCustomer

 /**
  * Retrieve customer model object
  *
  * @return \Magento\Customer\Model\Customer
  */
 public function getCustomer()
 {
     /**
      * @TODO: Remove the method after all external usages are refactored in MAGETWO-19930
      * _customer and _customerFactory variables should be eliminated as well
      */
     if (null === $this->_customer) {
         $this->_customer = $this->_customerFactory->create();
         $customerId = $this->getCustomerId();
         if ($customerId) {
             $this->_customer->load($customerId);
             if (!$this->_customer->getId()) {
                 $this->_customer->setCustomerId(null);
             }
         }
     }
     return $this->_customer;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:23,代码来源:Quote.php

示例9: setCustomer

 /**
  * Specify address customer
  *
  * @param Customer $customer
  * @return $this
  */
 public function setCustomer(Customer $customer)
 {
     $this->_customer = $customer;
     $this->setCustomerId($customer->getId());
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:12,代码来源:Address.php

示例10: getCustomerLastQuoteId

 /**
  * get customer last quote id
  *
  */
 public function getCustomerLastQuoteId(\Magento\Customer\Model\Customer $customer)
 {
     $storeIds = $this->_storeManager->getWebsite($customer->getWebsiteId())->getStoreIds();
     $collection = $this->_quoteCollection->create()->addFieldToFilter('customer_id', $customer->getId())->addFieldToFilter('store_id', array('in' => $storeIds))->setPageSize(1)->setOrder('entity_id');
     if ($collection->count()) {
         return $collection->getFirstItem();
     } else {
         return false;
     }
 }
开发者ID:ThomasNegeli,项目名称:dotmailer-magento2-extension,代码行数:14,代码来源:Order.php

示例11: _saveAddresses

 /**
  * Save/delete customer address
  *
  * @param \Magento\Customer\Model\Customer $customer
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _saveAddresses(\Magento\Customer\Model\Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     $changedAddresses = [];
     $changedAddresses['default_billing'] = $customer->getData('default_billing');
     $changedAddresses['default_shipping'] = $customer->getData('default_shipping');
     $this->_getWriteAdapter()->update($this->getTable('customer_entity'), $changedAddresses, $this->_getWriteAdapter()->quoteInto('entity_id = ?', $customer->getId()));
     return $this;
 }
开发者ID:shazal,项目名称:magento2,代码行数:40,代码来源:Customer.php

示例12: getCustomerLastQuoteId

 /**
  * Get customer last quote id.
  *
  * @param \Magento\Customer\Model\Customer $customer
  *
  * @return bool|mixed
  */
 public function getCustomerLastQuoteId(\Magento\Customer\Model\Customer $customer)
 {
     $storeIds = $this->storeManager->getWebsite($customer->getWebsiteId())->getStoreIds();
     $collection = $this->quoteCollection->create()->addFieldToFilter('customer_id', $customer->getId())->addFieldToFilter('store_id', ['in' => $storeIds])->setPageSize(1)->setOrder('entity_id');
     if ($collection->getSize()) {
         //@codingStandardsIgnoreStart
         return $collection->getFirstItem();
         //@codingStandardsIgnoreEnd
     } else {
         return false;
     }
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:19,代码来源:Order.php

示例13: createQuote

 /**
  * Create a quote object with customer
  *
  * @param array $quoteData
  * @param \Magento\Customer\Model\Customer $customer
  * @return \Magento\Sales\Model\Quote
  */
 protected function createQuote($quoteData, $customer)
 {
     /** @var \Magento\Customer\Service\V1\CustomerAddressServiceInterface $addressService */
     $addressService = $this->objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAddressServiceInterface');
     /** @var array $shippingAddressOverride */
     $shippingAddressOverride = empty($quoteData['shipping_address']) ? [] : $quoteData['shipping_address'];
     /** @var  \Magento\Customer\Model\Address $shippingAddress */
     $shippingAddress = $this->createCustomerAddress($shippingAddressOverride, $customer->getId());
     /** @var \Magento\Sales\Model\Quote\Address $quoteShippingAddress */
     $quoteShippingAddress = $this->objectManager->create('Magento\\Sales\\Model\\Quote\\Address');
     $quoteShippingAddress->importCustomerAddressData($addressService->getAddress($shippingAddress->getId()));
     /** @var array $billingAddressOverride */
     $billingAddressOverride = empty($quoteData['billing_address']) ? [] : $quoteData['billing_address'];
     /** @var  \Magento\Customer\Model\Address $billingAddress */
     $billingAddress = $this->createCustomerAddress($billingAddressOverride, $customer->getId());
     /** @var \Magento\Sales\Model\Quote\Address $quoteBillingAddress */
     $quoteBillingAddress = $this->objectManager->create('Magento\\Sales\\Model\\Quote\\Address');
     $quoteBillingAddress->importCustomerAddressData($addressService->getAddress($billingAddress->getId()));
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Sales\\Model\\Quote');
     $quote->setStoreId(1)->setIsActive(true)->setIsMultiShipping(false)->assignCustomerWithAddressChange($customer, $quoteBillingAddress, $quoteShippingAddress)->setCheckoutMethod($customer->getMode())->setPasswordHash($customer->encryptPassword($customer->getPassword()));
     return $quote;
 }
开发者ID:,项目名称:,代码行数:30,代码来源:

示例14: setCustomer

 /**
  * Set customer model and the customer id in session
  *
  * @param   Customer $customerModel
  * @return  $this
  * @deprecated use setCustomerId() instead
  */
 public function setCustomer(Customer $customerModel)
 {
     $this->_customerModel = $customerModel;
     $this->_httpContext->setValue(\Magento\Customer\Helper\Data::CONTEXT_GROUP, $customerModel->getGroupId(), \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
     $this->setCustomerId($customerModel->getId());
     if (!$customerModel->isConfirmationRequired() && $customerModel->getConfirmation()) {
         $customerModel->setConfirmation(null)->save();
     }
     return $this;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:17,代码来源:Session.php


注:本文中的Magento\Customer\Model\Customer::getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。