php Magento-Customer-Helper-Session-CurrentCustomer类(方法)实例源码

下面列出了php Magento-Customer-Helper-Session-CurrentCustomer 类(方法)源码代码实例,从而了解它的用法。

作者:shabbirvividad    项目:magento   
/**
  * Get the logged in customer
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface|null
  */
 public function getCustomer()
 {
     try {
         return $this->currentCustomer->getCustomer();
     } catch (NoSuchEntityException $e) {
         return null;
     }
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * {@inheritdoc}
  */
 public function getSectionData()
 {
     if (!$this->currentCustomer->getCustomerId()) {
         return [];
     }
     $customer = $this->currentCustomer->getCustomer();
     return ['fullname' => $this->customerViewHelper->getCustomerName($customer), 'firstname' => $customer->getFirstname()];
 }

作者:pradeep-wagent    项目:magento   
public function testGetConfigWithEmptyCustomer()
 {
     $customerId = 0;
     $expected = ['payment' => ['paypalBillingAgreement' => ['agreements' => [], 'transportName' => AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID]]];
     $this->currentCustomerMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->agreementFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($expected, $this->configProvider->getConfig());
 }

作者:Doabilit    项目:magento2de   
/**
  * {@inheritdoc}
  */
 public function getSectionData()
 {
     $customerId = $this->currentCustomer->getCustomerId();
     if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
         return ['askToCreate' => true, 'confirmUrl' => $this->escaper->escapeUrl($this->urlBuilder->getUrl($this->startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])), 'confirmMessage' => $this->escaper->escapeJsQuote(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'))];
     }
     return [];
 }

作者:shabbirvividad    项目:magento   
/**
  * Return the full name of the customer currently logged in
  *
  * @return string|null
  */
 public function getCustomerName()
 {
     try {
         $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customer));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }

作者:nja7    项目:magento   
/**
  * Return collection of reviews
  *
  * @return array|\Magento\Review\Model\Resource\Review\Product\Collection
  */
 public function getReviews()
 {
     if (!($customerId = $this->currentCustomer->getCustomerId())) {
         return [];
     }
     if (!$this->_collection) {
         $this->_collection = $this->_collectionFactory->create();
         $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($customerId)->setDateOrder()->setPageSize(5)->load()->addReviewSummary();
     }
     return $this->_collection;
 }

作者:buskamuz    项目:magento2-skeleto   
public function testGetCollection()
 {
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(array('id' => 42))));
     $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242));
     $this->collection->expects($this->any())->method('addStoreFilter')->with(42)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addCustomerFilter')->with(4242)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setDateOrder')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setPageSize')->with(5)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addReviewSummary')->with()->will($this->returnValue($this->collection));
     $this->assertSame($this->collection, $this->object->getCollection());
 }

作者:pradeep-wagent    项目:magento   
/**
  * Retrieve available customer billing agreements
  *
  * @return array
  */
 protected function getBillingAgreements()
 {
     $customerId = $this->currentCustomer->getCustomerId();
     $data = [];
     if (!$customerId) {
         return $data;
     }
     $collection = $this->agreementFactory->create()->getAvailableCustomerBillingAgreements($customerId);
     foreach ($collection as $item) {
         $data[] = ['id' => $item->getId(), 'referenceId' => $item->getReferenceId()];
     }
     return $data;
 }

作者:aies    项目:magento   
/**
  * Return true if order(s) has one or more downloadable products
  *
  * @return bool
  */
 public function getOrderHasDownloadable()
 {
     $hasDownloadableFlag = $this->_checkoutSession->getHasDownloadableProducts(true);
     if (!$this->isOrderVisible()) {
         return false;
     }
     /**
      * if use guest checkout
      */
     if (!$this->currentCustomer->getCustomerId()) {
         return false;
     }
     return $hasDownloadableFlag;
 }

作者:nja7    项目:magento   
/**
  * Class constructor
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $purchased = $this->_linksFactory->create()->addFieldToFilter('customer_id', $this->currentCustomer->getCustomerId())->addOrder('created_at', 'desc');
     $this->setPurchased($purchased);
     $purchasedIds = [];
     foreach ($purchased as $_item) {
         $purchasedIds[] = $_item->getId();
     }
     if (empty($purchasedIds)) {
         $purchasedIds = [null];
     }
     $purchasedItems = $this->_itemsFactory->create()->addFieldToFilter('purchased_id', ['in' => $purchasedIds])->addFieldToFilter('status', ['nin' => [Item::LINK_STATUS_PENDING_PAYMENT, Item::LINK_STATUS_PAYMENT_REVIEW]])->setOrder('item_id', 'desc');
     $this->setItems($purchasedItems);
 }

作者:andrewhowdenco    项目:m2onk8   
/**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  * @magentoDataFixture Magento/Customer/_files/customer_no_address.php
  * @dataProvider getDefaultShippingDataProvider
  */
 public function testGetDefaultShipping($customerId, $expected)
 {
     if (!empty($customerId)) {
         $this->currentCustomer->setCustomerId($customerId);
     }
     $this->assertEquals($expected, $this->_block->getDefaultShipping());
 }

