User Tools

Site Tools


zencartmods

This is an old revision of the document!


Improving Coupon Reports

Want to know how much was 'saved' by your customers by using a discount coupon? Here is a mod for v1.38 that will add it in the Admin coupon report. Enjoy :)

in admin/coupon_admin.php change lines 455+ to the following, adding the two statements marked "START MOD" and "END MOD"

<?php
    $heading = array();
    $contents = array();
      $coupon_desc = $db->Execute("select coupon_name
                                   from " . TABLE_COUPONS_DESCRIPTION . "
                                   where coupon_id = '" . $_GET['cid'] . "'
                                   and language_id = '" . $_SESSION['languages_id'] . "'");
      $count_customers = $db->Execute("select * from " . TABLE_COUPON_REDEEM_TRACK . "
                                       where coupon_id = '" . $_GET['cid'] . "'
                                       and customer_id = '" . $cInfo->customer_id . "'");
// START MOD
      $coupon_saved = $db->Execute("SELECT sum(value) as saved FROM " . TABLE_COUPON_REDEEM_TRACK . ", " . TABLE_ORDERS_TOTAL . " WHERE coupon_id = " . $_GET['cid'] . " AND orders_id = order_id AND class = 'ot_coupon'");
// END MOD
      $heading[] = array('text' => '<b>[' . $_GET['cid'] . ']' . COUPON_NAME . ' ' . $coupon_desc->fields['coupon_name'] . '</b>');
      $contents[] = array('text' => '<b>' . TEXT_REDEMPTIONS . '</b>');
//      $contents[] = array('text' => TEXT_REDEMPTIONS_TOTAL . '=' . $cc_list->RecordCount());
      $contents[] = array('text' => TEXT_REDEMPTIONS_TOTAL . '=' . $cc_query_numrows);
      $contents[] = array('text' => TEXT_REDEMPTIONS_CUSTOMER . '=' . $count_customers->RecordCount());
// START MOD
      $contents[] = array('text' => TEXT_REDEMPTIONS_SAVED . '=' . $coupon_saved->fields['saved']);
// END MOD
      $contents[] = array('text' => '');
?>

Allowing + in email

Line 548 of includes/functions/functions_email.php

$valid_email_pattern = '^[a-z0-9]+[a-z0-9_\.\'\-\+]*@[a-z0-9]+[a-z0-9\.\-]*\.(([a-z]{2,6})|([0-9]{1,3}))$';

Adding a barcode to invoices

Barcodes on invoices can be very handy if you have an automated shipping system. This mod will show you how to do that with only one line of added code to invoice.php. You'll need a barcode generator, this public domain code snipped by Charles J. Scheffold is ten years old and works great :)

Download barcode.php.zip and uncompress it, upload the barcode.php file to your zencart/admin directory

Then we can call this code to make a barcode image wherever we want! Open up admin/invoice.php and stick this line where ever you want the barcode

We suggest:

find line 48 of invoice.php

<!-- body_text //-->

and replace it with:

<!-- body_text //-->
<?php echo '<img src="barcode.php?barcode=' . $oID . '&width=250&height=50" />'; ?>;

Hiding inventory numbers

You can simplify your inventory display so that over a certain qty, the cart just says "In Stock"

In this example, we use 100 as the limit under which we display the quantity but of course you can change that pretty easily in the define to whatever you wish

New Files

Create a defines page, call it anything (we called it products_quantities_mods.php) and put it in /includes/extra_datafiles/

<?php
define(STOCK_SHOW_LIMIT, 100);
define(STOCK_OFFSET, 3);
define(STOCK_TEXT_IN_STOCK, 'IN STOCK');
define(STOCK_TEXT_QUANTITY_IN_STOCK, 'IN STOCK');
define(STOCK_TEXT_OUT_OF_STOCK, 'OUT OF STOCK');
?>

This should be the entire file.

NB: Make sure there isnt any white space before the '<?php' or after the '?>'. Any whitespace output there will cause php to send headers, which you don't want to do yet.

Change Settings

Make sure that the normal method for displaying products quantity is disabled.

Go to Admin>Catalog>Product Types>Products( General )>Edit Layout

and set Show Quantity in Stock to false. (Do this for Products (General), and any other types of products you use in the store)

This will remove the quantity display from everywhere on the site. This tutorial will cover adding it back into the individual products page and the products listing page. If you'd like to keep this feature enabled, please see the optional instructions at the bottom.

Show Quantity up to 100

Files to modify:

/includes/templates/YOUR_TEMPLATE/tpl_product_info_display.php
/includes/modules/product_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

Paste this new code into tpl_product_info_display.php anywhere you'd like – we recommend right below the price (line 75)

<div class="availability">
<?php
if($products_quantity > STOCK_SHOW_LIMIT)	
  echo STOCK_TEXT_IN_STOCK;
elseif($products_quantity > 0)	
  echo $products_quantity . ' ' . STOCK_TEXT_QUANTITY_IN_STOCK;
else	
  echo STOCK_TEXT_OUT_OF_STOCK;
?>      
</div>

in includes/modules/product_listing.php

find (lines 148-151)

case 'PRODUCT_LIST_QUANTITY':
        $lc_align = 'right';
        $lc_text = $listing->fields['products_quantity'];

and replace them with

case 'PRODUCT_LIST_QUANTITY':
        $lc_align = 'right';
	if($listing->fields['products_quantity'] > STOCK_SHOW_LIMIT)
          $lc_text = STOCK_TEXT_IN_STOCK;
	elseif($listing->fields['products_quantity'] > 0)
          $lc_text = $listing->fields['products_quantity'] . ' ' . STOCK_TEXT_QUANTITY_IN_STOCK;
        else
          $lc_text = STOCK_TEXT_OUT_OF_STOCK;

in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

find (line 59)

$display_products_quantity = TEXT_PRODUCTS_QUANTITY . $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

and replace with

          if ($products_all->fields['products_quantity'] > STOCK_SHOW_LIMIT)
            $display_products_quantity = STOCK_TEXT_IN_STOCK;
          elseif($products_all->fields['products_quantity'] > 0)
            $display_products_quantity = $products_all->fields['products_quantity'] . ' ' . STOCK_TEXT_IN_STOCK;
          else
            $display_products_quantity = STOCK_TEXT_OUT_OF_STOCK;
          $display_products_quantity .=	str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

Optional Stuff

If you would rather not set the "Show Products Quantity" option to false then you'll need to make the following mods as well to each of the following files:

Modified Files:
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_featured_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_new_listing.php

For the Stock Limit:

in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

find (line59)

$display_products_quantity = TEXT_PRODUCTS_QUANTITY . $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

and replace with

          if ($products_all->fields['products_quantity'] > STOCK_SHOW_LIMIT)
            $display_products_quantity = STOCK_TEXT_IN_STOCK;
          elseif($products_all->fields['products_quantity'] > 0)
            $display_products_quantity = $products_all->fields['products_quantity'] . ' ' . STOCK_TEXT_IN_STOCK;
          else
            $display_products_quantity = STOCK_TEXT_OUT_OF_STOCK;
          $display_products_quantity .=	str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

The changes for tpl_modules_products_featured_listing.php and tpl_modules_products_new_listing.php are identical except that the variable $products_all should be replaced with $featured_products and $products_new respectively.

Stashing inventory

New Files

We'll be using the same file as the "Show IN STOCK over 100 quantity" mod above

Change Settings

Change the same settings as the "Show IN STOCK over 100 quantity" mod above

Code changes

/includes/functions/functions_lookups.php
/includes/functions/functions_general.php
/includes/modules/product_listing.php
/includes/modules/pages/product_info/main_template_vars.php

???

in /includes/functions/functions_lookups.php

find (line 172)

    return $stock_values->fields['products_quantity'];

and replace it with

    return $stock_values->fields['products_quantity'] - STOCK_OFFSET;

in /includes/functions/functions_general.php

find (line 130)

$button_check = $db->Execute("select product_is_call, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");

and add a line below it so that it is looks like:

$button_check = $db->Execute("select product_is_call, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
$button_check->fields['products_quantity'] = zen_get_products_stock($product_id);

in /includes/modules/product_info.php

find (line 77)

  while (!$listing->EOF) {
    $rows++;

and replace with

  while (!$listing->EOF) {
    $rows++;
    $listing->fields['products_quantity'] = zen_get_products_stock($listing->fields['products_id']);

in /includes/modules/pages/product_info/main_template_vars.php

find (line 115)

$products_quantity = $product_info->fields['products_quantity'];

and replace it with

  // Stock Offset Mod
  $products_quantity = zen_get_products_stock($product_id);
/home/ladyada/public_html/wiki/data/attic/zencartmods.1302716492.txt.gz · Last modified: 2016/01/28 18:05 (external edit)