Cartweaver 4 PHP and MySQLi

First off let’s briefly look at what MySQLi is. 
PHP has always had a special relationship with the MySQL database, it is literally designed to work with MySQL and the two applications use this symbiosis to be a very effective web application platform.  Over the last few years however MySQL has made some extraordinary progress in being a truly powerful, fully relational database. It has not always been this way, for a long time MySQL was kind of a rigged flat file system which was blazingly fast and could scale to pretty amazing proportions, considering the way it was put together, but it was not technically a relational database. Since v4.1 however MySQL has been the real deal, a good solid relational database. The downside to this progress is that the PHP MySQL Extension that allowed the two to work so well together has not really kept pace with MySQL’s progress. So PHP developers set about replacing the old MySQL extension with a new more robust one and as of PHP 5.5 PHP will require developers to use MySQLi  to communicate with MySQL databases versions 4.1.3 and later. This is, from all that I have read and the discussions I’ve been in on, a good move. MySQLi is a more feature rich and arguably a more secure way to communicate with MySQL.  There’s far more information on this than I can cover here, indeed entire books are being written on the topic, but suffice to say, this is the way PHP and MySQL are going, so better get on board.

That being said, the question to ask is, does Cartweaver 4 PHP use MySQLi and is it compatible with PHP 5.5?  The answer is no, not right now, but yes it certainly will be, and it will be well before it becomes any kind of a problem for developers and Cartweaver users!  Is the lack of MySQLi support a problem now? No. Remember there are millions of legacy PHP/MySQL applications already on the web and still in development that use the legacy PHP / MySQL extension, so this change, by the very nature of the web will happen slowly, but it will happen.  As an example, there are an incredible number of web sites still being powered by traditional ASP, and even a few developers that are developing current sites in it – certainly NOT a course I’d recommend – even though vb-ASP has not been actively supported or updated for years!  The point is with an order of magnitude more pre PHP 5.5 sites in use today, this is a situation that will change at a pretty glacial pace.

How will hosts handle this?
A good example would be to look at what many of them do now – for example look at HostGator:  http://support.hostgator.com/articles/hosting-guide/hardware-software/what-version-of-php-are-you-using  -  Depending on the selected service, users can choose between PHP 5.2, 5.3 or 5.4  and before long they we will no doubt see PHP 5.5 showing up as a choice. Given that it was released just a few of weeks ago, it will be a while before it is installed on most servers.

So for the next year or so, or more, so long as users can choose to run PHP 5.4 or lower,  the Current release of Cartweaver 4 PHP will run properly.

Does this mean we are going to sit back and wait? Certainly not! We are already at work on making the switch to MySQLi, we have worked really hard to make Cartweaver 4 a powerful robust ecommerce solution, so it makes perfect sense to be very pro-active in making the transition to a more robust database connection method.  In brief here is what we are in the process of doing…

Step One:  We are starting out by replacing the mysql directives with mysqli directives.

Basically, this is doing an application wide update of mysql_connect   replace it with mysqli_connect  , and  mysql_query , replacing it with mysqli_query   – there may be a few other commands to replace here and there and we will test as we go for stability and performance, but this will cover the first phase.

Is that it?  Well it could be, this will get things working under PHP 5.5 so this is what we will do first. But we won’t stop there.

Step Two: Once the application is fully working under PHP 5.5 with the above changes we will then go through the application and see where we can take advantage of using parameter appending, instead of putting the parameters in the middle of the query. This among some other things MySQLi brings to the table is a better, and supposedly more secure, way to build queries, so over time we will replace the current query syntax with the MySQLi syntax, starting with areas where we may be able to see the best performance enhancements.

Naturally step two will take longer but this is where we will be going. The web is a constantly moving target and we fully intend on continuing to move with it.

Now to answer the inevitable next question; when will the update be available?  Well PHP 5.5 was just released on June 20th, so seriously we have a little time here.  The web community is pretty good about getting really worked up about things that won’t have a real-word impact for some time to come, so let’s take a moment to cool our jets here.  But we will have Step one out in the near future, we know this is where PHP/MySQL are headed and we will stay ahead of the curve, this is as important to us as it is to you.

So the short answer is, we are all over it, and we will keep you informed of our progress and will let you know as soon as the initial MySQLi updated version is available. So stay tuned here, and be sure to follow us on Facebook, Twitter and on the Cartweaver community Forums.

If you have any questions please let me know I’ll be glad to answer them!

Google is dropping support for Google Checkout

