コード例 #1
0
 public function testGetSetCustomerGroupId()
 {
     $this->assertEquals($this->groupManagement->getNotLoggedInGroup()->getId(), $this->_model->getCustomerGroupId());
     $customerGroupId = 123;
     $this->_model->setCustomerGroupId($customerGroupId);
     $this->assertEquals($customerGroupId, $this->_model->getCustomerGroupId());
 }
コード例 #2
0
 /**
  * Handle customer VAT number if needed on collect_totals_before event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function dispatch(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Quote\Model\Quote\Address $quoteAddress */
     $quoteAddress = $observer->getQuoteAddress();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $quoteAddress->getQuote();
     $customer = $quote->getCustomer();
     $storeId = $customer->getStoreId();
     if ($customer->getCustomAttribute('disable_auto_group_change') && $customer->getCustomAttribute('disable_auto_group_change')->getValue() || false == $this->vatValidator->isEnabled($quoteAddress, $storeId)) {
         return;
     }
     $customerCountryCode = $quoteAddress->getCountryId();
     $customerVatNumber = $quoteAddress->getVatId();
     $groupId = null;
     if (empty($customerVatNumber) || false == $this->customerVat->isCountryInEU($customerCountryCode)) {
         $groupId = $customer->getId() ? $this->groupManagement->getDefaultGroup($storeId)->getId() : $this->groupManagement->getNotLoggedInGroup()->getId();
     } else {
         // Magento always has to emulate group even if customer uses default billing/shipping address
         $groupId = $this->customerVat->getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $this->vatValidator->validate($quoteAddress, $storeId), $storeId);
     }
     if ($groupId) {
         $quoteAddress->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
         $quote->setCustomerGroupId($groupId);
         $customer->setGroupId($groupId);
         $quote->setCustomer($customer);
     }
 }
コード例 #3
0
 /**
  * Handle customer VAT number if needed on collect_totals_before event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
     $shippingAssignment = $observer->getShippingAssignment();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $observer->getQuote();
     /** @var \Magento\Quote\Model\Quote\Address $address */
     $address = $shippingAssignment->getShipping()->getAddress();
     $customer = $quote->getCustomer();
     $storeId = $customer->getStoreId();
     if ($customer->getDisableAutoGroupChange() || false == $this->vatValidator->isEnabled($address, $storeId)) {
         return;
     }
     $customerCountryCode = $address->getCountryId();
     $customerVatNumber = $address->getVatId();
     $groupId = null;
     if (empty($customerVatNumber) || false == $this->customerVat->isCountryInEU($customerCountryCode)) {
         $groupId = $customer->getId() ? $this->groupManagement->getDefaultGroup($storeId)->getId() : $this->groupManagement->getNotLoggedInGroup()->getId();
     } else {
         // Magento always has to emulate group even if customer uses default billing/shipping address
         $groupId = $this->customerVat->getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $this->vatValidator->validate($address, $storeId), $storeId);
     }
     if ($groupId) {
         $address->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
         $quote->setCustomerGroupId($groupId);
         $customer->setGroupId($groupId);
         $quote->setCustomer($customer);
     }
 }
コード例 #4
0
 /**
  * @magentoDataFixture Magento/Catalog/Model/Resource/_files/product_simple.php
  */
 public function testAddTierPriceData()
 {
     $this->_collection->setFlag('tier_price_added', false);
     $this->_collection->addIdFilter(2);
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection', $this->_collection->addTierPriceData());
     $tierPrice = $this->_collection->getFirstItem()->getDataByKey('tier_price');
     $this->assertEquals($this->_groupManagement->getNotLoggedInGroup()->getId(), current($tierPrice)['cust_group']);
     $this->assertEquals($this->_groupManagement->getAllCustomersGroup()->getId(), next($tierPrice)['cust_group']);
     $this->assertTrue($this->_collection->getFlag('tier_price_added'));
 }
コード例 #5
0
 /**
  * Retrieve allowed customer groups
  *
  * @param int $groupId return name by customer group id
  * @return array|string
  */
 protected function _getCustomerGroups($groupId = null)
 {
     if ($this->_customerGroups === null) {
         $this->_customerGroups = [];
         foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $item) {
             $this->_customerGroups[$item->getId()] = $item->getCode();
         }
         $notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
         $this->_customerGroups[$notLoggedInGroup->getId()] = $notLoggedInGroup->getCode();
     }
     if ($groupId !== null) {
         return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null;
     }
     return $this->_customerGroups;
 }
