duanjiaren8188 2015-06-03 10:41
浏览 17

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

I am working on a custom Magento(1.9.0.1) extension.

Let me show you what i have done already.

enter image description here

Here is the code for this Adminhtml form:

<?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!

  • 写回答

1条回答 默认 最新

  • dongpei2835 2015-06-03 23:35
    关注

    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('*'); }

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c