We resisted the pressure to support Google Checkout. We never really liked the way it was implemented and although there was a lot of buzz when it was launched, it never really looked like a strong contender when compared to Authorize Net, the various PayPal products and so forth, so we decided early on to focus our attention on other features and options. Turns out our crystal ball was pretty clear on this one. As of November 2013 Google will be dropping support for Google checkout. We applaud this move on their part – it’s always a good thing to focus on what you do well, and this service was pretty clearly out of Google’s wheelhouse.

Google Wallet will still be available, but we like this even less as a viable payment gateway for a standalone online store. There are much better choices to be made for this.

When choosing a payment gateway provide an important point to keep in mind is this is your most direct connection to YOUR money!

The most important things to keep in mind when selecting a gateway provide are

  1. They must be rock solid, secure and stable.
  2. They need to have as little impact as possible on your customer’s quick, seamless, and easy checkout.
  3. Longevity – how long they have served the industry and their current reputation says a lot about how long they will be around and how well they will serve you and your customers.

There are always newcomers to any market. As developers, when it comes to payment gateway providers, we have to resist the “ooo new and shiny” distractions and base our decisions on what will provide a good long term solution that can grow and scale as our future needs dictate. Choosing a payment gateway provider is an important decision and one place in our fast paced business where it pays to be more conservative.

How to use show/hide content based on user status – Part II (ColdFusion)

Our past post tackled how to show/hide certain content based on user status. in PHP.

This time, we”’ll do the same in ColdFusion.

To determine if a site visitor is logged in or not:

<cfif isdefined(“session.cwclient.cwCustomerID”) AND session.cwclient.cwCustomerID NEQ ‘ ‘ >User is logged in. (use your own  HTML here)
<cfelse>
User is Not Logged in  (use your own  HTML here)
</cfif>To determine if a site visitor is logged in or not and is not a checking out as a guest:

<cfif isdefined(“session.cwclient.cwCustomerID”) AND session.cwclient.cwCustomerID NEQ ‘ ‘ AND session.cwclient.cwCustomerCheckout NEQ ‘guest’>
User is logged in and is not using the guest checkout. (use your own  HTML here)
<cfelse>
User is Not Logged in, or is using the guest checkout  (use your own  HTML here)
</cfif>
Happy coding!

How to use show/hide content based on user status

On occasions, you may want to show certain content only for registered users. Since Cartweaver already has a customer registration form and login features, you may use that to show/hide your own content.

To do so, you need to make sure that the page you are using the code in, has the main Cartweaver application file included at the very top :

<?php require_once(“Application.php”); ?>

Then you need to check for the relevant sessions, to determine if a site visitor is logged in or not.  For that purpose, you would use a code snippet such as this:

<?php if (isset($_SESSION["cwclient"]["cwCustomerID"]) && $_SESSION["cwclient"]["cwCustomerID"]!=”) { ?>

User is logged in. (use your own  HTML here)

<?php } else { ?>

User is Not Logged in  (use your own  HTML here)

<?php } ?>

The code above, will include users that are checking out as guests ( since the cwCustomerID Session is present).  If we want to show/hide content only for users who have created an account, you would use the code below:

<?php if (isset($_SESSION["cwclient"]["cwCustomerID"]) && $_SESSION["cwclient"]["cwCustomerID"]!=” && $_SESSION["cwclient"]["cwCustomerCheckout"]!=”guest”) { ?>

User is logged in and is not using the guest checkout. (use your own  HTML here)

<?php } else { ?>

User is Not Logged in, or is using the guest checkout  (use your own  HTML here)

<?php } ?>

The difference here, is that we include $_SESSION["cwclient"]["cwCustomerCheckout"] in our conditional, so that it does not equal “guest”, which happens when a user wants to checkout as a guest without creating an account.

Happy coding !

Integrating Social Networks with your Cartweaver 4 store

Nowadays, social networks play a large part in promoting our client’s sites and stores. Integrating each individual social network, can take quite a bit of work, and, on top of that you must get familiar with each of the social network’s API.

In this blog post, we’ll teach you how to make use of a great 3rd party script, to make your store have social integration, in just a few minutes.

We will be showing you how to integrate AddThis to your product detail page.

Step 1)

Visit AddThis at http://www.addthis.com, and get your free code. ( click the “Free Get Started” blue button)

At this stage, you will be prompted to create an account. Although it’s a nice feature, since it will give you a whole lot of stats on the script usage, you don’t NEED to create an account. You can proceed without using analytics by clicking the “Don’t want analytics” link below the Sign In button.

 Step 2)

You can choose what buttons to use, or just use the default options provided by AddThis.

In this example we will use the default code (similar to the code below) :

