Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 05-25-2009 06:25:17

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Exclude Catagory from Custom Sale Method

I have used the following code to Buy Y and Save X Amount. It works like a charm but I need to exclude one catagory form this Custom Sales Method any ideas?

Code:

$cartids = $this->globals('ecom.checkout_cartids');
$cosess  = $this->globals('ecom.checkout_cosess');

// +--
// | sale_amount   = The amount of the sale.
// | sale_items    = The number of items needed to get the sale.
// | sale_textshow = The text to be displayed for the sale.
// +--

$sale_amount    = 10;
$sale_items     = 2;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 20;
$sale_items     = 3;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 30;
$sale_items     = 4;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 40;
$sale_items     = 5;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 50;
$sale_items     = 6;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 60;
$sale_items     = 7;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 70;
$sale_items     = 8;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 80;
$sale_items     = 9;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 90;
$sale_items     = 10;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 100;
$sale_items     = 11;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

$sale_amount    = 110;
$sale_items     = 12;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

Offline

 

#2 05-25-2009 16:11:14

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

Pretty tricky to put it mildly since items may be in more than one category and there is no category information available once an item is in the cart and you're going through the checkout process.

Offline

 

#3 05-25-2009 20:54:56

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

How about excluding a product by id# all of our products has a five digit number like 11401 - 5 Ft Curtain Rod System ? I know that is in the cart and threw-out the checkout process ?

Offline

 

#4 05-26-2009 05:41:06

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

Excluding based on the product ID should be feasible yes.  I believe there are examples of how to accomplish it here in the fora.

Offline

 

#5 05-26-2009 06:06:19

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Can you please point me toward those. I have been searching the forums for about two days now and cant find anything that references this. Thanks

Offline

 

#6 05-26-2009 08:20:48

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

Guess there haven't been posted (which is why I said I believed there may have been) smile

In the custom sale method the item detail array(s) within the $cartids array contains the product IDs.  If you look at the provided example titled "Buy X Items Save Y Amount" you'll see a line of code that looks like this:

Code:

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

Within the $item array you'll find the id index which contains the product identifier ($item['id']).  That's what you'll want to check to determine whether or not you want to include or exclude a product.

Offline

 

#7 05-26-2009 11:06:47

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Cananyone make since of this? I am totally confused now !!

Guess there haven't been posted (which is why I said I believed there may have been)

In the custom sale method the item detail array(s) within the $cartids array contains the product IDs.  If you look at the provided example titled "Buy X Items Save Y Amount" you'll see a line of code that looks like this:

Code:
foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

Within the $item array you'll find the id index which contains the product identifier ($item['id']).  That's what you'll want to check to determine whether or not you want to include or exclude a product.

Offline

 

#8 05-26-2009 11:39:06

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

The foreach that goes through the $cartids array allows you to check each individual product identifier that is in the cart. As the pseudo code below shows, if the product identifier is NOT one that you want to exclude you may exclude it from being considered in your custom sale method.

Code:

foreach ($cartids as $cartid => $item) {
    $productid = $item['id'];
    if ($productid != 'id_to_exclude') {
        # Do something
    }
}

Offline

 

#9 05-26-2009 12:32:20

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

So the code would look like this:

// +--
// | sale_amount   = The amount of the sale.
// | sale_items    = The number of items needed to get the sale.
// | sale_textshow = The text to be displayed for the sale.
// +--

$sale_amount    = 10;
$sale_items     = 2;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {$productid = $item['id'];
    if ($productid != '11401') {
        # Do something
    }

foreach ($cartids as $cartid => $item) {$count = $count + $item['quantity'];}

if ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

Offline

 

#10 05-26-2009 12:59:42

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Exclude Catagory from Custom Sale Method

There would be no need to do the foreach statement twice, so it would look something like

Code:

foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if ($productid != '11401') {
        # Do something
        # or the code to get what you want.
    }

elseif ($count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement.

it could also be done like

Code:

foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (($productid != '11401') && ($count >= $sale_items)) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement.

John

Last edited by dh783 (05-26-2009 13:06:05)

Offline

 

#11 05-26-2009 13:19:58

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

DUH !! Makes since now ! Thanks a million. I am getting pressured by my boss to get this thing done. I have only been working on everything he wants for two weeks. He thinks everything should be done in two days.

One other question if he wants to add other excluded products it would show like this:

((productid != 'id1','id2','id3') = with comma's

or

((productid != 'id1''id2''id3') = without comma's

correct?

Thanks again....

Offline

 

#12 05-26-2009 13:28:08

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

Neither.

Code:

$productid != 'id1' or $productid != 'id2' or $productid != 'id3'

Offline

 

#13 05-26-2009 13:39:33

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

If you want to get "fancy" and perhaps make it a little easier, especially if you end up with a lot of exclusions, this method will work also.

Code:

$excludeids = array('id1','id2','id3','id4');
if (in_array($productid,$excludeids)) {
# this area is for excluded IDs
} else {
# this area is for IDs that are NOT being excluded
}

Offline

 

#14 05-26-2009 14:09:06

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Okay here is the code: (It deosnt work)

// +--
// | sale_amount   = The amount of the sale.
// | sale_items    = The number of items needed to get the sale.
// | sale_textshow = The text to be displayed for the sale.
// +--

$sale_amount    = 10;
$sale_items     = 2;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (($productid != '11401' or $productid != '11402' or $productid != '11403' or $productid != '11404' or $productid != '11405' or $productid != '11406' or $productid != '11407' or $productid != '11408' or $productid != '11409' or $productid != '11410' or $productid != '11411' or $productid != '11413' or $productid != '11414' or $productid != '11416' or $productid != '11417' or $productid != '11418' or $productid != '11420' or $productid != '11421' or $productid != '11422' or $productid != '11425' or $productid != '11426' or $productid != '11301' or $productid != '11302' or $productid != '11303' or $productid != '11304' or $productid != '11306' or $productid != '11307' or $productid != '11308' or $productid != '11309' or $productid != '11314' or $productid != '11315' or $productid != '11316' or $productid != '11317' or $productid != '11320' or $productid != '11323' or $productid != '11324' or $productid != '11327' or $productid != '11328' or $productid != '11329' or $productid != '11330' or $productid != '11331' or $productid != '11332' or $productid != '11335' or $productid != '11336' or $productid != '11338' or $productid != '11338' or $productid != '11340' or $productid != '11342' or $productid != '11344' or $productid != '11345' or $productid != '11347' or $productid != '11348' or $productid != '11349' or $productid != '11350' or $productid != '11601' or $productid != '11602' or $productid != '11603' or $productid != '11604' or $productid != '11605' or $productid != '11607' or $productid != '11608' or $productid != '11609' or $productid != '11610' or $productid != '11611' or $productid != '11612' or $productid != '11613' or $productid != '11614' or $productid != '11615' or $productid != '11617' or $productid != '11618' or $productid != '11619' or $productid != '11620' or $productid != '11621' or $productid != '11622' or $productid != '11623' or $productid != '11624' or $productid != '11625') && ($count >= $sale_items)) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement.

Offline

 

#15 05-26-2009 14:12:00

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Dave wrote:

If you want to get "fancy" and perhaps make it a little easier, especially if you end up with a lot of exclusions, this method will work also.

Code:

$excludeids = array('id1','id2','id3','id4');
if (in_array($productid,$excludeids)) {
# this area is for excluded IDs
} else {
# this area is for IDs that are NOT being excluded
}

The code above would go where?

Code:

foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (($productid != '11401') && ($count >= $sale_items)) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement.

Offline

 

#16 05-26-2009 14:16:32

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Exclude Catagory from Custom Sale Method

Your going to have make the if statement like

Code:

if (($productid != '11401') || ($productid != '11402') || ($productid != '11403') ...and on until the end... ($productid != '11625')){

but there are other way of doing the same thing.

John

Offline

 

#17 05-26-2009 14:24:50

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

The array of IDs to be excluded goes near the top of the code before anything else.

Code:

$excludeids = array('id1','id2','id3','id4');
foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (!in_array($productid,$excludeids)  && $count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement.

Offline

 

#18 05-26-2009 14:27:14

shopmaster
Member
Registered: 05-26-2009
Posts: 1

Re: Exclude Catagory from Custom Sale Method

I am sure glad someone is doing this also. I take care of 5 websites using this software and I have asked by 4 of them to see if this can be done. I also looked throught the forums and couldnt find any information. Thans DJSKirtsweb in starting this thread and to all that is answering.

Offline

 

#19 05-26-2009 14:55:48

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

For people that want the code here it is and it works: (here we have like 11401 and 11402 this is where you put your id numbers to exclude the products.)

Code:

<?php
$cartids = $this->globals('ecom.checkout_cartids');
$cosess  = $this->globals('ecom.checkout_cosess');

// +--
// | sale_amount   = The amount of the sale.
// | sale_items    = The number of items needed to get the sale.
// | sale_textshow = The text to be displayed for the sale.
// +--

$sale_amount    = 10;
$sale_items     = 2;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

$excludeids = array('11401','11402','11403','11404','11405','11406','11407','11408','11409','11410','11411','11412','11413','11414','11415','11416','11417','11418','11419','11420','11421','11421','11422','11423','11424','11425','11426','11301','11302','11303','11304','11305','11306','11307','11308','11309','11310','11311','11312','11313','11314','11315','11316','11317','11318','11319','11320','11321','11322','11323','11324','11325','11326','11327','11328','11329','11330','11331','11332','11333','11334','11335','11336','11337','11338','11339','11340','11341','11341','11342','11343','11344','11345','11346','11347','11348','11348','11350','11601','11602','11603','11604','11605','11606','11607','11608','11609','11610','11611','11612','11613','11614','11615','11616','11617','11618','11619','11620','11621','11622','11623','11624','11625');
foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (!in_array($productid,$excludeids)  && $count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement
?>

Offline

 

#20 05-26-2009 15:03:58

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Exclude Catagory from Custom Sale Method

Just as an FYI you don't have to keep the array on a single line.  It may be easier to read and maintain by breaking up a little bit as shown below.  As you can see it also makes it easy to take out IDs if you need to.

Code:

$excludeids = array('11401','11402','11403','11404','11405',
                    '11406','11407','11408','11409','11410',
                    '11411','11412','11413','11414','11415',
                    '11416','11417','11418','11419','11420',
                    '11421','11421',        '11423','11424',
                    '11425','11426','11301','11302','11303',
                    '11304','11305','11306','11307','11308',
                    '11309','11310','11311','11312','11313',
                    '11314','11315','11316','11317','11318',
                    '11319','11320','11321','11322','11323',
                    '11324','11325','11326','11327','11328',
                    '11329','11330','11331','11332','11333',
                    '11334','11335','11336','11337','11338',
                    '11339','11340','11341','11341','11342',
                    '11343',        '11345','11346','11347',
                    '11348','11348','11350','11601','11602',
                    '11603','11604','11605','11606','11607',
                    '11608','11609','11610','11611','11612',
                    '11613','11614','11615','11616','11617',
                    '11618','11619','11620','11621','11622',
                    '11623','11624','11625');

Offline

 

#21 05-26-2009 15:07:54

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Here is the code for even more buy x get y off. We did this up to twelve times and works like a charm. If you have problems please feel free to email me at webmaster@djskirts.com and I will be more than happy to help.

Code:

<?php
// +--
// | sale_amount   = The amount of the sale.
// | sale_items    = The number of items needed to get the sale.
// | sale_textshow = The text to be displayed for the sale.
// +--

$sale_amount    = 10;
$sale_items     = 2;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

$excludeids = array('11401','11402','11403','11404','11405','11406','11407','11408','11409','11410','11411','11412','11413','11414','11415','11416','11417','11418','11419','11420','11421','11421','11422','11423','11424','11425','11426','11301','11302','11303','11304','11305','11306','11307','11308','11309','11310','11311','11312','11313','11314','11315','11316','11317','11318','11319','11320','11321','11322','11323','11324','11325','11326','11327','11328','11329','11330','11331','11332','11333','11334','11335','11336','11337','11338','11339','11340','11341','11341','11342','11343','11344','11345','11346','11347','11348','11348','11350','11601','11602','11603','11604','11605','11606','11607','11608','11609','11610','11611','11612','11613','11614','11615','11616','11617','11618','11619','11620','11621','11622','11623','11624','11625');
foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (!in_array($productid,$excludeids)  && $count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement

$sale_amount    = 20;
$sale_items     = 3;
$sale_textshow  = 'Buy ' . $sale_items . ' or More Items and Save Sale';

$count = 0;

$excludeids = array('11401','11402','11403','11404','11405','11406','11407','11408','11409','11410','11411','11412','11413','11414','11415','11416','11417','11418','11419','11420','11421','11421','11422','11423','11424','11425','11426','11301','11302','11303','11304','11305','11306','11307','11308','11309','11310','11311','11312','11313','11314','11315','11316','11317','11318','11319','11320','11321','11322','11323','11324','11325','11326','11327','11328','11329','11330','11331','11332','11333','11334','11335','11336','11337','11338','11339','11340','11341','11341','11342','11343','11344','11345','11346','11347','11348','11348','11350','11601','11602','11603','11604','11605','11606','11607','11608','11609','11610','11611','11612','11613','11614','11615','11616','11617','11618','11619','11620','11621','11622','11623','11624','11625');
foreach ($cartids as $cartid => $item) {

$productid = $item['id'];
$count = $count + $item['quantity'];

    if (!in_array($productid,$excludeids)  && $count >= $sale_items) {

     $this->globals('ecom.total_customsale',$sale_amount);
     $this->globals('ecom.customsale_text',$sale_textshow);

} // End of if statement.

} // End of foreach statement
?>

Offline

 

#22 05-26-2009 15:32:29

djskirtsweb
Member
Registered: 04-18-2009
Posts: 44

Re: Exclude Catagory from Custom Sale Method

Thanks very much they do show as below in the admin section. I just copied and pasted for everyone else that wants the code. I hope you dont mind. I seen where allot of other wanted it and I am willing to share it for all.


Dave wrote:

Just as an FYI you don't have to keep the array on a single line.  It may be easier to read and maintain by breaking up a little bit as shown below.  As you can see it also makes it easy to take out IDs if you need to.

Code:

$excludeids = array('11401','11402','11403','11404','11405',
                    '11406','11407','11408','11409','11410',
                    '11411','11412','11413','11414','11415',
                    '11416','11417','11418','11419','11420',
                    '11421','11421',        '11423','11424',
                    '11425','11426','11301','11302','11303',
                    '11304','11305','11306','11307','11308',
                    '11309','11310','11311','11312','11313',
                    '11314','11315','11316','11317','11318',
                    '11319','11320','11321','11322','11323',
                    '11324','11325','11326','11327','11328',
                    '11329','11330','11331','11332','11333',
                    '11334','11335','11336','11337','11338',
                    '11339','11340','11341','11341','11342',
                    '11343',        '11345','11346','11347',
                    '11348','11348','11350','11601','11602',
                    '11603','11604','11605','11606','11607',
                    '11608','11609','11610','11611','11612',
                    '11613','11614','11615','11616','11617',
                    '11618','11619','11620','11621','11622',
                    '11623','11624','11625');

Offline

 

#23 05-28-2009 20:51:11

rtringo
Member
Registered: 06-22-2005
Posts: 95

Re: Exclude Catagory from Custom Sale Method

This is a great topic. I have a few items that I need to exclude from a Custom Sale that uses a little different code.

I have Distributors who log in and receive a variable discount based on dollar amount spent.

The original code is:

<?php

$cartids = $this->globals('ecom.checkout_cartids');

$user          = $this->globals('khxc_user.id');
$group         = $this->globals('khxc_user.usergroup');
$subtotal      = 0;
$sale_amount   = 0;
$sale_textshow = '';

if ((!(empty($user))) && ($group == 'wholesale')) {

foreach ($cartids as $cartid => $item) {
$subtotal = $subtotal + $item['subtotal'];  }
// End of foreach statement.

     if (($subtotal >= 60) && ($subtotal < 100)) {

          $sale_amount    = $subtotal * .20;
          $sale_textshow  = 'Wholesale Distributor Discount - 20% OFF';

     } elseif (($subtotal >= 100) && ($subtotal < 300)) {

          $sale_amount    = $subtotal * .30;
          $sale_textshow  = 'Wholesale Distributor Discount - 30% OFF';

     } elseif (($subtotal >= 300) && ($subtotal < 500)) {

          $sale_amount    = $subtotal * .40;
          $sale_textshow  = 'Wholesale Distributor Discount - 40% OFF';

     } elseif ($subtotal >= 500) {

          $sale_amount    = $subtotal * .45;
          $sale_textshow  = 'Wholesale Distributor Discount - 45% OFF';

     } // End of if statement.

} // End of if statement.

$this->globals('ecom.total_customsale',$sale_amount);
$this->globals('ecom.customsale_text',$sale_textshow);
?>

I inserted:      $excludeids = array('lfn1','lfn2');

to exlcude items lfn1 and lfn2

above the line of code:   foreach ($cartids as $cartid => $item) {

The two items are not excluded from discounts.
Am I putting:   $excludeids = array('lfn1','lfn2');   in the wrong place

Or will it even work with the given code. If not any ideas what I need to use to exclude those 2 items?

Roger

Offline

 

#24 05-28-2009 21:18:31

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Exclude Catagory from Custom Sale Method

The line

Code:

 $excludeids = array('lfn1','lfn2');

needs to be before (above) the foreach statement as it doesn't need to be inside the foreach loop and declaried more than once. This line needs to be inside the foreach loop to pull the current product id

Code:

$productid = $item['id'];

The actual line that is excluding the porducts (id's) is this part of the if statement

Code:

(!in_array($productid,$excludeids)

which is comparing the current prouductid to keys in the array excludeids and if found it returns a true flag or a false if not found. The actual if statement in this case is saying "if not(!) productid as an  array key in excludeids return(false) then procced" so if the id is found(true) in the excludeids array it doesn't meet the condition set and will move to the next statement.

John

Last edited by dh783 (05-28-2009 21:21:25)

Offline

 

#25 05-29-2009 09:46:02

rtringo
Member
Registered: 06-22-2005
Posts: 95

Re: Exclude Catagory from Custom Sale Method

Thanks for reply and code.
Where do I put the below code inside the foreach loop?
Another person created the Custome Sale, and I am trying to refine it. Not really familiar with PHP coding

Code:
$productid = $item['id'

Code:
(!in_array($productid,$excludeids)

Is this the foreach code the above items need to go in?

foreach ($cartids as $cartid => $item) {
$subtotal = $subtotal + $item['subtotal'];  }
// End of foreach statement.

Thanks

Offline

 

Board footer