我使用在subtotal.phtml中返回錯誤的客戶組ID?
$id = Mage::getSingleton('customer/session')->getCustomerGroupId();
在應用程序\設計\前臺\基地\ DEFAULT \模板\稅\結賬\ subtotal.phtml得到客戶組ID。它總是返回1,這是不正確的。在其他模板文件中,它會返回相同的會話中的正確編號。
我作爲正確的客戶登錄,這不能成爲問題。
可能是什麼問題?
謝謝!
我使用在subtotal.phtml中返回錯誤的客戶組ID?
$id = Mage::getSingleton('customer/session')->getCustomerGroupId();
在應用程序\設計\前臺\基地\ DEFAULT \模板\稅\結賬\ subtotal.phtml得到客戶組ID。它總是返回1,這是不正確的。在其他模板文件中,它會返回相同的會話中的正確編號。
我作爲正確的客戶登錄,這不能成爲問題。
可能是什麼問題?
謝謝!
今天我偶然發現了同樣的問題,所以我想我會分享一下我的發現。
在我們的商店啓用自動分配到客戶組(配置 - >系統 - >客戶配置 - >創建新帳戶選項)設置已啓用。無論客戶何時登錄,我都會根據請求此信息的塊放置在佈局中的位置得到不同的客戶組ID的結果。然後我發現它是Minicart-Block搞亂了事情。
如果自動客戶組分配 t設置啓用,magento將從Mage_Sales
執行觀察者:Mage_Sales_Model_Observer::changeQuoteCustomerGroupId
。這是由於報價單上的小型收集總計。
此觀察者從報價中獲取地址,並驗證該地址是否存在增值稅ID,如果不存在,則選擇的國家是否爲歐盟的一部分。
如果不是,它會默認的用戶組分配給報價 - 但此外,它也將分配一個用戶組到用戶對象,這就是事情變得一團糟:
if ((empty($customerVatNumber) || !Mage::helper('core')->isCountryInEU($customerCountryCode))
&& !$isDisableAutoGroupChange
) {
$groupId = ($customerInstance->getId()) ? $customerHelper->getDefaultCustomerGroupId($storeId)
: Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
$quoteAddress->setPrevQuoteCustomerGroupId($quoteInstance->getCustomerGroupId());
$customerInstance->setGroupId($groupId);
$quoteInstance->setCustomerGroupId($groupId);
return;
}
問題是否有從不是在將產品添加到空購物車時在報價地址上設置的增值稅號或國家/地區。這些值只會在結帳過程中填寫,不能在之前輸入。這意味着對於每個有購物車但尚未結賬的顧客,Magento都會將默認用戶組分配給用戶。
我最終禁用了原始觀察者,並檢查引用地址上設置的country_id
屬性是否有任何值。
如果沒有設置,我會從默認地址獲取vat_id
和country_id
的值(如果有的話),將它們設置在報價地址上,然後推遲到原始觀察者。
public function changeQuoteCustomerGroupId(Varien_Event_Observer $observer)
{
/** @var $quoteAddress Mage_Sales_Model_Quote_Address */
$quoteAddress = $observer->getQuoteAddress();
$quoteInstance = $quoteAddress->getQuote();
$customerInstance = $quoteInstance->getCustomer();
if (!$quoteAddress->getCountryId())
{
// no country chosen, yet. Copy default billing addresses value to quote address.
$primaryBillingAddress = $customerInstance->getPrimaryAddress('default_' . $quoteAddress->getAddressType());
if ($primaryBillingAddress->getId())
{
$quoteAddress->setVatId($primaryBillingAddress->getVatId());
$quoteAddress->setCountryId($primaryBillingAddress->getCountryId());
}
}
Mage::getSingleton('sales/observer')->changeQuoteCustomerGroupId($observer);
return $this;
}
3210
<events>
<sales_quote_address_collect_totals_before>
<observers>
<sales_customer_validate_vat_number>
<type>disabled</type>
</sales_customer_validate_vat_number>
<fallback_customer_validate_vat_number>
<class>vendor/sales_observer</class>
<method>changeQuoteCustomerGroupId</method>
</fallback_customer_validate_vat_number>
</observers>
</sales_quote_address_collect_totals_before>
<events>
也許這將是有幫助的人。
你想獲得角色或組ID嗎?上面的代碼返回特定角色的組ID。什麼是你的組在管理端的組ID? –