Guest Posted September 18, 2009 Posted September 18, 2009 Hello, I have the newsletter products contribution installed. I want to add a "buy now" button below each product image and product name that links to the product page on my website. Obviously I could use something like this... <a target="_blank" href="http://www.punkrockcds.com/rise-against-appeal-reason-p-2664.html"><img title=" Buy Now " height="24" alt="Buy Now" width="114" border="0" src="http://www.punkrockcds.com/includes/languages/english/images/buttons/button_buy_now.gif" /></a> But I think there must be a way to do this without having to change the links for every product on every newsletter I send out? Here is my newsletter_products.php... <?php /* $Id: newsletter_products.php,v 2.0 2007/05/17 scottyb Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2002 osCommerce Released under the GNU General Public License //newsletter products */ class newsletter_products { function newsletter_products($title, $content, $products, $template) { $this->title = $title; $this->content = $content; $this->products = $products; $this->template = $template; } function choose_products() { global $HTTP_GET_VARS, $languages_id; //first let's get the products that have been added to newsletter if ($HTTP_GET_VARS['nID']) { $newsletter_products_query = tep_db_query("select products_id from " . TABLE_NEWSLETTERS_TO_PRODUCTS . " where newsletters_id ='" . (int)$HTTP_GET_VARS['nID'] . "'"); $newsletter_products_string = ''; while($newsletter_products = tep_db_fetch_array($newsletter_products_query)){ $newsletter_products_string .= $newsletter_products['products_id'] . ', '; } $newsletter_products_string = trim($newsletter_products_string, ', '); //$newsletter_products_string = tep_db_result($newsletter_products_query, 0, $newsletter_products_query['products']); $current_products_query = "select pd.products_id, pd.products_name, p.products_model from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.language_id = '" . (int)$languages_id . "' and pd.products_id = p.products_id and p.products_status = '1'"; if($newsletter_products_string) $current_products_query .= " and pd.products_id in (" . $newsletter_products_string . ")"; $current_products_query .= " order by pd.products_name"; $current_products_query = tep_db_query($current_products_query); } if($newsletter_products_string){ $current_products_array = array(); while ($current_products = tep_db_fetch_array($current_products_query)){ $current_products_array[] = array('id' => $current_products['products_id'], 'text' => $current_products['products_name'] . ' - ' . $current_products['products_model']); } } $products_query = "select pd.products_id, pd.products_name, p.products_model from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.language_id = '" . (int)$languages_id . "' and pd.products_id = p.products_id and p.products_status = '1'"; if ($newsletter_products_string) $products_query .= " and pd.products_id not in(" . $newsletter_products_string . ")"; $products_query .= " order by pd.products_name"; $products_array = array(); $products_query = tep_db_query($products_query); while ($products = tep_db_fetch_array($products_query)) { $products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name'] . ' - ' . $products['products_model']); } $choose_products_string = '<script language="javascript"><!-- function mover(move) { if (move == \'remove\') { for (x=0; x<(document.newsletter.products.length); x++) { if (document.newsletter.products.options[x].selected) { with(document.newsletter.elements[\'chosen[]\']) { options[options.length] = new Option(document.newsletter.products.options[x].text,document.newsletter.products.options[x].value); } document.newsletter.products.options[x] = null; x = -1; } } } if (move == \'add\') { for (x=0; x<(document.newsletter.elements[\'chosen[]\'].length); x++) { if (document.newsletter.elements[\'chosen[]\'].options[x].selected) { with(document.newsletter.products) { options[options.length] = new Option(document.newsletter.elements[\'chosen[]\'].options[x].text,document.newsletter.elements[\'chosen[]\'].options[x].value); } document.newsletter.elements[\'chosen[]\'].options[x] = null; x = -1; } } } return true; } function selectAll(FormName, SelectBox) { temp = "document." + FormName + ".elements[\'" + SelectBox + "\']"; Source = eval(temp); for (x=0; x<(Source.length); x++) { Source.options[x].selected = "true"; } } //--></script>'; $choose_products_string .= '<table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n" . ' <tr>' . "\n" . ' <td align="center" class="main"><b>' . TEXT_PRODUCTS . '</b><br>' . tep_draw_pull_down_menu('products', $products_array, '', 'size="20" style="width: 32em;" multiple') . '</td>' . "\n" . ' <td align="center" class="main"> <br><br><input type="button" value="' . BUTTON_SELECT . '" style="width: 8em;" onClick="mover(\'remove\');"><br><br><input type="button" value="' . BUTTON_UNSELECT . '" style="width: 8em;" onClick="mover(\'add\');"></td>' . "\n" . ' <td align="center" class="main"><b>' . TEXT_SELECTED_PRODUCTS . '</b><br>' . tep_draw_pull_down_menu('chosen[]', $current_products_array, '', 'size="20" style="width: 25em;" multiple') . '</td>' . "\n" . ' </tr>' . "\n" . '</table>'; return $choose_products_string; } function productInfo(){ global $languages_id; $this->productInfo = array(); $p_string = ''; for($i=0, $n=sizeof($this->products); $i<$n; $i++){ $p_string .= $this->products[$i] . ', '; } $p_string = trim($p_string, ', '); $product_query = tep_db_query("select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, NULL) as specials_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.products_id = p.products_id and p.products_id in(" . $p_string . ") and pd.language_id=" . (int)$languages_id); //$this->productsInfo = array(); while($product = tep_db_fetch_array($product_query)){ $this->productsInfo[] = array('products_id' => $product['products_id'], 'products_name' => $product['products_name'], 'products_image' => $product['products_image'], 'products_price' => $product['products_price'], 'specials_price' => $product['specials_price'], 'products_tax_class_id' => $product['products_tax_class_id']); } } function html_content() { global $currencies, $languages_id; //create HTML string containing links & pics //define product columns here define('COLS', 3); $width = intval(100/COLS); $html_content = '<table border="0" width="628px" cellpadding="" cellspacing="50"><tr>'; $col = 0; $this->productInfo(); //change html body styles here $cssPrice = 'color: #ff0000; font-family: Arial; font-size: 16px; font-weight: bold'; $cssSale = 'color: #ff0000;'; $cssMarkdown = 'color: #000000; text-decoration: line-through'; $cssLink = 'color:#3a3a3a; font-family: Arial, Helvetica, sans-serif; font-size:14px; font-weight: bold'; for ($i=0, $n=sizeof($this->productsInfo); $i<$n; $i++) { if ($col > COLS-1) { $html_content .= '</tr><tr><td align="left" width="' . $width . '%"><a href="' . tep_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $this->productsInfo[$i]['products_id']) . '" style="' . $cssLink . '">' . tep_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $this->productsInfo[$i]['products_image'], $this->productsInfo[$i]['products_name'], $imgWidth = 140, $imgHeight = 131) . '<br>' . $this->productsInfo[$i]['products_name'] . '</a><br>'; $price = ($this->productsInfo[$i]['specials_price']) ? '<span style="'. $cssMarkdown . '">' . $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span> <span style="' . $cssSale . '">' . $currencies->display_price($this->productsInfo[$i]['specials_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span>' : '<span style="' . $cssPrice . '">' . $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span>'; $html_content .= $price . '</td>'; $col = 0; } else { $html_content .= '<td align="left" width="' . $width . '%"><a href="' . tep_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $this->productsInfo[$i]['products_id']) . '" style="' . $cssLink . '">' . tep_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $this->productsInfo[$i]['products_image'], $this->productsInfo[$i]['products_name'], $imgWidth = 140, $imgHeight = 131) . '<br>' . $this->productsInfo[$i]['products_name'] . '</a><br>'; $price = ($this->productsInfo[$i]['specials_price']) ? '<span style="' . $cssMarkdown . '">' . $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span> <span style="' . $cssSale . '">' . $currencies->display_price($this->productsInfo[$i]['specials_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span>' : '<span style="' . $cssPrice . '">' . $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . '</span>'; $html_content .= $price . '</td>'; } $col++; } //uncomment & create your unsubscribe link in your includes/languages/YOUR LANGUAGE/modules/newsletters/newsletter_products.php //$html_content .= '</tr><tr><td colspan="' . COLS . '">' . TEXT_UNSUBSCRIBE . '</td></tr></table>'; if(tep_not_null($this->template)){ //HTML page from template //$content = join('', file(DIR_WS_TEMPLATES . $this->template)); $content = file_get_contents(DIR_WS_TEMPLATES . $this->template); //remove all line breaks and spaces in template to ensure no spaces resulting from email class $content = str_replace("\n", '', $content); $content = str_replace("\r", '', $content); //$content = str_replace('> ', '>', $content); $content = addslashes($content); $email_title = $this->title; $email_message = nl2br($this->content); $text_content = $this->content; eval ("\$content = \"$content\";"); $html_content = $content; } return $html_content; } function text_content(){ global $currencies, $languages_id; $text_content = $this->content . "\r\n\r\n"; //var_dump($this->productsInfo); for($i=0, $n=sizeof($this->productsInfo); $i<$n; $i++){ $text_content .= $this->productsInfo[$i]['products_name'] . ' '; $price = ($this->productsInfo[$i]['specials_price']) ? 'Sale Price: ' . $currencies->display_price($this->productsInfo[$i]['specials_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) . ' Down from: ' . $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])) : $currencies->display_price($this->productsInfo[$i]['products_price'], tep_get_tax_rate($this->productsInfo[$i]['products_tax_class_id'])); $text_content .= $price . "\n"; $text_content .= tep_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $this->productsInfo[$i]['products_id']) . "\r\r"; } //uncomment & create your unsubscribe link in your includes/languages/YOUR LANGUAGE/modules/newsletters/newsletter_products.php $text_content .= "\r\r" . TEXT_UNSUBSCRIBE; return $text_content; } function confirm() { global $HTTP_GET_VARS; $mail_query = tep_db_query("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'"); $mail = tep_db_fetch_array($mail_query); $confirm_string = '<table border="0" cellspacing="0" cellpadding="2">' . "\n" . ' <tr>' . "\n" . ' <td class="main"><font color="#ff0000"><b>' . sprintf(TEXT_COUNT_CUSTOMERS, $mail['count']) . '</b></font></td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td class="main"><b>' . $this->title . '</b></td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td class="main">' . $this->text_content() . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td class="main">' . $this->html_content() . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr>' . "\n" . ' <td align="right"><a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm_send') . '">' . tep_image_button('button_send.gif', IMAGE_SEND) . '</a> <a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a></td>' . "\n" . ' </tr>' . "\n" . '</table>'; return $confirm_string; } function send($newsletter_id) { $mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'"); //create id for current mailing $messageId = "Message-Id: <" . time() . "@" . $_SERVER['SERVER_NAME'] . ">"; $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer', $messageId)); //$mimemessage->add_text($this->content); //$text = $this->text_content(); $mimemessage->add_html($this->html_content(), $this->text_content(), HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES); $mimemessage->build_message(); while ($mail = tep_db_fetch_array($mail_query)) { $mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title); } $newsletter_id = tep_db_prepare_input($newsletter_id); tep_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1' where newsletters_id = '" . tep_db_input($newsletter_id) . "'"); } } ?> Hope someone can help! Cheers, Mark.
Guest Posted September 20, 2009 Posted September 20, 2009 Hello! Can anyone help with this? I think the code should be something like... $html_content .= '<td align="left" width="' . $width . '%"><a href="' . tep_catalog_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $this->productsInfo[$i]['products_id']) . '">' . tep_image('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</span>'; But this doesn't seem to work quite right. Any ideas? Any help or advice much appreciated. Cheers, Mark.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.