當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Session::getCustomerGroupId方法代碼示例

本文整理匯總了PHP中Magento\Customer\Model\Session::getCustomerGroupId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::getCustomerGroupId方法的具體用法?PHP Session::getCustomerGroupId怎麽用?PHP Session::getCustomerGroupId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Customer\Model\Session的用法示例。


在下文中一共展示了Session::getCustomerGroupId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getCustomerGroupId

 /**
  * @return int
  */
 protected function getCustomerGroupId()
 {
     if ($this->product->getCustomerGroupId()) {
         return (int) $this->product->getCustomerGroupId();
     }
     return (int) $this->customerSession->getCustomerGroupId();
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:10,代碼來源:GroupPrice.php

示例2: execute

 /**
  * Apply catalog price rules to product on frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $product = $observer->getEvent()->getProduct();
     $pId = $product->getId();
     $storeId = $product->getStoreId();
     if ($observer->hasDate()) {
         $date = new \DateTime($observer->getEvent()->getDate());
     } else {
         $date = $this->localeDate->scopeDate($storeId);
     }
     if ($observer->hasWebsiteId()) {
         $wId = $observer->getEvent()->getWebsiteId();
     } else {
         $wId = $this->storeManager->getStore($storeId)->getWebsiteId();
     }
     if ($observer->hasCustomerGroupId()) {
         $gId = $observer->getEvent()->getCustomerGroupId();
     } elseif ($product->hasCustomerGroupId()) {
         $gId = $product->getCustomerGroupId();
     } else {
         $gId = $this->customerSession->getCustomerGroupId();
     }
     $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     if (!$this->rulePricesStorage->hasRulePrice($key)) {
         $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
         $this->rulePricesStorage->setRulePrice($key, $rulePrice);
     }
     if ($this->rulePricesStorage->getRulePrice($key) !== false) {
         $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
         $product->setFinalPrice($finalPrice);
     }
     return $this;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:39,代碼來源:ProcessFrontFinalPriceObserver.php

示例3: beforeGenerateXml

 /**
  * Before generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @return array
  */
 public function beforeGenerateXml(\Magento\Framework\View\LayoutInterface $subject)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->customerGroupId = $this->customerSession->getCustomerGroupId();
         $this->formKey = $this->session->getData(\Magento\Framework\Data\Form\FormKey::FORM_KEY);
     }
     return [];
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:DepersonalizePlugin.php

