PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

Bill me later module only for regular customers and maximum basket (download it here)

28 replies to this topic
#1
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Here is the extend "Bill me later module" based on the Cash-on-Delivery-Modul

Functions (You have to edit the billmelater.php in Line 31):

Exclude Carriers by ID
Maximum amount for the basket
Minimum orders before Billing is possible

Special thanks to the great d0m1n1k



Quote


The discussion:

Hi,
I search for a method to include a query in the "Bill me later"-Module. So only Customer with more than 5 orders can pay later by bill.

I include a query for a basketlimit and for carrier:

function hookPayment($params)

{
global $smarty;
if ((intval($params['cart']->id_carrier))==29) return;
if ((intval($params['cart']->getOrderTotal(true, 4)))>250) return;


But how can i include a query with "nb_orders" ?

Thanks in advance.
(I'm using Version 1.0)

Attached Files



#2
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Is really nobody out there who has an idea about this?

I think using this:

Quote


'.$this->l('Valid orders placed:').' '.$customerStats['nb_orders'].'



from the AdminOrders.php is a little help.

#3
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Really, really nobody out there who has an idea? Is this such a complicated question?

#4
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
 
$customer = new Customer($order->id_customer);
$customerStats = $customer->getStats();

then you sould be able to use $customerStats['nb_orders']

you might have to change the $order->id_customer to $cart->id_customer to get a result.

greetings

#5
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Thanks a lot. But this overcharges me a little bit.

Where should i put this code in? in the billmelater.php?

I dont know what to do.

#6
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
i'd put it into your function hookpayment ($params){ ...

tell me if it works

#7
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
This is the code of the billmelater.php


<?php
$smarty->debugging = true;
class BillMeLater extends PaymentModule
{
function __construct()
{
$this->name = 'billmelater';
$this->tab = 'Payment';
$this->version = 0.1;

parent::__construct();

/* The parent construct is required for translations */
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Rechnungskauf');
$this->description = $this->l('Kauf auf Rechnung');

}

function install()
{
parent::install();
$this->registerHook('payment');
$this->registerHook('paymentReturn');
}

function hookPayment($params)


{
global $smarty;
if ((intval($params['cart']->id_carrier))==29) return;
if ((intval($params['cart']->getOrderTotal(true, 4)))>250) return;
$customer = new Customer($cart->id_customer);
$customerStats = $customer->getStats();
if ((intval($params['cart']->nb_orders))<2) return;



/* Photo is copyrighted by Leticia Wilson - Fotolia.com, licenced to PrestaShop company */
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}

function hookPaymentReturn($params)
{
return $this->display(__FILE__, 'confirmation.tpl');
}
}

?>


No errors, but no effect.

#8
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
try

$customer = new Customer($cart->id_customer);
$customerStats = $customer->getStats();
if ((intval($customerStats->nb_orders))<2) return;

the return things are a bit confusing for me. whats the use of them?

#9
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
The same: No errors, no effect.
Customer has 3 orders (maybe i'm wrong with the logic?)


if ((intval($params['cart']->id_carrier))==29) return;


Customers outside Germany but inside the EU didnt see this Pay-Module.


if ((intval($params['cart']->getOrderTotal(true, 4)))>250) return;


Exludes all Carts with more then 250 Euro.

I have the code from the dutch-Forum.

#10
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts

global $smarty;

$customer = new Customer($cart->id_customer);
$customerStats = $customer->getStats();

if (intval($params['cart']->id_carrier)==29 && (intval($params['cart']->getOrderTotal(true, 4)))>250 && intval($customerStats->nb_orders)>5)
{
commands to be executed if all 3 are true
}


#11
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts

global $smarty;

$customer = new Customer($cart->id_customer);
$customerStats = $customer->getStats();

if ((intval($params['cart']->id_carrier))!=29 && (intval($params['cart']->getOrderTotal(true, 4)))<250 && intval($params['cart']->nb_orders)>5)


I have changed ==29 to !=29 because carrier with id=29 has to be excluded. This works, but


intval($params['cart']->nb_orders)>5


seems to have no effect

#12
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
hi thats because i had a bug inside ;)
check the last part again and you will notice that i've changed the $params['cart'] to $customerStats

#13
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts

if ((intval($params['cart']->id_carrier))!=29 && (intval($params['cart']->getOrderTotal(true, 4)))<250 && intval($customerStats->nb_orders)>2)


has also no effect the payment-module will not shown


if ((intval($params['cart']->id_carrier))!=29 && (intval($params['cart']->getOrderTotal(true, 4)))<250)


this code works

I seh gerade das Du deutsch sprichst. Was mach ich nur falsch?

#14
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
ich war schon länger am überlegn ob wir die sprache nicht wechseln sollten ;)

es könnte sein dass presta dich aus dem modul nicht auf die customer klasse lässt, wär zwar komisch aber möglich.


global $smarty;
$customers_id = $params['cart']->id_customer;

$hack_nb_orders = Db::getInstance()->getRow('
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid`) AS total_orders
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`id_customer` = '$customers_id'
AND o.valid = 1');

if (intval($params['cart']->id_carrier)==29 && (intval($params['cart']->getOrderTotal(true, 4)))>250 && intval($customerStats->nb_orders)>5)
{


oder


global $smarty;

$customer = new Customer($params['cart']->id_customer);
$customerStats = $customer->getStats();

if (intval($params['cart']->id_carrier)==29 && (intval($params['cart']->getOrderTotal(true, 4)))>250 && intval($customerStats->nb_orders)>2)
{

(versuch zuerst das letzte, ist sauberer ;) )

#15
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Sind da syntax-fehler drin? Ich hab nur eine weiße Seite....

#16
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Auch auf die Gefahr, dass ich langsam lästig werde:

1. Lösung führt zu weißer Seite

2. Lösung hat keinen Effekt

#17
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts

<?php
$smarty->debugging = true;
class BillMeLater extends PaymentModule
{
function __construct()
{
$this->name = 'billmelater';
$this->tab = 'Payment';
$this->version = 0.1;

parent::__construct();

/* The parent construct is required for translations */
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Rechnungskauf');
$this->description = $this->l('Kauf auf Rechnung');
}

function install()
{
parent::install();
$this->registerHook('payment');
$this->registerHook('paymentReturn');
}

function hookPayment($params)

{
global $smarty;
$customers_id = $params['cart']->id_customer;

$hack_nb_orders = Db::getInstance()->getRow('
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid`) AS total_orders
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`id_customer` = '$customers_id'
AND o.valid = 1');

if (intval($params['cart']->id_carrier)==29 && (intval($params['cart']->getOrderTotal(true, 4)))>250 && intval($customerStats->nb_orders)>5)
{


/* Photo is copyrighted by Leticia Wilson - Fotolia.com, licenced to PrestaShop company */
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}}