作者:pradeep-wagent    项目:magento   
/**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     /** @var \Magento\Paypal\Model\Config $config */
     $config = $this->_paypalConfigFactory->create();
     $config->setMethod($this->_paymentMethodCode);
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
         $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
         $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
     }
     return $result;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * test get customer method, method returns customer from service
  */
 public function testGetCustomerLoadCustomerFromService()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false));
     $this->customerSessionMock->expects($this->once())->method('getId')->will($this->returnValue($this->customerId));
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($this->equalTo($this->customerId))->will($this->returnValue($this->customerDataMock));
     $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
 }

作者:kidaa3    项目:magento2-platforms   
public function testSetLayoutWithoutAddress()
 {
     $addressId = 1;
     $customerPrefix = 'prefix';
     $customerFirstName = 'firstname';
     $customerMiddlename = 'middlename';
     $customerLastname = 'lastname';
     $customerSuffix = 'suffix';
     $title = 'title';
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMock();
     $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($addressId);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willThrowException(\Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', $addressId));
     $newAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMock();
     $this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($newAddressMock);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->currentCustomerMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $customerMock->expects($this->once())->method('getPrefix')->willReturn($customerPrefix);
     $customerMock->expects($this->once())->method('getFirstname')->willReturn($customerFirstName);
     $customerMock->expects($this->once())->method('getMiddlename')->willReturn($customerMiddlename);
     $customerMock->expects($this->once())->method('getLastname')->willReturn($customerLastname);
     $customerMock->expects($this->once())->method('getSuffix')->willReturn($customerSuffix);
     $newAddressMock->expects($this->once())->method('setPrefix')->with($customerPrefix)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setFirstname')->with($customerFirstName)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setMiddlename')->with($customerMiddlename)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setLastname')->with($customerLastname)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setSuffix')->with($customerSuffix)->willReturnSelf();
     $pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($pageTitleMock);
     $this->model->setData('title', $title);
     $pageTitleMock->expects($this->once())->method('set')->with($title)->willReturnSelf();
     $this->assertEquals($this->model, $this->model->setLayout($layoutMock));
     $this->assertEquals($layoutMock, $this->model->getLayout());
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->currentCustomer->getCustomerId()) {
         return parent::_toHtml();
     } else {
         return '';
     }
 }

作者:PayFas    项目:mod-magento_   
/**
  * Return billing agreement code for method
  *
  * @param string $code
  * @return null|string
  */
 protected function getBillingAgreementCode($code)
 {
     $pre = __METHOD__ . ' : ';
     $this->_logger->debug($pre . 'bof');
     $customerId = $this->currentCustomer->getCustomerId();
     $this->config->setMethod($code);
     $this->_logger->debug($pre . 'eof');
     // always return null
     return $this->payfastHelper->shouldAskToCreateBillingAgreement($this->config, $customerId);
 }

作者:pradeep-wagent    项目:magento   
/**
  * Get all tax rates JSON for all product tax classes.
  *
  * @return string
  */
 public function getAllRatesByProductClassJson()
 {
     $result = [];
     foreach ($this->productTaxClassSource->getAllOptions() as $productTaxClass) {
         $taxClassId = $productTaxClass['value'];
         $taxRate = $this->calculationService->getDefaultCalculatedRate($taxClassId, $this->currentCustomer->getCustomerId(), $this->getStore()->getId());
         $result["value_{$taxClassId}"] = $taxRate;
     }
     return $this->jsonHelper->jsonEncode($result);
 }

作者:shabbirvividad    项目:magento   
/**
  * @return int
  */
 public function getCompareItems()
 {
     if (!$this->_compareItems) {
         $this->_compareItems = $this->_createProductCompareCollection()->setStoreId($this->_storeManager->getStore()->getId());
         $this->_compareItems->setCustomerId($this->currentCustomer->getCustomerId());
         $this->_compareItems->setCustomerId($this->_customerSession->getCustomerId());
         $this->_compareItems->addAttributeToSelect('name')->useProductItem()->load();
     }
     return $this->_compareItems;
 }

作者:aies    项目:magento   
/**
  * @return \Magento\Customer\Service\V1\Data\Customer|null
  */
 public function getCustomer()
 {
     $customer = $this->getData('customer');
     if (is_null($customer)) {
         try {
             $customer = $this->_customerAccountService->getCustomer($this->currentCustomer->getCustomerId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             return null;
         }
         $this->setData('customer', $customer);
     }
     return $customer;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @return \Magento\Customer\Api\Data\CustomerInterface|null
  */
 public function getCustomer()
 {
     $customer = $this->getData('customer');
     if ($customer === null) {
         try {
             $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             return null;
         }
         $this->setData('customer', $customer);
     }
     return $customer;
 }


问题


面经


文章

微信
公众号

扫码关注公众号