本文整理汇总了PHP中Magento\Customer\Model\Session::getCustomerId方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getCustomerId方法的具体用法?PHP Session::getCustomerId怎么用?PHP Session::getCustomerId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::getCustomerId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBillingAgreements
/**
* Retrieve billing agreements collection
*
* @return \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection
*/
public function getBillingAgreements()
{
if ($this->_billingAgreements === null) {
$this->_billingAgreements = $this->_agreementCollection->create()->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->setOrder('agreement_id', 'desc');
}
return $this->_billingAgreements;
}
示例2: _construct
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
//TODO: add full name logic
$orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('*')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')->addAttributeToFilter('customer_id', $this->_customerSession->getCustomerId())->addAttributeToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->addAttributeToSort('created_at', 'desc')->setPageSize('5')->load();
$this->setOrders($orders);
}
示例3: getSubscriptionObject
/**
* Fetch the subscription object. Create the subscriber by loading using the customerId.
*
* @return Subscriber
*/
public function getSubscriptionObject()
{
if ($this->_subscription === null) {
$this->_subscription = $this->_createSubscriber()->loadByCustomerId($this->_customerSession->getCustomerId());
}
return $this->_subscription;
}
示例4: _preDispatchValidateCustomer
/**
* Make sure customer is valid, if logged in
*
* By default will add error messages and redirect to customer edit form
*
* @param bool $redirect - stop dispatch and redirect?
* @param bool $addErrors - add error messages?
* @return bool
*/
protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
{
try {
$customerId = $this->_customerSession->getCustomerId();
$customer = $this->_customerAccountService->getCustomer($customerId);
} catch (NoSuchEntityException $e) {
return true;
}
if (isset($customer)) {
$validationResult = $this->_customerAccountService->validateCustomerData($customer, $this->_customerMetadataService->getAllCustomerAttributeMetadata());
if (!$validationResult->isValid()) {
if ($addErrors) {
foreach ($validationResult->getMessages() as $error) {
$this->messageManager->addError($error);
}
}
if ($redirect) {
$this->_redirect('customer/account/edit');
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
}
return false;
}
}
return true;
}
示例5: _prepareLayout
/**
* Prepare the layout of the address edit block.
*
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
// Init address object
if ($addressId = $this->getRequest()->getParam('id')) {
try {
$this->_address = $this->_addressRepository->getById($addressId);
if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) {
$this->_address = null;
}
} catch (NoSuchEntityException $e) {
$this->_address = null;
}
}
if ($this->_address === null || !$this->_address->getId()) {
$this->_address = $this->addressDataFactory->create();
$customer = $this->getCustomer();
$this->_address->setPrefix($customer->getPrefix());
$this->_address->setFirstname($customer->getFirstname());
$this->_address->setMiddlename($customer->getMiddlename());
$this->_address->setLastname($customer->getLastname());
$this->_address->setSuffix($customer->getSuffix());
}
$this->pageConfig->getTitle()->set($this->getTitle());
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
$postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']];
}
$this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
}
return $this;
}
示例6: _construct
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$orders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->addFieldToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->setOrder('created_at', 'desc');
$this->setOrders($orders);
$this->pageConfig->setTitle(__('My Orders'));
}
示例7: initOrders
/**
* Init customer order for display on front
*
* @return void
*/
protected function initOrders()
{
$customerId = $this->_customerSession->getCustomerId();
$orders = $this->_orderCollectionFactory->create()->addAttributeToFilter('customer_id', $customerId)->addAttributeToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->addAttributeToSort('created_at', 'desc')->setPage(1, 1);
//TODO: add filter by current website
$this->orders = $orders;
}
示例8: getUserId
/**
* Returns user ID. If it is not a customer, a hash of the visitor ID is generated with md5
* to differentiate from a customer ID
* @return string|int
*/
public function getUserId()
{
if ($this->isUserLoggedIn()) {
return $this->_customerSession->getCustomerId();
}
return $this->getUserIdByVisitor();
}
示例9: getConfig
/**
* Retrieve assoc array of checkout configuration
*
* @return array
*/
public function getConfig()
{
$vaultPayments = [];
$customerId = $this->customerSession->getCustomerId();
if (!$customerId) {
return $vaultPayments;
}
$storeId = $this->storeManager->getStore()->getId();
if (!$this->vaultPayment->isActive($storeId)) {
return $vaultPayments;
}
$vaultProviderCode = $this->vaultPayment->getProviderCode($storeId);
$componentProvider = $this->getComponentProvider($vaultProviderCode);
if (null === $componentProvider) {
return $vaultPayments;
}
$filters[] = $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)->setValue($customerId)->create();
$filters[] = $this->filterBuilder->setField(PaymentTokenInterface::IS_VISIBLE)->setValue(1)->create();
$filters[] = $this->filterBuilder->setField(PaymentTokenInterface::PAYMENT_METHOD_CODE)->setValue($vaultProviderCode)->create();
$searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create();
foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $index => $token) {
$component = $componentProvider->getComponentForToken($token);
$vaultPayments[VaultPaymentInterface::CODE . '_item_' . $index] = ['config' => $component->getConfig(), 'component' => $component->getName()];
}
return ['payment' => [VaultPaymentInterface::CODE => $vaultPayments]];
}
示例10: getWishlist
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getWishlist($wishlistId = null)
{
if ($this->wishlist) {
return $this->wishlist;
}
try {
if (!$wishlistId) {
$wishlistId = $this->request->getParam('wishlist_id');
}
$customerId = $this->customerSession->getCustomerId();
$wishlist = $this->wishlistFactory->create();
if (!$wishlistId && !$customerId) {
return $wishlist;
}
if ($wishlistId) {
$wishlist->load($wishlistId);
} elseif ($customerId) {
$wishlist->loadByCustomerId($customerId, true);
}
if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
throw new \Magento\Framework\Exception\NoSuchEntityException(__('The requested Wish List doesn\'t exist.'));
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->messageManager->addError($e->getMessage());
return false;
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t create the Wish List right now.'));
return false;
}
$this->wishlist = $wishlist;
return $wishlist;
}
示例11: canView
/**
* {@inheritdoc}
*/
public function canView(\Magento\Sales\Model\Order $order)
{
$customerId = $this->customerSession->getCustomerId();
$availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses();
if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) {
return true;
}
return false;
}
示例12: _sendPurchaseEvent
/**
* Record a customer-buys-product event in PredictionIO when the customer
* completes an order
*
* @param $productCollection
*/
private function _sendPurchaseEvent($productCollection)
{
foreach ($productCollection as $item) {
for ($i = 0; $i < $item->getQtyOrdered(); $i++) {
$this->_eventClient->saveCustomerBuyProduct($this->_customerSession->getCustomerId(), $item->getProductId());
}
}
return;
}
示例13: getCustomerSessionTokens
/**
* Returns list of payment tokens for current customer session
*
* @return PaymentTokenInterface[]
*/
public function getCustomerSessionTokens()
{
$vaultPayments = [];
$customerId = $this->session->getCustomerId();
if (!$customerId) {
return $vaultPayments;
}
return $this->tokenManagement->getVisibleAvailableTokens($customerId);
}
示例14: processViews
/**
* @param $productId
* @return bool|void
*/
public function processViews($productId)
{
if (!$this->_config->isEnabled()) {
return false;
}
if ($this->_customerSession->isLoggedIn()) {
return $this->_eventClient->saveCustomerViewProduct($this->_customerSession->getCustomerId(), $productId);
}
return false;
}
示例15: beforeDispatch
/**
* @param AbstractAction $subject
* @param RequestInterface $request
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
{
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost() && $this->notificationStorage->isExists(NotificationStorage::UPDATE_CUSTOMER_SESSION, $this->session->getCustomerId())) {
$customer = $this->customerRepository->getById($this->session->getCustomerId());
$this->session->setCustomerData($customer);
$this->session->setCustomerGroupId($customer->getGroupId());
$this->session->regenerateId();
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
}
}