简体   繁体   中英

Magento/PHP - Get phones on all members in a customer group

I am working on a custom Magento extension. I am working around the Adminhtml part and i've created a custom form there.

Here is the form code:

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

Here is the code that i have in my save action:

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

This code is supposed to give me the group id when i press the submit button. But i have to get all the phones of these members in array like that:

$phones = array($phone);

How can i get all the phone numbers and make them in array ?

Thanks in advance!

this code is give you collection of customer in this group.. you can get by this code.

$customers = Mage::getModel('customer/customer')
                            ->getCollection()
                            ->addAttributeToSelect('*')
                            ->addFieldToFilter('group_id', $groupId);

    $phone=array();
    foreach($customers ans $customer)
    {
       $phone[]=$customer->getTelephone();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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