Jump to content

Ajouter un champ "recherche par société" lors d'une création de facture


Recommended Posts

Bonjour je souhaiterais lors de la création d'une facture ajouter un champ de recherche exclusivement pour les clients ayant le champs société de remplie.

 

Fichier: ./controllers/admin/AdminOrdersController.php

 

Dans AdminOrdersController j'ai ajouté les lignes suivantes ressemblant à celle de la recherche client:

public function ajaxProcessSearchCustomers()
    {
        if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search'))))
            $to_return = array('customers' => $customers,
                                    'found' => true);
        else
            $to_return = array('found' => false);
        $this->content = Tools::jsonEncode($to_return);
    }

public function ajaxProcessSearchCompany()
    {
        if ($customers = Customer::searchByCompany(pSQL(Tools::getValue('company_search'))))
            $to_return = array('company' => $company,
                                    'found' => true);
        else
            $to_return = array('found' => false);
        $this->content = Tools::jsonEncode($to_return);
    }

Fichier:./adminxxxx/themes/default/template/controllers/orders/form.tpl

 

et ensuite dans form.tpl une nouvelle fonction ajax ressemblant à celle de recherche des clients.

function searchCustomers()
    {
        $.ajax({
            type:"POST",
            url : "{$link->getAdminLink('AdminOrders')|escape:'html'}",
            async: true,
            dataType: "json",
            data : {
                ajax: "1",
                token: "{$token}",
                tab: "AdminOrders",
                action: "searchCustomers",
                customer_search: $('#customer').val()},
            success : function(res)
            {
                if(res.found)
                {
                    var html = '<ul>';
                    $.each(res.customers, function() {
                        html += '<li class="customerCard"><div class="customerName"><a class="fancybox" href="{$link->getAdminLink('AdminCustomers')}&id_customer='+this.id_customer+'&viewcustomer&liteDisplaying=1">'+this.firstname+' '+this.lastname+'</a><span class="customerBirthday"> '+((this.birthday != '0000-00-00') ? this.birthday : '')+'</span></div>';
                        html += '<div class="customerEmail"><a href="mailto:'+this.email+'">'+this.email+'</div>';
                        html += '<a onclick="setupCustomer('+ this.id_customer+');return false;" href="#" class="id_customer button">{l s='Choose'}</a></li>';
                    });
                    html += '</ul>';
                }
                else
                    html = '<div class="warn">{l s='No customers found'}</div>';
                $('#customers').html(html);
                resetBind();
            }
        });
    }

function searchCompany()
	{
		$.ajax({
			type:"POST",
			url : "{$link->getAdminLink('AdminOrders')|escape:'html'}",
			async: true,
			dataType: "json",
			data : {
				ajax: "1",
				token: "{$token}",
				tab: "AdminOrders",
				action: "searchCompany",
				company_search: $('#company').val()},
			success : function(res)
			{
				if(res.found)
				{
					var html = '<ul>';
					$.each(res.company, function() {
						html += '<li class="customerCard"><div class="customerName"><a class="fancybox" href="{$link->getAdminLink('AdminCustomers')}&id_customer='+this.id_customer+'&viewcustomer&liteDisplaying=1">'+this.firstname+' '+this.lastname+'</a><span class="customerBirthday"> '+((this.birthday != '0000-00-00') ? this.birthday : '')+'</span></div>';
						html += '<div class="customerEmail"><a href="mailto:'+this.email+'">'+this.email+'</div>';
						html += '<a onclick="setupCustomer('+ this.id_customer+');return false;" href="#" class="id_customer button">{l s='Choose'}</a></li>';
					});
					html += '</ul>';
				}
				else
					html = '<div class="warn">{l s='No customers found'}</div>';
				$('#company').html(html);
				resetBind();
			}
		});
	}

Fichier:./adminxxxx/themes/default/template/controllers/orders/form.tpl

 

et ensuite le champ de recherche toujours sur le form.tpl

<input type="text" id="company" value="" />
		<p>{l s='Search a customer by typing the first letters of his/her name'}</p>
		<a class="fancybox button" href="{$link->getAdminLink('AdminCustomers')|escape:'htmlall':'UTF-8'}&addcustomer&liteDisplaying=1&submitFormAjax=1#">
			<img src="../img/admin/add.gif" title="new"/><span>{l s='Add new customer'}</span>
		</a>

Vu que je n'ai quasiment aucune connaissance en ajax est-ce quelqu'un pourrait me dire ou est-ce que je me trompe!

 

Merci.

 

Baptiste

Edited by pouc (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...