简体   繁体   English

Magento / PHP-为选定客户组中的所有客户获取电话,电子邮件,姓名

[英]Magento/PHP - Get Phones, Emails, Names for all customers in a selected customer group

I am working on a custom Magento(1.9.0.1) extension. 我正在开发自定义的Magento(1.9.0.1)扩展。

Let me show you what i have done already. 让我告诉你我已经做了什么。

在此处输入图片说明

Here is the code for this Adminhtml form: 这是此Adminhtml表单的代码:

<?php

class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Sendmass_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
    {

        public function _prepareLayout() 
           {
              $ExtensionPath = Mage::getModuleDir('js', 'VivasIndustries_SmsNotification'); 
              $head = $this->getLayout()->getBlock('head');
              $head->addJs('jquery.js');
              $head->addJs('vivas.js');

              return parent::_prepareLayout();
           }

        protected function _prepareForm()
            {
            $form = new Varien_Data_Form(array(
                                    'id' => 'edit_form',
                                    'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                                    'method' => 'post',
                                 ));

                $fieldset = $form->addFieldset('edit_form', array('legend'=>Mage::helper('smsnotification')->__('SMS Information')));

                $CustomerGroups = Mage::getResourceModel('customer/group_collection')->toOptionArray();

                $smsprice_value = Mage::getStoreConfig('vivas/smsprice/smsprice_value');
                $smsprice_tag = Mage::getStoreConfig('vivas/smsprice/smsprice_tag');

                $customerArray=array();
                foreach($CustomerGroups as $each){

                     $count=Mage::getResourceModel('customer/customer_collection')
                                ->addAttributeToFilter('group_id',$each['value'])->getSize();
                $SMSPrice = $count * $smsprice_value;               
                     $customerArray[]=array('value'=> $each['value'],'label'=> $each['label'].' - ('.$count.' Members) - ('.$SMSPrice.' '.$smsprice_tag.')');

                }

                $CustomerGroups = array_merge(array('' => ''), $customerArray);

                $fieldset->addField('customergroups', 'select',
                        array(
                            'name'      => 'customergroups',
                            'label'     => Mage::helper('smsnotification')->__('Customer Group'),
                            'class'     => 'required-entry',
                            'after_element_html' => '<br><small>If customer group is not selected the SMS will be sended<br> to all store members!</small>',
                            'values'    => $CustomerGroups
                        )
                    );


                $fieldset->addField('smstext', 'textarea', array(
                          'label'     => Mage::helper('smsnotification')->__('SMS Text'),
                          'class'     => 'required-entry',
                          'required'  => true,
                          'name'      => 'smstext',
                          'onclick' => "",
                          'onkeyup' => "CheckLetterSize(this)",
                          'after_element_html' => '<br><b style="color:brown;"><span id="charNum"></span><span id="charNum1"></span></b><br><small>SMS text must <b>NOT</b> be longer then 160 characters!</small>',
                          'tabindex' => 1
                        ));






                if ( Mage::getSingleton('adminhtml/session')->getsmsnotificationData() )
                    {
                        $form->setValues(Mage::getSingleton('adminhtml/session')->getsmsnotificationData());
                        Mage::getSingleton('adminhtml/session')->setsmsnotificationData(null);
                    } elseif ( Mage::registry('smsnotification_data') ) {
                        $form->setValues(Mage::registry('smsnotification_data')->getData());
                    }
                // Add these two lines


                $form->setUseContainer(true);
                $this->setForm($form);

                ////

                return parent::_prepareForm();
            }
    }

When this form is submitted i want to get all Names, phones and emails of the members in the selected group. 提交此表单后,我想获取所选组中成员的所有姓名,电话和电子邮件。 The second thing is, when no customer group is selected it must give me names, phones and emails for all customers in the store. 第二件事是,当未选择任何客户组时,必须为我提供商店中所有客户的姓名,电话和电子邮件。

I used to get information about the user from Order information like this: 我曾经从这样的订单信息中获取有关用户的信息:

    class VivasIndustries_SmsNotification_Model_Observer
    {
        public function orderSaved(Varien_Event_Observer $observer)
        {
            /** **/

        $CustomerPhone = $observer->getOrder()->getBillingAddress()->getTelephone();
        $CustomerName = $observer->getOrder()->getBillingAddress()->getName();
        $CustomerEmail = $observer->getOrder()->getBillingAddress()->getEmail();
        } 
      }

I know that this is not even close to what i need but i don't know how to get this information. 我知道这甚至与我所需的资源不尽相同,但我不知道如何获取此信息。

Can you please help me out ? 你能帮我吗?

Thanks in advance! 提前致谢!

In your admin controller, where the form is posted: $groupId = $this->getRequest()->getPost('customergroups', ''); if (!empty($groupId)) { //Get customers from a group $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*') ->addFieldToFilter('group_id', $groupId); } else { //Get all customers $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*'); } 在您的管理控制器中,表单的发布位置: $groupId = $this->getRequest()->getPost('customergroups', ''); if (!empty($groupId)) { //Get customers from a group $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*') ->addFieldToFilter('group_id', $groupId); } else { //Get all customers $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*'); } $groupId = $this->getRequest()->getPost('customergroups', ''); if (!empty($groupId)) { //Get customers from a group $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*') ->addFieldToFilter('group_id', $groupId); } else { //Get all customers $customers = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('*'); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM