.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. 每个客户有多个客户群
- 3. 为每个客户定制
- 4. Magento:将客户的taxvat编号添加到帐单地址(地址模板)
- 5. 独特的客户经理
- 6. 每个用户的独特颜色
- 7. 如何为每个客户
- 8. 多个NetworkStreams为每个客户端
- 9. 删除特定atrribute
- 10. 为多个客户端同时提供独特的结果
- 11. 为每个用户创建独特的链接
- 12. 独特的django管理网站为每个不同的用户
- 13. 为每个用户生成独特的SALT?
- 14. 特价客户群在magento的折扣
- 15. SQL为每个客户查找下一个日期,SQL对于每个客户?
- 16. Magento每个客户的产品可见度
- 17. 为包括全局用户在内的每个用户实施独特价值
- 18. 让客户在Magento
- 19. 如何给每个用户一个独特的网址
- 20. 在magento中将每个客户的产品数量限制为1
- 21. Solr + Spring Roo每个客户的独立索引
- 22. 每个客户端的服务器单独连接
- 23. 烧瓶中的每个客户端请求的独立数据
- 24. Magento的API不工作,为客户
- 25. 我如何为每个客户ID设置单独的订单ID?
- 26. magento客户创建和客户将被转换为常规客户
- 27. Magento每个类别的特定属性
- 28. 多个独特的客户端使用socket.io和快递
- 29. 独特的Id:是一个独特的用户名+ currentMilliseconds足够好,为一个独特的Id
- 30. 每个用户独特的有序号码
:
而在你的观察员 if($ result!== true){error = array_merge($ errors,$ result); } ... – karpa 2012-03-14 14:01:32