コード例 #6
0
ファイル: Session.php プロジェクト: pradeep-wagento/magento2
 /**
  * Logout without dispatching event
  *
  * @return $this
  */
 protected function _logout()
 {
     $this->_customer = null;
     $this->_customerModel = null;
     $this->setCustomerId(null);
     $this->setCustomerGroupId($this->groupManagement->getNotLoggedInGroup()->getId());
     $this->destroy(['clear_storage' => false]);
     return $this;
 }
 /**
  * Apply catalog price rules to product on frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /* @var $collection ProductCollection */
     $collection = $observer->getEvent()->getCollection();
     $store = $this->storeManager->getStore($observer->getEvent()->getStoreId());
     $websiteId = $store->getWebsiteId();
     if ($observer->getEvent()->hasCustomerGroupId()) {
         $groupId = $observer->getEvent()->getCustomerGroupId();
     } else {
         if ($this->customerSession->isLoggedIn()) {
             $groupId = $this->customerSession->getCustomerGroupId();
         } else {
             $groupId = $this->groupManagement->getNotLoggedInGroup()->getId();
         }
     }
     if ($observer->getEvent()->hasDate()) {
         $date = new \DateTime($observer->getEvent()->getDate());
     } else {
         $date = (new \DateTime())->setTimestamp($this->localeDate->scopeTimeStamp($store));
     }
     $productIds = [];
     /* @var $product Product */
     foreach ($collection as $product) {
         $key = implode('|', [$date->format('Y-m-d H:i:s'), $websiteId, $groupId, $product->getId()]);
         if (!$this->rulePricesStorage->hasRulePrice($key)) {
             $productIds[] = $product->getId();
         }
     }
     if ($productIds) {
         $rulePrices = $this->resourceRuleFactory->create()->getRulePrices($date, $websiteId, $groupId, $productIds);
         foreach ($productIds as $productId) {
             $key = implode('|', [$date->format('Y-m-d H:i:s'), $websiteId, $groupId, $productId]);
             $this->rulePricesStorage->setRulePrice($key, isset($rulePrices[$productId]) ? $rulePrices[$productId] : false);
         }
     }
     return $this;
 }
コード例 #8
0
 /**
  * Get request object with information necessary for getting tax rate
  *
  * Request object contain:
  *  country_id (->getCountryId())
  *  region_id (->getRegionId())
  *  postcode (->getPostcode())
  *  customer_class_id (->getCustomerClassId())
  *  store (->getStore())
  *
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $shippingAddress
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $billingAddress
  * @param null|int $customerTaxClass
  * @param null|int|\Magento\Store\Model\Store $store
  * @param int $customerId
  * @return  \Magento\Framework\Object
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null, $customerId = null)
 {
     if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
         return $this->getRateOriginRequest($store);
     }
     $address = new \Magento\Framework\Object();
     $basedOn = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') {
         $basedOn = 'default';
     } else {
         if (($billingAddress === null || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === null || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') {
             if ($customerId) {
                 try {
                     $defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 try {
                     $defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 if ($basedOn == 'billing' && isset($defaultBilling) && $defaultBilling->getCountryId()) {
                     $billingAddress = $defaultBilling;
                 } elseif ($basedOn == 'shipping' && isset($defaultShipping) && $defaultShipping->getCountryId()) {
                     $shippingAddress = $defaultShipping;
                 } else {
                     $basedOn = 'default';
                 }
             } else {
                 $basedOn = 'default';
             }
         }
     }
     switch ($basedOn) {
         case 'billing':
             $address = $billingAddress;
             break;
         case 'shipping':
             $address = $shippingAddress;
             break;
         case 'origin':
             $address = $this->getRateOriginRequest($store);
             break;
         case 'default':
             $address->setCountryId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setRegionId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setPostcode($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store));
             break;
         default:
             break;
     }
     if ($customerTaxClass === null || $customerTaxClass === false) {
         if ($customerId) {
             $customerData = $this->customerRepository->getById($customerId);
             $customerTaxClass = $this->customerGroupRepository->getById($customerData->getGroupId())->getTaxClassId();
         } else {
             $customerTaxClass = $this->customerGroupManagement->getNotLoggedInGroup()->getTaxClassId();
         }
     }
     $request = new \Magento\Framework\Object();
     //TODO: Address is not completely refactored to use Data objects
     if ($address->getRegion() instanceof AddressRegion) {
         $regionId = $address->getRegion()->getRegionId();
     } else {
         $regionId = $address->getRegionId();
     }
     $request->setCountryId($address->getCountryId())->setRegionId($regionId)->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass);
     return $request;
 }
コード例 #9
0
 public function testGetNotLoggedInGroup()
 {
     $notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
     $this->assertEquals(GroupManagement::NOT_LOGGED_IN_ID, $notLoggedInGroup->getId());
 }