当前位置: 首页>>代码示例>>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;未经允许,请勿转载。