Пример #1
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * {@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;
 }
 /**
  * {@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;
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * @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
0
 /**
  * @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());
     }
 }
Пример #16
0
 /**
  * @return bool|\Magento\Sales\Model\ResourceModel\Order\Collection
  */
 public function getOrders()
 {
     if (!($customerId = $this->_customerSession->getCustomerId())) {
         return false;
     }
     if (!$this->orders) {
         $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect('*')->addFieldToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->setOrder('created_at', 'desc');
     }
     return $this->orders;
 }
Пример #17
0
 /**
  * @return string
  */
 public function getScripts()
 {
     $html = '';
     foreach ($this->bxHelperData->getScripts() as $script) {
         $html .= $script;
     }
     if ($this->customerSession->getCustomerId()) {
         $html .= $this->bxHelperData->reportLogin($this->customerSession->getCustomerId());
     }
     return $html;
 }
 /**
  * Add Product to Compare Products List action
  *
  * Reset count of compared products cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $productId = $observer->getEvent()->getProduct()->getId();
     $viewData = ['product_id' => $productId];
     if ($this->_customerSession->isLoggedIn()) {
         $viewData['customer_id'] = $this->_customerSession->getCustomerId();
     } else {
         $viewData['visitor_id'] = $this->_customerVisitor->getId();
     }
     $this->_productCompFactory->create()->setData($viewData)->save()->calculate();
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $productId);
 }
 /**
  * Adds New Relic custom parameters per request for store, website, and logged in user if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName());
         $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName());
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname());
         }
     }
 }
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
Пример #21
0
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
Пример #22
0
 /**
  * Shared wishlist view page
  *
  * @return void
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     $customerId = $this->customerSession->getCustomerId();
     if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) {
         $this->getResponse()->setRedirect($this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->getListUrl($wishlist->getId()));
         return;
     }
     $this->registry->register('shared_wishlist', $wishlist);
     $this->_view->loadLayout();
     $this->_view->getLayout()->initMessages();
     $this->_view->renderLayout();
 }
 /**
  * Customer login action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return $this;
     }
     $visitorId = $this->_customerVisitor->getId();
     $customerId = $this->_customerSession->getCustomerId();
     $eventModel = $this->_eventFactory->create();
     $eventModel->updateCustomerType($visitorId, $customerId);
     $this->_productCompFactory->create()->updateCustomerFromVisitor()->calculate();
     $this->_productIndexFactory->create()->updateCustomerFromVisitor()->calculate();
     return $this;
 }
Пример #24
0
 /**
  * @inheritdoc
  */
 public function execute()
 {
     $response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     try {
         $publicHash = $this->getRequest()->getParam('public_hash');
         $customerId = $this->session->getCustomerId();
         $result = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId])->get();
         $response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         return $this->processBadRequest($response);
     }
     return $response;
 }
 protected function _populateCustomerData()
 {
     $result[self::CFG_CUST_BALANCE] = 0;
     if ($this->sessionCustomer) {
         $customerId = $this->sessionCustomer->getCustomerId();
         $assetTypeId = $this->repoAssetType->getIdByCode(\Praxigento\Wallet\Config::CODE_TYPE_ASSET_WALLET_ACTIVE);
         $account = $this->repoAccount->getByCustomerId($customerId, $assetTypeId);
         if ($account) {
             $balance = $account->getBalance();
             $result[self::CFG_CUST_BALANCE] = $balance;
         }
     }
     return $result;
 }
Пример #26
0
 /**
  * Returns list of payment tokens for current customer session
  *
  * @return PaymentTokenInterface[]
  */
 public function getCustomerSessionTokens()
 {
     $vaultPayments = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $vaultPayments;
     }
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return $vaultPayments;
     }
     $providerCode = $this->vaultPayment->getProviderCode($storeId);
     return $this->tokenManagement->getVisibleAvailableTokens($customerId, $providerCode);
 }
 /**
  * Return billing agreement information
  *
  * @return string
  */
 protected function _toHtml()
 {
     $agreementReferenceId = $this->_checkoutSession->getLastBillingAgreementReferenceId();
     $customerId = $this->_customerSession->getCustomerId();
     if (!$agreementReferenceId || !$customerId) {
         return '';
     }
     $agreement = $this->_agreementFactory->create()->load($agreementReferenceId, 'reference_id');
     if ($agreement->getId() && $customerId == $agreement->getCustomerId()) {
         $this->addData(['agreement_ref_id' => $agreement->getReferenceId(), 'agreement_url' => $this->getUrl('paypal/billing_agreement/view', ['agreement' => $agreement->getId()])]);
         return parent::_toHtml();
     }
     return '';
 }
 /**
  * Reports concurrent users 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->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()];
             $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
Пример #29
0
 /**
  * Shared wishlist view page
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     $customerId = $this->customerSession->getCustomerId();
     if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
         $resultRedirect->setUrl($this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->getListUrl($wishlist->getId()));
         return $resultRedirect;
     }
     $this->registry->register('shared_wishlist', $wishlist);
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
     return $resultPage;
 }
Пример #30
0
 /**
  * Add vote
  *
  * @param \Magento\Review\Model\Rating\Option $option
  * @return $this
  */
 public function addVote($option)
 {
     $connection = $this->getConnection();
     $optionData = $this->loadDataById($option->getId());
     $data = ['option_id' => $option->getId(), 'review_id' => $option->getReviewId(), 'percent' => $optionData['value'] / 5 * 100, 'value' => $optionData['value']];
     if (!$option->getDoUpdate()) {
         $data['remote_ip'] = $this->_remoteAddress->getRemoteAddress();
         $data['remote_ip_long'] = $this->_remoteAddress->getRemoteAddress(true);
         $data['customer_id'] = $this->_customerSession->getCustomerId();
         $data['entity_pk_value'] = $option->getEntityPkValue();
         $data['rating_id'] = $option->getRatingId();
     }
     $connection->beginTransaction();
     try {
         if ($option->getDoUpdate()) {
             $condition = ['vote_id = ?' => $option->getVoteId(), 'review_id = ?' => $option->getReviewId()];
             $connection->update($this->_ratingVoteTable, $data, $condition);
             $this->aggregate($option);
         } else {
             $connection->insert($this->_ratingVoteTable, $data);
             $option->setVoteId($connection->lastInsertId($this->_ratingVoteTable));
             $this->aggregate($option);
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollback();
         throw new \Exception($e->getMessage());
     }
     return $this;
 }