<!– AddThis Button BEGIN –>
<div class=”addthis_toolbox addthis_default_style “>
<a class=”addthis_button_facebook_like” fb:like:layout=”button_count”></a>
<a class=”addthis_button_tweet”></a>
<a class=”addthis_button_pinterest_pinit”></a>
<a class=”addthis_counter addthis_pill_style”></a>
</div>
<script type=”text/javascript” src=”//s7.addthis.com/js/300/addthis_widget.js”></script>
<!– AddThis Button END –>

Step 3)

Open file cw4\cw-product.php (or .cfm), and paste the AddThis code where you want it to be displayed.

For instance, if you want to display it right after the product title:

PHP :
<h1 class=”CWproductName”><?php echo $product["product_name"]; ?></h1>
AddThis Code here

ColdFusion:
<h1 class=”CWproductName”>#product.product_name#</h1>
AddThis Code here

This is what it will look like:

Click to enlarge

This will allow your customers to spread the word about your site and products!  If they want to share your store with thier friends, but all means, do what you can to make it easy for them!

Cartweaver Search and Navigation Options Code Snippet explained

Cartweaver offers a variety of search and navigation code snippets. These are listed  in the default index.php page, where you can see them in action, and even get the relevant code snippet.

If you take some time to experiment with this aspect of Cartweaver you will be pleasantly surprised how easy and powerful this feature is. You may want to set up a local practice site and spend some time experimenting with the various settings. Acquainting yourself with this feature will give you greater control and creative freedom next time you add Cartweaver to a web site!

Here is a detailed breakdown of how to use this very powerful snippet.

Basic syntax is
<?php
$module_settings = array(
“parameter” => true/false,
“parameter2″ => “value”,
…(more parameters here)…
);
include(“cw4/cwapp/mod/cw-mod-searchnav.php”);
unset($module_settings);
?>

There are a lot of parameters you can use.   The most important parameter, is search_type, which can be:

a) list
Generates an UL list with the navigation links. This can be styled to fit your needs ( vertically, horizontally, you name it. Your CSS skills are the only limit as to how you can style it.

Unstyled List Preview

b) links
This generates a series of links  with the defined navigation options. As opposed to the “list” type, this dopes not use an unordered list… just a series of a tags.

Links Preview

c) form
This generates a search form.

Form Preview


d) breadcrumb

This generates a breadcrumb trail with the current user location on the site.

In each case, you can use a variety of parameters to control what elements to be displayed and also control the different options  in each case.

Breadcrumb preview
Complete list of parameters

The following is a list of parameters  that can be used:

action_page
This is the  form action / menu target page. By default, it will use the page defined as the results page ( $_ENV["request.cwpage"]["urlResults"] )

show_empty
possible values: true/false
This specifies is categories eith no products in it should be shown ( true) or not shown false)

show_secondary
possible values: true/false
Choose true to display secondary categories. Set this to false to display only main categories

relate_cats
possible values: true/false
By default this is taken from the corresponding setting in the admin: $_ENV["application.cw"]["appEnableCatsRelated"]
If you choose to relate secondary categories to primary cats , then only the secondary categories that have products in a given catgory will be shown.
On the contrary, if you choose to NOT relate them, then, all secondary categories will be listed, regardless of what category  the user is currently seeing.

separator
possible values:  any string
This is only used for horizontal links. It is the separator that is placed between all category links
The default value is |

current_url
This is the link to show as current
Usually, it will be left blank so that Cartweaver can do this automatically, based on the current page in display ( $_ENV["request.cw"]["thisPageQS"] )

all_categories_label
possible values:  any string
This is the text label for ‘all items’ link. Set it blank to have it not show

all_secondaries_label
possible values:  any string
This is the text label for ‘all secondary categories’ link. Set it blank to have it not show

all_products_label
possible values:  any string
Default value: All Items
This is the label for all products link in breadcrumb nav
Set it blank to have it not show

end_label
This is a text item tagged on to end of menu, overridden by search keywords

show_product_count
possible values: true/false
Set this to true to show number of products in each category , and false to not show it.

prepend_links
possible values:  any string
For list or links type, formatted url/labels to insert before the links

append_links
possible values:  any string
For list or links type, formatted url/labels to insert after the links

menu_id
possible values:  any string
This is the  id applied to menu <ul>

menu_class
possible values:  any string
This is the CSS class applied to menu <ul>

Only used for search_type= form
form_id
possible values:  any string
This is the  form id applied to the search <form> tag

form_keywords
possible values: true/false
Show form keyword field  ( true to show it, false to hide it)

form_keywords_text
possible values:  any string
Default value: Search Products
This is the default text entered in the keyword search field

