.Hi,
我試圖使屬性taxvat唯一爲每個客戶。 (特別是對於我從後端創建的用戶)。即沒有重複。
就像電子郵件屬性一樣,如果電子郵件已被使用,則會通知用戶使用其他電子郵件。
我試圖從eav_attribute更改「is_unique」爲「1」,但什麼都沒有發生。
你能幫我解決這個問題嗎?
感謝Magento獨特TaxVat atrribute爲每個客戶
0
A
回答
1
好吧,我找到了解決辦法。在 查找文件/app/code/core/Mage/Customer/Model/Form.php(不要忘了,而不是覆蓋。) 「公共職能是validateData(數組$數據)」
添加代碼的 的foreach($這 - >的getAttributes()作爲$屬性)
foreach ($this->getAttributes() as $attribute) {
...
...
//## code to add
if ($attribute->getIsUnique()) {
$cid = $this->getEntity()->getData('entity_id'); //get current customer id
$cli = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $data[$attribute->getAttributeCode()]);
//->addFieldToFilter('customer_id', array('neq' => $cid)); //exclude current user from results //###### not working......
$flag=0;
foreach ($cli as $customer) {
$dataid=$customer->getId();
if ($dataid != $cid) //if the value is from another customer_id
$flag |= 1; //we found a dup value
}
if ($flag) {
$label = $attribute->getStoreLabel();
$errors = array_merge($errors, Mage::helper('customer')->__('"%s" already used!',$label));
}
}
//## End of code to add
}
0
我一直在尋找該溶液一段時間內。但我注意到你所引用的form.php文件是magento的1.5版本。在版本1.6中,文件是不同的...在1.6版本中放置代碼的位置在哪裏?謝謝。
我找到了該文件。它位於/app/code/core/Mage/Eav/Model/form.php。 但我把代碼,並沒有在這裏工作......我不斷嘗試一個解決方案。
1
我修改了哪些Karpa寫道,使其更好地
if ($attribute->getIsUnique()) {
$cid = $this->getEntity()->getData('entity_id'); //get current customer id
$cli = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $data[$attribute->getAttributeCode()])
->addFieldToFilter('entity_id', array('neq' => $cid)); //exclude current user from results //###### not working......
if (count($cli)>0) {
$label = $attribute->getStoreLabel();
$errors = array_merge($errors, array(Mage::helper('customer')->__('"%s" already used!',$label)));
}
0
您可以創建一個事件:後添加
/**
* Check customer attribute which must be unique
*
* @param Varien_Event_Observer $observer
* @return $this
* @@see customer_save_before
*/
public function checkUniqueAttribute(Varien_Event_Observer $observer)
{
/** @var Mage_Customer_Model_Customer $customer */
$customer = $observer->getEvent()->getCustomer();
foreach ($customer->getAttributes() as $attribute) {
if ($attribute->getIsUnique()) {
$collection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $customer->getData($attribute->getAttributeCode()))
->addFieldToFilter('entity_id', array('neq' => $customer->getId()));
if ($collection->getSize()) {
Mage::throwException(sprintf(
'The value %s for %s is already used',
$customer->getData($attribute->getAttributeCode()),
$attribute->getStoreLabel()
));
}
}
}
return $this;
相關問題
- 1. Magento:將客戶的taxvat添加到計費地址
- 2. Magento以編程方式設置客戶DOB和Taxvat號碼
- 3. 每個客戶有多個客戶羣
- 4. magento爲特定客戶免費送貨
- 5. 爲每個客戶端強制實施一個獨特的websocket連接?
- 6. Magento:將客戶的taxvat編號添加到帳單地址(地址模板)
- 7. 爲每個客戶定製
- 8. 獨特的客戶經理
- 9. Django每個用戶的獨特模型
- 10. 每個用戶的獨特顏色
- 11. 如何爲每個客戶
- 12. Python的扭曲:更改目錄爲每個客戶端獨立
- 13. 單獨的子域爲每個客戶端
- 14. 多個NetworkStreams爲每個客戶端
- 15. 刪除特定atrribute
- 16. 爲多個客戶端同時提供獨特的結果
- 17. 生成每個客戶獨特的URL下載同一個文件
- 18. 如何爲每個獨特用戶建立這種關係?
- 19. 如何爲每個用戶製作獨特的模型?
- 20. 如何爲每個用戶創建獨特的會話? - Node.js
- 21. 爲每個用戶創建獨特的鏈接
- 22. 爲每個用戶生成獨特的SALT?
- 23. 獨特的django管理網站爲每個不同的用戶
- 24. SQL爲每個客戶查找下一個日期,SQL對於每個客戶?
- 25. 特價客戶羣在magento的折扣
- 26. 選擇每個客戶,每個客戶在許多日期
- 27. 每個獨特的價值
- 28. 每個TreeItem的獨特ContextMenu
- 29. 登錄客戶的獨特css?
- 30. Magento:限制產品最大數量每個客戶(不是每個訂單)
:
而在你的觀察員 if($ result!== true){error = array_merge($ errors,$ result); } ... – karpa 2012-03-14 14:01:32