Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Get 1 Free


kymation

Recommended Posts

not a bug really, but noticed all products show up in the free product dropdown list regardless of status in the shop. So I added:   and p.products_status = '1'

  // Remember selected free product in the dropdown		
		 $free_products = array();
		  $free_array = array();
		  $free_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_status = '1' order by products_name");
		  while ($free = tep_db_fetch_array($free_query)) {
			$free_products[] = array('id' => $free['products_id'],
									 'text' => $free['products_name'] . ' (' . $currencies->format($free['products_price']) . ')');
			$free_array[$free['products_id']] = $free['products_name'];
		  }
   // End remember	

-Dave

Link to comment
Share on other sites

@@Roaddoctor

 

just tested your query works like a charm! But my suggestion to add the same status in the query on line 161/162 doesn't work.

So i looked for this function inside the admin/includes/functions/general.php

function tep_draw_products_pull_down($name, $parameters = '', $exclude = '') {

and there is a $products_query. Inside that query i added and p.products_status = '1' and it works.

Now the "promoted" products dropdown and the "free" products dropdown won't list up products that have a products_status = 0.

 

Cool! I guess i'll need to add this to the install manual. And I hope that this is the last change/fix for this addon.

I will rewrite the manual and update all necessary files and upload it with a new version number to the addons area.

Thanks again for all the help. Appreciated! :thumbsup:

Edited by Tsimi
Link to comment
Share on other sites

yep I think your gold.

 

 

Only other tweaks I've made was changing the product_info.php line from a <p> to <div>, moved the <div> to above the <PiGal> section, and applied this css

.get1free {
  font-family: Verdana, Arial, sans-serif;
  font-size: 11px;
  background: #F9F9F9;
  font-weight: bold;
  overflow: hidden;
  margin: 1em;
  padding: 1em 1em 1em 2em;
  border-left: 4px solid #090;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.125);
}

I'm quite happy. Here is a example of the result. Thanks for the efforts! @@Tsimi

-Dave

Link to comment
Share on other sites

@@Roaddoctor

 

Oh that looks nice Dave. And you customized it to show the expire date.

Where the message should appear is a design layout thing. But it looks way better than the simple red background.

If you don't mind i would like to use your css for the install manual. If that's OK with you. And i will add the expire date thing inside the message like you have if expire date is set.

Link to comment
Share on other sites

How about this inside the product_info.php

<?php
// start Get 1 Free
    // If this product qualifies for free product(s) display promotional text
    $get_1_free_query = tep_db_query("select pd.products_name,
                                             g1f.products_free_quantity,
                                             g1f.products_qualify_quantity,
					     g1f.get_1_free_expires_date
                                      from " . TABLE_GET_1_FREE . " g1f,
                                           " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      where g1f.products_id = '" . (int)$product_info['products_id'] . "'
                                        and pd.products_id = g1f. products_free_id
                                        and pd.language_id = '" . (int)$languages_id . "'
                                        and status = '1'"
                                    );
    if (tep_db_num_rows($get_1_free_query) > 0) {
      $free_product = tep_db_fetch_array($get_1_free_query);
		echo '<div class=get1free><strong>' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'], $free_product['products_name']) . '</strong>';
	if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
		echo '<i>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . '</i>'; 
    }
		echo '</div>';
	}
// end Get 1 Free
?>

and add new language define inside the /languages/english/product_info.php

define('TEXT_OFFER_ENDS', ' - Limited time offer ends');
Edited by Tsimi
Link to comment
Share on other sites

@@Tsimi

 

Since the css already has the font weight at bold, I changed slightly your code... just cosmetic stuff here.

<?php
// start Get 1 Free
    // If this product qualifies for free product(s) display promotional text
    $get_1_free_query = tep_db_query("select pd.products_name,
                                             g1f.products_free_quantity,
                                             g1f.products_qualify_quantity,
					     g1f.get_1_free_expires_date
                                      from " . TABLE_GET_1_FREE . " g1f,
                                           " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      where g1f.products_id = '" . (int)$product_info['products_id'] . "'
                                        and pd.products_id = g1f. products_free_id
                                        and pd.language_id = '" . (int)$languages_id . "'
                                        and status = '1'"
                                    );
    if (tep_db_num_rows($get_1_free_query) > 0) {
      $free_product = tep_db_fetch_array($get_1_free_query);
		echo '<div class=get1free>' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'], $free_product['products_name']);
	if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
		echo '<span style="font-weight:normal"><em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . ' 11:59pm. </em></span>'; 
    }
		echo '</div>';
	}
// end Get 1 Free
?>

Very nice work... What do you think about hyperlinking the free item? good or bad idea? overlay layer?

-Dave

Link to comment
Share on other sites

Thanks for fixing Dave!

 

You mean something like in the package from 6 Jul 2008?

Well that depends. My Free products is hidden and not showing inside the shop. This hiding function comes from my Master products addon. It doesn't deactivate the product but just hide it so linking to it makes no sense in my case but i think others would probably like the idea so yes sure why not.

We could either add it to the code or we could add it as mod option inside the Get 1 Free Mods.txt file.

Edited by Tsimi
Link to comment
Share on other sites

@@Roaddoctor

 

Here is the code including hyperlink to the free product. The other question would be, open a new window (target="_blank") or redirect inside the same window?

This code opens a new window to the free product.

<?php
// start Get 1 Free
    // If this product qualifies for free product(s) display promotional text
    $get_1_free_query = tep_db_query("select pd.products_name,
                                             g1f.products_free_id,
                                             g1f.products_free_quantity,
                                             g1f.products_qualify_quantity,
                         g1f.get_1_free_expires_date
                                      from " . TABLE_GET_1_FREE . " g1f,
                                           " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      where g1f.products_id = '" . (int)$product_info['products_id'] . "'
                                        and pd.products_id = g1f. products_free_id
                                        and pd.language_id = '" . (int)$languages_id . "'
                                        and status = '1'"
                                    );
    if (tep_db_num_rows($get_1_free_query) > 0) {
      $free_product = tep_db_fetch_array($get_1_free_query);
        echo '<div class=get1free>' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'], '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $free_product['products_free_id']) . '" target="_blank">' . $free_product['products_name'] . '</a>');
    if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
        echo '<span style="font-weight:normal"><em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . ' 11:59pm. </em></span>';
    }
        echo '</div>';
    }
// end Get 1 Free
?>

I will probably add it like this and write something inside the Mods text file to remove target blank if they want to redirect inside the same window.

 

Link to comment
Share on other sites

Get 1 Free v1.6 (normal osC 2.3.4)

Get 1 Free v1.6BS (osC 2.3.4BS GOLD)

 

uploaded to the addons area

 

http://addons.oscommerce.com/info/4990

 

I think all known bugs are fixed now. Anything else from here on is just improvement to the code to make it better.

 

Again thanks to @@Roaddoctor for help testing and improving.

All credits to Jim for making this addon.

Link to comment
Share on other sites

  • 4 weeks later...

@@Tsimi

 

Bug I think -

I had 8 specials running in Feb, all set to expire on 2/28/15

It's now 3/2/15, and it appears only the first item has switched status to off. The remaining 7 are still status active.

 

also noticed this code has stopped working    this quit working until I went back and updated all 8 entries with new expire date

    if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
        echo '<span style="font-weight:normal"><em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . ' 11:59pm. </em></span>';
Edited by Roaddoctor

-Dave

Link to comment
Share on other sites

OK did more testing...

 

When i set up a product to expire date March 3rd (here in Japan is today) then the message shows for the first time and when adding that product to the cart the message disappears and also no free product is added to the cart.

So it kinda works but the Special offer message stays until the moment I add the product to the cart.

Edited by Tsimi
Link to comment
Share on other sites

@@Roaddoctor

 

I think I found the problem.

 

EDIT: (2nd try, lol)

 

I have this code inside the product_info.php (yours might look a bit different)

<?php
// start Get 1 Free
    // If this product qualifies for free product(s) display promotional text
    $get_1_free_query = tep_db_query("select pd.products_name,
											 g1f.products_free_id,
                                             g1f.products_free_quantity,
                                             g1f.products_qualify_quantity,
											 g1f.get_1_free_expires_date
                                      from " . TABLE_GET_1_FREE . " g1f,
                                           " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      where g1f.products_id = '" . (int)$product_info['products_id'] . "'
                                        and pd.products_id = g1f. products_free_id
                                        and pd.language_id = '" . (int)$languages_id . "'
                                        and status = '1'"
                                    );
    if (tep_db_num_rows($get_1_free_query) > 0) {
      $free_product = tep_db_fetch_array($get_1_free_query);
		echo '<div class=get1free><strong>' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'],  '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $free_product['products_free_id']). '" target="_blank">' . $free_product['products_name'] . '</a>') . '</strong>';
	if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
		echo '<em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . '</em>'; 
    }
		echo '</div>';
	}
// end Get 1 Free
?>