function hookPaymentReturn($params)
{
return $this->display(__FILE__, 'confirmation.tpl');
}
}

?>


Die komplette billmelater.php, die zur weissen Seite führt.

#18
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts

function hookPayment($params)
{
global $smarty;
$customer = new Customer($params['cart']->id_customer);
$customerStats = $customer->getStats();

if(intval($params['cart']->id_carrier)==29 && intval($params['cart']->getOrderTotal(true, 4))>250 && intval($customerStats[nb_orders])>6)
{
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}
}


funktioniert bei mir, hab mir das modul nun extra nachgebaut.
es sind definitiv in dem bereich keine syntaxfehler drinnen, ich kann dir auch die ganze datei schicken.
die bedingungen reagieren auch richtig auf veränderungen, wenn ich weniger als 250 im korb habe wirds nicht angezeigt, für kunden mit weniger als 6 bestellungen wirds auch nicht angezeigt.

#19
d0m1n1k

    PrestaShop Apprentice

  • Members
  • PipPip
  • 284 posts
in deiner lösung musst du in der zeile
 WHERE o.`id_customer` = '$customers_id'
vor und nach $customers_id noch einen punkt machen:
 WHERE o.`id_customer` = '.$customers_id.'


(würde dir aber sowieso empfehlen die lösung aus #17 zu verwenden)

#20
kdk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 231 posts
Inzwischen bin ich glaub ich zu blöd den Code zu kopieren. Ich bekomme immer nur eine weisse Seite. Könntest Du wirklich mal die ganze Datei dranhängen?