本文整理汇总了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();
}
示例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;
}
示例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 [];
}
示例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;
}
示例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)];
}
示例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];
}
示例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();
}
}
示例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());
}
}
示例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());
}
示例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();
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例15: _getCustomerGroupId
/**
* @param Product $product
* @return int
*/
protected function _getCustomerGroupId($product)
{
if ($product->getCustomerGroupId() !== null) {
return $product->getCustomerGroupId();
}
return $this->_customerSession->getCustomerGroupId();
}