Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help! Expert Coder Advise Needed.


RazorSharp

Recommended Posts

Hi:

 

I am trying to tie in the following code so when a New Product has a 0 quantity the button will display the Sold-Out button, not the Buy Now button. Thus, not adding that product to the shopping cart. I need some help tying these two pieces of code together so I don't get a blank screen. I am new to php code and need some help. The following code below is my problem.

 

 

ORIGINAL CODE:

 

FILE: Catalog/includes/modules/new_products.php

 

Note: This is only a chuck of the whole orginal code, only the part I need to work on.

 

Bold code is the code I am trying to modify.

 

 

<!-- new_products //-->

<?php

$space = " ";

$lb = "(";

$rb = ")";

$p = "!";

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$info_box_contents = array();

$row = 0;

$col = 0;

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

 

?>

 

 

 

MODIFIED CODE: Includes (Buy it Now for New Products MOD). - Works fine.

 

FILE: Catalog/includes/modules/new_products.php

 

Note: This is only a chuck of the whole orginal code, only the part I need to work on.

 

Code in bold is Buy it Now for New Products MOD code.

 

<!-- new_products //-->

<?php

$space = " ";

$lb = "(";

$rb = ")";

$p = "!";

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$info_box_contents = array();

$row = 0;

$col = 0;

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '<br><a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $new_products['products_name'] . TEXT_NOW) . '</a><br><br>');

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

 

?>

 

 

 

CODE I AM TRYING TO BLEND TOGETHER: - This includes the orginal code and the Buy it Now for New Products MOD code within a switch statement. However, I don't know exactly how to tie them together correctly so the page displays correctly.

 

FILE: Catalog/includes/modules/new_products.php

 

Code in Bold & italic is the orginal code:

 

Code in Bold only is the (Buy it Now for New Products MOD) code plus the switch statement.

 

Note: This is only a chuck of the whole orginal code, only the part I need to work on.

 

 

<!-- new_products //-->

<?php

$space = " ";

$lb = "(";

$rb = ")";

$p = "!";

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$info_box_contents = array();

$row = 0;

$col = 0;

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

switch (tep_get_products_stock($products_id)) {

case 0:

echo '<br>';

echo tep_image_button('button_buy_now_sold.gif', 'Cannot add to Cart - Sold or Out of stock');

echo '<br><em><font color="#999999">Cannot add to Cart</font></em>';

break;

default:

echo '<br><a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id'], 'NONSSL') . '">';

echo tep_image_button('button_buy_now.gif', TEXT_BUY . $new_products['products_name'] . TEXT_NOW) . '</a><br><br>')');

}

 

 

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

 

?>

 

 

Any help would be appreciated, Thanks in advance.

 

 

RazorSharp :?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...