Modular Storefront

Top  Previous  Next

The index.php script is an example of a storefront for AShop. By using the various content modules found in the includes directory you can put together the frontpage of your shopping cart any way you like. This way the storefront is an exception from how the pages usually work in AShop, in that it is its own page template. It is also one of the few scripts included with AShop that isn't ioncube encoded, which means that you can edit it, for example with a web page editor like Dreamweaver or a text editor.

 

The storefront script always needs to begin with the following PHP code:

 

<?php

       // Initialize the storefront page...

       include "admin/config.inc.php";

       if (!$lang) $lang = $defaultlanguage;

       include "language/$lang/storefront.inc.php";

       $databaseuser = "";

?>

 

This makes the script ready to use the content modules and also makes it multilingual, as long as you put all text used in the page in the storefront.inc.php language module. To use the text from the language module you need to replace it with this type of code:

 

<?php echo HOME; ?>

 

Where the "HOME" part should be the name of the language constant you want to use, in this case it will show the word "Home" in the language selected by the visitor. Open the storefront.inc.php language module in a text editor to see which constants are available and to add your own constants if needed.

 

Newsletter Module

If you are using the Autoresponder-Service.com account that is included for free with your full AShop V license, you can enable the newsletter module to let visitors sign up with your mailing list, which can of course be an autoresponder. You need to select the list you wish to use for this on the Configuration->Shop Parameters page to make it work. There should be an option labeled "Newsletter Autoresponder" on that page with a drop down list showing all your available autoresponders/lists.

 

By using the DHTML popup mode of the newsletter module you can make the storefront page ask every new visitor to sign up with your list before they start shopping. The whole page will be greyed out while a signup box shows on top of it. To enable this, put the following code directly after the BODY tag of your storefront script:

 

<?php

       // Show newsletter subscription form...

       $layout = 2;

       $subscribe = "index.php";

       include "includes/newsletter.inc.php";

?>

 

The $subscribe parameter must be set to the filename of the page you are using this code on, which would be index.php when it is used on the storefront.

 

To just show a form somewhere on the page, use the following code in the location where you want the form to show up:

 

<?php

       // Show newsletter subscription form...

       $layout = 1;

       $subscribe = "index.php";

       include "includes/newsletter.inc.php";

?>

 

You can also use the following optional parameter to disable the captcha code:

 

       $captcha = "off";

 

The captcha parameter must be set before the include statement.

 

Category List Module

To list your product categories you can use the categories.inc.php module. For example:

 

<?php

       // Show categories...

       $catalog = "index.php";

       include "includes/categories.inc.php";

?>

 

The name of each category is a link that should lead to a page that shows the products that belong to the category, the $catalog parameter determines which page the links lead to.

 

To create a custom list of categories you can use the layout parameter to get the full category tree as an unordered list:

 

<?php

       // Show categories...

       $layout = "2";

       $catalog = "index.php";

       include "includes/categories.inc.php";

?>

 

The default value of the layout parameter is "1", which gives you the standard categories list in a table. Using mode "2" will, for example, let you create vertical or horizontal drop down lists, using CSS.

 

You can limit the listing to just one category and its subcategories by using the cattree parameter. It must be set to the category ID of the top category, for example:

 

<?php

       // Show categories...

       $cattree = "1";

       $catalog = "index.php";

       include "includes/categories.inc.php";

?>

 

Which will show category 1 with all its subcategories.

 

You can also exclude certain categories from the listing by using the exclude parameter, set to a pipe separated list of category IDs to exclude, for example:

 

<?php

       // Show categories...

       $exclude = "1|2";

       $catalog = "index.php";

       include "includes/categories.inc.php";

?>

 

Which will skip categories 1 and 2 from the list.

 

Language Selection Module

This module will display a drop down list of all available languages.

 

<?php

       // Show language selection...

       $redirect="index.php";

       include "includes/language.inc.php";

?>

 

It only takes one parameter: redirect, which should be set to the page that will be shown after the customer selects a language. If you skip this parameter or leave it blank, the redirect URL configured for each language in its lang.cfg.php file will be used instead, which can be used to redirect the customer to a different page for each language.

 

