Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

simple php question


Guest

Recommended Posts

Posted

based on customer id, i give a % discount

however, i can't get more than one id to work.

 

for instance:

when customer # 111 logs into their account, the % will appear deducted automatically.

 

here's the code:

<?php
if ($customer_id == '1097') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
?>

 

my problem:

i need to offer more than 1 discount for different customers. i tried:

<?php
if ($customer_id == '1097') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
}else{ //if this is not the right customer, see if the next entry is them
if ($customer_id == '111') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
?>

 

 

the discounts work properly, but i just need to figure out how to get multiple discounts to work on the same page.

 

with my second code, only the first entry is recognized... the second customer's discount doesn't get logged.

Posted

<?php
if ($customer_id == '1097') { $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
} elseif($customer_id == '111') { $easy_discount->set('COUPON1','10% Discount', $cart->show_total() * 0.1);
}else {
echo "";
}
?>

doesn't seem to work either... any php guru's know what i'm missing? :(

Posted
based on customer id, i give a % discount

however, i can't get more than one id to work.

 

for instance:

when customer # 111 logs into their account, the % will appear deducted automatically.

 

here's the code:

<?php
if ($customer_id == '1097') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
?>

 

my problem:

i need to offer more than 1 discount for different customers. i tried:

<?php
if ($customer_id == '1097') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
}else{ //if this is not the right customer, see if the next entry is them
if ($customer_id == '111') $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);
?>

the discounts work properly, but i just need to figure out how to get multiple discounts to work on the same page.

 

with my second code, only the first entry is recognized... the second customer's discount doesn't get logged.

 

 

ofcourse not, there is only 1 customer_id per session.

 

 

I would use something like:

 

if ($cart->count_contents() > 0) {

switch ($customer_id) {

case '1097' : $easy_discount->set('COUPON1','10% Coupon Discount', $cart->show_total() * 0.1);

$easy_discount->set('COUPON2','5% Coupon extra Discount', $cart->show_total() * 0.05);

case '111' : $easy_discount->set('COUPON1','5% Coupon Discount', $cart->show_total() * 0.05);

case '1098' : $easy_discount->set('COUPON1','1% Coupon Discount', $cart->show_total() * 0.01);

}

} else { // clear them if cart goes empty

$easy_discount->clear('COUPON1');

$easy_discount->clear('COUPON2');

}

Treasurer MFC

Posted

it still seems to be only allowing the first customer (1097) the discount, also, if i disable:

$easy_discount->set('COUPON2','5% Coupon extra Discount', $cart->show_total() * 0.05);

 

..it changes #1097's discount to -$0.00 again, is there anyway to work around that?

Posted
it still seems to be only allowing the first customer (1097) the discount, also, if i disable:

$easy_discount->set('COUPON2','5% Coupon extra Discount', $cart->show_total() * 0.05);

 

..it changes #1097's discount to -$0.00 again, is there anyway to work around that?

 

explain what it is you want to do.

Treasurer MFC

Posted

i have 5 customers i need to give automatic discounts on their next order (all 10% off their next order). to make it easiest for them, i want this to occur the second they log in (thus is t he reason i put my codes in /account.php)

 

that's it :)

Posted
i have 5 customers i need to give automatic discounts on their next order (all 10% off their next order). to make it easiest for them, i want this to occur the second they log in (thus is t he reason i put my codes in /account.php)

 

that's it :)

 

 

if they all get the same discount then you can use a single set statement like :

 

 

$disc_cust_array = array('1097', // customer 1

'111', // customer 2

'123'); // customer 3

 

if ($cart->count_contents() > 0) {

if (in_array($customer_id, $disc_cust_array)) $easy_discount->set('CUSTD', '10% Discount for customer '. $customer_id, $cart->show_total()*0.1);

}

 

 

if you put this in account.php you have to realize that it gives a 10% discount of the total in the cart at that moment.

if the total changes later, the discount is not adjusted unless the user visits account again.

if you want that to happen at all times, place the code in application top.

Treasurer MFC

Posted

i put the code in checkout_shipping just after:

$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

 

 

 

 

 

 

i get this error:

Parse error: parse error, unexpected T_IF, expecting ')' in /home/**/public_html/checkout_shipping.php on line 203

 

 

 

line 203: if ($cart->count_contents() > 0) {

Posted

anyone know what this missing ) is from? i tried to add one, but i just got another error from it

Posted

just tried this again using only my own customer id, i get this:

 

Parse error: parse error, unexpected T_IF, expecting ')' in /home/**/public_html/checkout_shipping.php on line 203

 

203: if ($cart->count_contents() > 0) {

 

then i commented out:

//if ($cart->count_contents() > 0) {

 

 

new error:

Parse error: parse error, unexpected T_IF, expecting ')' in /home/**/public_html/checkout_shipping.php on line 204

 

204: if (in_array($customer_id, $disc_cust_array)) $easy_discount->set('CUSTD', '10% Discount for customer '.

 

 

am i putting this in the wrong spot on checkout_shipping, possibly?

Posted
just tried this again using only my own customer id, i get this:

 

Parse error: parse error, unexpected T_IF, expecting ')' in /home/**/public_html/checkout_shipping.php on line 203

 

203: if ($cart->count_contents() > 0) {

 

then i commented out:

//if ($cart->count_contents() > 0) {

new error:

Parse error: parse error, unexpected T_IF, expecting ')' in /home/**/public_html/checkout_shipping.php on line 204

 

204: if (in_array($customer_id, $disc_cust_array)) $easy_discount->set('CUSTD', '10% Discount for customer '.

am i putting this in the wrong spot on checkout_shipping, possibly?

 

 

try it like this:

 

$disc_cust_array = array('1097','111','123');

if ($cart->count_contents() > 0) {

if (in_array($customer_id, $disc_cust_array)) {

$easy_discount->set('CUSTD', '10% Discount for customer '. $customer_id, $cart->show_total()*0.1);

}

}

Treasurer MFC

Posted

thank you!!

one last request: how can i get rid of the customer number? i figure most of my customers skim things and if they see an extra number there, i don't want them to get spooked and abandon their cart

 

and if i need to add more customer id's, i just add one inbetween '111','123' like: '111','000','123' ?

Posted
thank you!!

one last request: how can i get rid of the customer number? i figure most of my customers skim things and if they see an extra number there, i don't want them to get spooked and abandon their cart

 

and if i need to add more customer id's, i just add one inbetween '111','123' like: '111','000','123' ?

 

in the description?

 

$easy_discount->set('CUSTD', '10% Discount especially for you', $cart->show_total()*0.1);

 

 

yes, you can add as many customer id's as you like.

Treasurer MFC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...