form_category
possible values: true/false
Show category list in search form .

form_category_label
possible values:  any string
This is the text shown for the first entry in the category list

form_secondary
possible values: true/false
This shows/hides the secondary category list in the search form

form_secondary_label
possible values:  any string
This is the text for the first entry in the secondary category list

form_button_label
possible values:  any string
Defalt value: Search
This is the text for the search button

prepend_breadcrumb ( only used in search_type = breadcrumb
possible values:  any string
Insert leading nav elements

Here is a visual example that will help you understand how to work with it

Search Form Explained


The image above is generated by the following code:

<?php
$module_settings = array(
“search_type” => “form”,
“show_empty” => false,
“form_keywords” => true,
“form_keywords_text” => “Search Our Store”,
“form_category” => true,
“form_category_label” => “All Categories”,
“form_secondary” => true,
“form_secondary_label” => “All Subcategories”,
“show_product_count” => true,
“relate_cats” => true,
“form_button_label” => “Search”,
“form_id” => “search1″);
include(“cw4/cwapp/mod/cw-mod-searchnav.php”);
unset($module_settings);
?>

Happy coding !

Setting up CW4 “shipping ranges”

What is Local Calculation?

In Cartweaver 4, along with the options for live rates returned by services like UPS, US Postal Service and FedEx, there is a robust system for calculation of shipping based on the customer’s country, and a defined set of price ranges for either the order total or the total weight of the customer’s shopping cart. When setting up your Cartweaver 4 eCommerce site, you can associate a set of shipping price ranges with each active country in your site, to determine the prices charged at checkout.

This is useful when your store does not use or require a live account, when you want to determine the exact price to specific countries, for specific weights or cart totals, or when one of the live connections return an error message or has a problem with the customer’s address, etc (see fallback, below).

Setting up Local (CW) Shipping Methods

How to set up Cartweaver “localcalc” shipping, in a nutshell:

Start by activating or adding all of the countries you want to make available to the site’s shoppers. (See the options for Shipping/Tax > Countries/Regions in the Cartweaver Administration area.)
Then, check your shipping settings and select whether you want to calculate the shipping cost based on  cart weight or order total. (Shipping/Tax > Shipping Settings)
Next, create the shipping methods for each country, and set up the ranges. (Shipping/Tax > Shipping Methods and Shipping Ranges in the admin menu.) Be sure your first range starts with 0. The Cartweaver Shipping Ranges admin will fill in the next one-cent value higher than the previous range when adding a new one, so all you will need to do is enter the ending numbers for each range. The last one should end with a number higher than your highest expected order total.
With a shipping method for each active country in your site, and local calculation ranges within each method, you are ready to start taking orders with your shipping costs in place.
Once the shopper has selected a country, either during checkout or on the ‘my account’ page, the CW system will attempt to
get rates for each shipping method for that country. (A country may have multiple active methods, creating a multiple choice shipping option for the shopper.)
If any shipping method is set to “localcalc”, the shipping ranges will be used. Details about the cart are passed to the shipping functions in cw-func-shipping, and the rate is returned based on the order total, or the cart weight total, depending on the store settings. For example, if you have a range that goes from 100-150 , based on cart total, and the customer’s cart total is $114, the rate from that range will be applied.

Shipping Ranges as a Fallback for Live Rate Services

The shipping ranges also come into play as a fail safe, or fallback rate, when a non-local lookup fails or returns an error. So if you are using USPS, UPS or FedEx live rates, you can set up the ranges to approximate what those services would return, and the customer will be shown that amount as the rate for that method at checkout, even if the live connection is unavailable, or the address is not valid for the live system.

Fine Tuning the Local Shipping Cost
Once you have your local calculation shipping rates working as expected, you can further fine tune the cost of shipping on specific shipping methods, or specific items by adding a base rate to the shipping method (e.g. a $5 ‘handling charge’ in addition to the variable ship cost ranges) or tack on an additional ship cost value in the Sku admin (Products > select a product > Skus tab > Ship Cost field), to add a flat additional fee per item.
If charging by “cart weight”, you can use the sku weight value to adjust the shipping for oversize items, forcing the order to the next range by entering a value higher than the item’s actual weight, or for items that are free or very cheap to ship, to reduce the calculation applied for that line item in the cart.
There are also a number of ways that discounts can be used to apply free or reduced shipping costs to your orders. Explore the options in your Cartweaver administration area, and check your results by logging in as customers in various countries. Once you are satisfied with your shipping rates and the site is processing live transactions, be sure to monitor the shipping charge being applied as your orders come in, knowing you have the tools to adjust these systems as needed, anytime.
See this page of the Cartweaver 4 documentation for more specific instructions related to third-party shipping services:
http://docs.cartweaver.com/index.cfm?pagename=manage-shipping-3rd-party 
and this page for more about  shipping ranges, and Cartweaver 4 shipping settings in general:
http://docs.cartweaver.com/index.cfm?pagename=manage-shipping .

Using Dreamweaver’s Find function to find Cartweaver code location

Our Cartweaver Support Team gets quite a few questions regarding where to find a given text string or piece of code.

For those of you using Dreamweaver, you have a great tool, to search the entire site. Using it is quite simple, and over time, you will master it’s different settings so you can easily find what you are looking for. If you are already familiar with it, you can probably skip this blog entry, but for those of you who have never used it, we believe this will be a nice addition to your tool set.

Assuming you already have created a site definition with your Cartweaver site in it, to invoke the  “Find Dialog” you need to either press CTRL+F , or access the Edit Menu > Find and Replace

 

You will then see the Find/Replace dialog, as shown below:

Find in:  will allow you to choose the scope of the search. Choose Find In: “Entire Current Local Site” to include all your local site .

Leave all the options unchecked, except for Ignore whitespace.

Enter what you are looking for in the “Find” text area, and then click “Find All”.  Below yuo will see a sample image showing the search results for the string  “Add to Cart”  ( click to enlarge)

In this case, we have found a fair amount of results, along with a small preview of the code where the string was found.  A lot of comments were found, but you can see where it is being used as part of a button label! You can click any of those result lines, to open the matching file at the correct line number.

Dreamweaver’s  find/replace feature is very powerful, allowing you to search the entire site, just some files, a given document, and you can even use regular expressions, but that’s for another post!

Happy coding!

Updating Cartweaver 4 to the Latest Version

When updates to Cartweaver 4 are released, developers have two persistent questions – how to find the changes, and how to apply them. With the right tools and information, applying these updates to your existing Cartweaver 4 site is a routine and relatively easy process.

Finding and Applying Changes to Cartweaver 4

To find the current version of Cartweaver 4, log in to the Cartweaver.com website and look at the “Downloads” tab under “My Account”. The current version is always listed along with the download link for Cartweaver PHP or CFML.

To find your current version, simply log in to your Cartweaver admin and look at the “Global Settings” section. The version number is listed there as an editable field. This value is set automatically with each use of the Database Update Utility.

As with any dynamic, database-driven application, Cartweaver updates may include any number of file or database changes. These are applied in different ways.

Updating the database:

Along with the purchased version of Cartweaver in your “My Account” area, you will see a free download for the Cartweaver Database Update Utility. Follow the instructions inside the downloaded file, to apply the latest CW4 updates to your database. This utility automatically detects your current Cartweaver version and applies any differential updates to your database.

Be sure to select the “Cartweaver 4 (CF or PHP) Database Update Utility”, this is different from the database migration utility for older CW3 site upgrades.

As each new version of Cartweaver is released, a new .sql file will be included in the Update Utility. You can replace the entire utility on your web server, or simply drop the newest .sql file into the appropriate location in your previously-installed Update Utility location.

Updating your files:

As each version is released, we collect our code management difference notes, and make them available on the “My Account page“ at Cartweaver.com. Below the “Downloads” section you will see the appropriate update notes for your version (CFML or PHP). This color-coded report lists all of the changed files since the previous release, along with full documentation of the lines of code that were changed.

See this post for more on applying file changes to customized CW sites.

Note: it is recommended to run the Database Update Utility before merging file changes, as the code changes are often dependent on new content or settings in the database.


Good Practices = Good Results

These are the general steps required to update a Cartweaver site:
- run the database update utility for the new version
- identify and download the file changes,
- and apply the changed files to your site.

Keep in mind, while highly recommended, it is not absolutely mandatory to apply Cartweaver updates. You may want to check the difference notes to see if any small bug fixes or other adjustments apply to your site. Each version of Cartweaver contains all of the fixes of the previous version, so when you update your site at any point, you know you have all of the previous changes and enhancements. However, you must apply BOTH the database and file changes as included with any version. Applying only the file changes, without also updating the database, will usually result in errors appearing on your site.

By applying these general practices and following these steps in order, you can safely and efficiently apply each new release to your existing Cartweaver sites, making sure you have every possible feature, bug fix and security enhancement as time goes on.

See 
this post for a detailed tutorial on using file comparison programs to merge these updates into your code, and always be sure to mark your changes when making edits to Cartweaver. 

1 2 3 6  Scroll to top