as you can see there is a date checking (if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {) but only for the last part of the message and not for the entire message. Make sense?

So changing it to this should solve the issue.

<?php
// start Get 1 Free
    // If this product qualifies for free product(s) display promotional text
    $get_1_free_query = tep_db_query("select pd.products_name,
											 g1f.products_free_id,
                                             g1f.products_free_quantity,
                                             g1f.products_qualify_quantity,
											 g1f.get_1_free_expires_date
                                      from " . TABLE_GET_1_FREE . " g1f,
                                           " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      where g1f.products_id = '" . (int)$product_info['products_id'] . "'
                                        and pd.products_id = g1f. products_free_id
                                        and pd.language_id = '" . (int)$languages_id . "'
                                        and status = '1'"
                                    );
    if (tep_db_num_rows($get_1_free_query) > 0) {
      $free_product = tep_db_fetch_array($get_1_free_query);
if (($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) || ($free_product['status'] = 1)) {  
        echo '<div class=get1free><strong>' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'],  '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $free_product['products_free_id']). '" target="_blank">' . $free_product['products_name'] . '</a>') . '</strong>';
    if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
        echo '<em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . '</em>';
    }
        echo '</div>';
    }
}
// end Get 1 Free
?>
Edited by Tsimi
Link to comment
Share on other sites

That code above didn't work... <_<

Set a product to March 4th yesterday, today message was still on. Adding the product in the cart doesn't add the free item so technically again OK. Somehow the status in the admin won't turn off when the date is reached.

...time for bug hunting... (w00t)

Link to comment
Share on other sites

found a small typo

 

this

 

if (($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) || ($free_product['status'] = 1)) { 

 

should be like this

 

if (($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) || ($free_product['status'] == 1)) { 

 

forgot to add one additional =  :blush:

now it seems to work...when i set todays date even though the products status in the admin is not red the message doesn't show anymore which is good and no freebie item gets added to the cart.

If i set a future date it shows the message and freebie item gets added to the cart.

Just to make 100% sure before adding it as bug fix i setup few products in my test shop with tomorrows date. Let's see if that works this time...

Edited by Tsimi
Link to comment
Share on other sites

The original code for this Addon was designed to check the expiration any time a page was loaded from the site and expire any offers that were past the end date. That code seems to have been lost somewhere in all of the updates. I suggest putting something like that back in.

////
// Auto expire products on get_1_free
  function tep_expire_get_1_free() {
    $get_1_free_query = tep_db_query("select get_1_free_id from " . TABLE_GET_1_FREE . " where status = '1' and now() >= get_1_free_expires_date and get_1_free_expires_date > 0");
    if (tep_db_num_rows($get_1_free_query)) {
      while ($get_1_free = tep_db_fetch_array($get_1_free_query)) {
        tep_set_get_1_free_status($get_1_free['get_1_free_id'], '0');
      }
    }
  }

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

@@Roaddoctor

 

hmmm...i looked at the get_1_free file and also compared it with the specials.php since they seem to be "similar" in the build up.

Anyway, good timing it is 1 am (March 5th) here and that means that the products that i set yesterday (March 4th) are expired now.

I went and looked at the products and....no message! and when I add the products to the cart no freebie gets added so the get 1 free function was never buggy just that message was not disappearing.

The only bug i can see now is in the admin area that when the expire date is past the status light stays green until the product gets added at least once to the cart or gets deactivated manually. And even though the light is green no freebie gets added because the expire date is reached.

The expire date stays in the admin area and setting the status to green with a past expire date does not show the message or doesn't add the freebie so again function works.

 

@@kymation

 

Thanks Jim! Do you remember around when that piece of code was removed from the get 1 free addon? Which version was the last that had that inside?

Edited by Tsimi
Link to comment
Share on other sites

That code is in my copy of version 1.4.2, so it was sometime after that. I haven't checked all of the versions -- I'm a bit too busy right now for forensic archaeology.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

  • 2 weeks later...

@@Tsimi

 

This may only apply if you have Free Shipping per Product installed, not sure.

 

/includes/classes/shopping_cart.php

I changed

// start Get 1 free
          // If this product qualifies for free product(s) add in the number of free products
          if (is_array ($free_product = $this->get1free ($products_id))) {
//            $total_items += $free_product['quantity'];  // charge shipping on free item breaks shipping quote if purchased item is free shipping
            $total_items += "0";  // free shipping on free item if purchased item is also free shipping
          }
// end Get 1 free

might not be the correct way to do it, but the result works so far.

 

should it be?

$total_items += "0" ;

or

$total_items += 0 ;

-Dave

Link to comment
Share on other sites

All of those have the same result: they add zero to the existing total of $total_items. Which is to say they do nothing at all. If that's really what you want, it would be better to just comment out that line.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...