Forums / Contribution-Writing Guidelines / Searching a cart for Gift Certificates (GIFT-XXXX)

Searching a cart for Gift Certificates (GIFT-XXXX)

Locked

Views: 4,257

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
6 Aug 2010, 11:49 PM
#1
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Searching a cart for Gift Certificates (GIFT-XXXX)

While working on a module, I was wondering... is it possible to search the order/shopping cart's contents for a specific term. Say for example, searching for models that start with GIFT-XXXX?

7 Aug 2010, 3:38 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Are you trying to search an Order that has been completed or ... are you trying to search the Shopping Cart as it is being created? :unsure:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

10 Aug 2010, 7:33 AM
#3
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Ajeh:

Are you trying to search an Order that has been completed or ... are you trying to search the Shopping Cart as it is being created? :unsure:

Trying to search the shopping cart as it is being created.

10 Aug 2010, 3:33 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

See if either of these two help you ...

global $cart;
echo 'Cart get_product_id_list: ' . $_SESSION['cart']->get_product_id_list();
echo 'Cart get_products: ' . print_r($_SESSION['cart']->get_products());

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

11 Aug 2010, 4:42 PM
#5
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Ajeh:

See if either of these two help you ...

global $cart;
echo 'Cart get_product_id_list: ' . $_SESSION['cart']->get_product_id_list();

echo 'Cart get_products: ' . print_r($_SESSION['cart']->get_products());
```

It did actually. Had to do a preg_match function on it. But it did the trick.
11 Aug 2010, 4:57 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Thanks for the update on what worked for you ...

If you have some details on how you tested for the GIFT certificates specifically in your code, it might help others ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Aug 2010, 1:40 AM
#7
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Certainly.

This was an add on for the reward points mod. However, you can use it in any order_total module. Since I don't want to discount gift certificates sold, I figured it was best if they were removed from the sub-total before calculation of the discount. The built in programming of the reward points mod prevents negative discounts (basic algebra on this one, a negative of a negative turns into a positive or in this case, creates a charge).

If you are going to use this for that same mod, edit ot_reward_points_discount.php found in the includes/modules/order_total directory.

Find (near line 61):

$order_total=$this->get_order_total();
```Add after:
```php
for($i=0; $i<sizeof($order->products); $i++) {
    if (preg_match("/GIFT/", $order->products[$i]['model'])) {
    $order_total -= ($order->products[$i]['qty'] * $order->products[$i]['price']);
    }
}

Essentially you would need to cycle through $order->products and test each one for a match on the preg_match. If it's true, add code in to do something with it or vice versa. In my case in the line of code above, I'm instructing ot_reward_points_discount.php to remove the total of the gift certificate from the total.

12 Aug 2010, 1:58 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Searching a cart for Gift Certificates (GIFT-XXXX)

Thanks for the instructions and demo of the code that you used ... this is a great help to others ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!