Currency Selection Module

This module will display a drop down list of currencies which a customer can select from to view the prices in their local currency with automatic currency conversion.

 

<?php

       // Show currency selection...

       $redirect="index.php";

       $currencies="usd,cad,aud,eur";

       include "includes/currency.inc.php";

?>

 

The $currencies variable can be set to a comma separated list of currencies and will limit the available currencies to those included in this list. Note that this will only affect how the price is viewed by the currency, not the actual currency used for the payment when a customer places an order.

 

The TopForm Module

If you use the catalogue.php script as your storefront instead of the more advanced modular index.php script, it will include a form at the top of the page with the search box, the subtotal of the cart contents and the View Cart and Checkout buttons. These can be placed individually instead, using the topform.inc.php module, if you wish to use the modular storefront. Here are some examples...

 

This code will just show the search box:

 

       <?php

               // Show search box...

               $layout = 3;

               $search = "index.php";

               include "includes/topform.inc.php";

       ?>

 

This one will show the subtotal field, the customer profile links and a placeholder for "added to cart" messages:

 

       <?php

               // Show subtotal...

               $layout = 4;

               include "includes/topform.inc.php";

       ?>

 

This will show only the subtotal field, without the customer profile links or the placeholder:

 

       <?php

               // Show shopping cart buttons...

               $customerlogin = "off";

               $confirmmessage = "off";

               $layout = 4;

               include "includes/topform.inc.php";

       ?>

 

This code will show the shopping cart buttons:

 

       <?php

               // Show shopping cart buttons...

               $layout = 5;

               include "includes/topform.inc.php";

       ?>

 

This will show the default box, but wherever you want to place it:

 

       <?php

               // Show shopping cart buttons...

               $layout = 2;

               include "includes/topform.inc.php";

       ?>

 

This will show only the customer profile links:

 

       <?php

               // Show shopping cart buttons...

               $layout = 6;

               include "includes/topform.inc.php";

       ?>

 

Displaying the product list or search results

The catalogue.php script shows the list of products for a selected category while the search.php script shows the results of a search. They can either be used standalone or as part of a modular storefront script. To use them in a storefront script add the following code:

 

               <?php

                       // Show product list or search results...

                       $topform = "off";

                       $categories = "off";

                       if($searchstring) {

                               $search = "index.php";

                               include "search.php";

                       } else if ($product) {

                               $catalog = "index.php";

                               include "product.php";

                       } else {

                               $catalog = "index.php";

                               include "catalogue.php";

                       }

               ?>

 

By adding the line: $topform = "off", the output will not include a box at the top of the list, with a search field, the subtotal of the shopping cart contents and the View Cart/Checkout buttons.

 

By adding the line: $categories = "off", the output will not include a categories list to the left of the products/search results. Use this if you want to place the categories using the categories list module instead.

 

The $search parameter must be set to the filename of the script that shows the search results and the $catalog parameter must be set to the filename of the script that shows the product list. Both should be set to "index.php" when you use the default storefront script.

 

Using Custom Modules

The storefront script can of course show any other module or dynamic content you want to use. As an example of this the default index.php script includes a SimplePie RSS reader, which can show news feeds from an external site or even article links from your own blog. This is the code that runs this script:

 

               <?php

                       // Demonstrates how to include a news feed reader on your storefront...

                       include "includes/simplepie.inc.php";

                       $feed = new SimplePie();

                       $feed->set_cache_location("./updates");

                       $feed->set_cache_duration(900);

                       $feed->set_feed_url($ashopnewsfeed);

                       $feed->init();

                       if ($feed->data) {

                               $items = $feed->get_items(0,5);

                               foreach($items as $item) echo " &nbsp;<img src=\"images/bullet.gif\" alt=\"o\" /> &nbsp;<a href=\"".$item->get_permalink()."\" target=\"_blank\">".$item->get_title()."</a><br />";

                       }

               ?>

 

To change the news feed just set the News Feed option on the page Configuration->Shop Parameters in your admin panel to the URL of any RSS news feed you want. The default is to show any link items you have added to your catalog.