示例4: getValue

 /**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         $this->value = $this->resourceRuleFactory->create()->getRulePrice($this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
         $this->value = $this->value ? floatval($this->value) : false;
     }
     return $this->value;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:13,代碼來源:CatalogRulePrice.php

示例5: build

 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
     $currentDate = $this->dateTime->formatDate($timestamp, false);
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     return [$this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalogrule_product_price')], 't.product_id = child.entity_id', [])->where('parent.entity_id = ? ', $productId)->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.rule_date = ?', $currentDate)->order('t.rule_price ' . Select::SQL_ASC)->limit(1)];
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:11,代碼來源:LinkedProductSelectBuilderByCatalogRulePrice.php

示例6: beforeLoad

 /**
  * @param Collection $productCollection
  * @param bool $printQuery
  * @param bool $logQuery
  * @return array
  */
 public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
 {
     if (!$productCollection->hasFlag('catalog_rule_loaded')) {
         $connection = $this->resource->getConnection();
         $store = $this->storeManager->getStore();
         $productCollection->getSelect()->joinLeft(['catalog_rule' => $this->resource->getTableName('catalogrule_product_price')], implode(' AND ', ['catalog_rule.product_id = e.entity_id', $connection->quoteInto('catalog_rule.website_id = ?', $store->getWebsiteId()), $connection->quoteInto('catalog_rule.customer_group_id = ?', $this->customerSession->getCustomerGroupId()), $connection->quoteInto('catalog_rule.rule_date = ?', $this->dateTime->formatDate($this->localeDate->scopeDate($store->getId()), false))]), [CatalogRulePrice::PRICE_CODE => 'rule_price']);
         $productCollection->setFlag('catalog_rule_loaded', true);
     }
     return [$printQuery, $logQuery];
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:16,代碼來源:AddCatalogRulePrice.php

示例7: __construct

 /**
  * @param Product $saleableItem
  * @param float $quantity
  * @param CalculatorInterface $calculator
  * @param Session $customerSession
  */
 public function __construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, Session $customerSession)
 {
     $quantity = $quantity ?: 1;
     parent::__construct($saleableItem, $quantity, $calculator);
     $this->customerSession = $customerSession;
     if ($saleableItem->hasCustomerGroupId()) {
         $this->customerGroup = (int) $saleableItem->getCustomerGroupId();
     } else {
         $this->customerGroup = (int) $this->customerSession->getCustomerGroupId();
     }
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:17,代碼來源:TierPrice.php

示例8: testGetCustomerMissingCustomer

 public function testGetCustomerMissingCustomer()
 {
     $moduleManager = $this->objectManager->get('Magento\\Framework\\Module\\Manager');
     if ($moduleManager->isEnabled('Magento_PageCache')) {
         $customerDataFactory = $this->objectManager->create('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory');
         $customerData = $customerDataFactory->create()->setGroupId($this->_customerSession->getCustomerGroupId());
         $this->assertEquals($customerData, $this->_block->getCustomer());
     } else {
         $this->assertNull($this->_block->getCustomer());
     }
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:11,代碼來源:AddressTest.php

示例9: testEmulateCustomer

 /**
  * @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());
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:18,代碼來源:EmulateCustomerTest.php

示例10: __construct

 /**
  * @param Product $saleableItem
  * @param float $quantity
  * @param CalculatorInterface $calculator
  * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
  * @param Session $customerSession
  * @param GroupManagementInterface $groupManagement
  */
 public function __construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, Session $customerSession, GroupManagementInterface $groupManagement)
 {
     $quantity = $quantity ?: 1;
     parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
     $this->customerSession = $customerSession;
     $this->groupManagement = $groupManagement;
     if ($saleableItem->hasCustomerGroupId()) {
         $this->customerGroup = (int) $saleableItem->getCustomerGroupId();
     } else {
         $this->customerGroup = (int) $this->customerSession->getCustomerGroupId();
     }
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:20,代碼來源:TierPrice.php

示例11: testEmulateCustomer

 /**
  * @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());
 }
開發者ID:zhangjiachao,項目名稱:magento2,代碼行數:18,代碼來源:EmulateCustomerTest.php

示例12: build

 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.qty = ?', 1)->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
         $select[] = $priceSelect;
     }
     return $select;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:17,代碼來源:LinkedProductSelectBuilderByTierPrice.php

示例13: getValue

 /**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         if ($this->product->hasData(self::PRICE_CODE)) {
             $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false;
         } else {
             $this->value = $this->getRuleResource()->getRulePrice($this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
             $this->value = $this->value ? floatval($this->value) : false;
             if ($this->value) {
                 $this->value = $this->priceCurrency->convertAndRound($this->value);
             }
         }
     }
     return $this->value;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:20,代碼來源:CatalogRulePrice.php

示例14: getCustomerGroupId

 /**
  * Getter for customer group id, return current customer group if not set
  *
  * @return int
  */
 public function getCustomerGroupId()
 {
     if ($this->customerGroupId === null) {
         return $this->customerSession->getCustomerGroupId();
     }
     return $this->customerGroupId;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:12,代碼來源:Item.php

示例15: _getCustomerGroupId

 /**
  * @param Product $product
  * @return int
  */
 protected function _getCustomerGroupId($product)
 {
     if ($product->getCustomerGroupId() !== null) {
         return $product->getCustomerGroupId();
     }
     return $this->_customerSession->getCustomerGroupId();
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:11,代碼來源:Price.php


注:本文中的Magento\Customer\Model\Session::getCustomerGroupId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。