Chapter 4 - Shopping Cart

The ecommerce portion of the wePrint Design Studio, provides a simple shopping cart to hold the customer's items and a simple checkout form that is sent to your Paypal account for payment processing. The cart simply calculates the price of each item and the total based on the prices you set in the product xml files. The cart does not provide a means for calculating tax, shipping or discounts. These costs need to be set within your paypal checkout page.

4.1 Shopping Cart Functionality

The shopping cart that is provided with the wePrint Design Studio, provides a simple cart that can be used with your paypal account. As seen in Figure 4.1.1, the cart displays the thumbnail of each design, the type of product, and the description (including Design ID, color, and size).



The cart also has an editable quantity box and a remove checkbox.

The checkout page allows the customer to input both the billing and shipping addresses.



The input fields that are labeled, "required", are validated before moving to the confirmation page. The customer must correct invalid inputs before moving forward. The postal code is validated against US and Canadian postal codes. If you are in another country and need to adjust the postal code input box please email the wePrint support for details on making adjustments.

Modifiying the Country and State Lists
The code that lists the countries can be changed to accomodate your needs. The country list is as follows:

<select name="country" id="country" >
<option value="" selected="selected">Choose a country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
Each country and country code needs to be placed within an option tag.
The states/provinces list initially shows the US and Canadian states, provinces and territories.
select name="state_province" id="state_province" >
<option value="" selected="selected">Choose a state</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
........................................................................
<option value="QC">Quebec</option>
<option value="SK">Saskatchewan</option>
<option value="YK">Yukon</option>
</select>
You can modify this list in a simlar manner as the country list . Simply replace the states accordingly.

The confirmation page shows the shopping cart, the billing information and the shipping information. When the customer clicks Submit, they will be taken to your Paypal checkout page.

Important: You must place your paypal email into the shop-defaults.xml file within the paypalEmail tag. If the email is not correct, the customer will be taken to an invalid checkout page on the paypal site.


4.2 Paypal Processing

When the customer Submits their order they will be taken to your paypal checkout page. There are a few things in need to modify in your Paypal account to make things work correctly.

4.2.1 Paypal Account Setup

Within your Paypal account go to - Profile : Selling Preferences : Website Payment Preferences
  • Auto Return for Website Payments - Turn On, You can leave the return URL blank. The shopping cart will send the return URL along (www.example.com/order-complete.php)
  • Payment Data Transfer - Turn On, This will send the confirmation info to the order-complete page.
Within your Paypal account go to - Profile : Selling Preferences :Instant Payment Notification Prefrences and select Edit IPN. You will be give a token.

Once the customer checks out of the paypal page they are redirected to the order-complete.php page where they we see a receipt of the transaction. Also, an email will be sent to your email address and to the customers


4.3 Using Your Own Cart

In order to replace the included cart with your own cart, you will need to have an understanding of php along with knowledge of your shopping cart code. This guide assumes you meet the above mentioned requirements.

Add to Cart via addtocart.php:
The add to cart button in the design studio provides an AJAX call to the php/addtocart.php file. This file contains the code that connects to the shopping cart. The shopping cart is defined in the WA_eCart/wePDS_cart_PHP.php file. In particular the code - $wePDS_cart->AddToCart - is the object that adds the item to the cart. If you have your own cart, you will need to pass the POSTED data from the AJAX call to your cart object. As can be seen in the addtocart.php file, each attribute is passed within a $_POST. The posted data is as follows:

  • design_id2 - the design ID.
  • design_name2 - the name of the design.
  • actprod2 - the type of product.
  • productSize2 - the size of the item.
  • productColor2 - the color of the item.
  • Quantity_Add2 - the quantity to be added to the cart.
  • productPrice2 - the price of the item.

You need to pass these parameters to your cart through whichever object it is that you have defined for your cart. If you are not using the cart provided with the deisgn studio, you need to remove the first two lines from the addtocart.php file:

require_once("../WA_eCart/wePDS_cart_PHP.php");
$wePDS_cart->GetContent();

These lines need to be replaced with code that will include your defined cart.

Once the item has been added to the cart through the cart object, the price and total number of items is echo-ed back to the design studio, to be displayed in the quick cart. If you want to return the cart contents to the quick cart, you will need to modify the following line:

echo $wePDS_cart->TotalColumn("Quantity").'+'.$price;

with

echo $YOUR_CART_QUANTITY_VARIABLE. '+'. $YOUR_CART_TOTAL_VARIABLE;
the '+' is used to delimit the quantity and total variables.

Get Cart Contents via getcart.php:
When the design studio loads there is an AJAX call to the php/getcart.php file. This call will get the cart quantity and total to be displayed in the quick cart. As with the addtocart.php file, you will need to modify this file so that you can connect to your cart object. The code outline is as follows:

  • include the cart object file
  • get the cart contents
  • echo the number of items and total price

Be sure to delimit the two paramaters with a '+'. You may notice that there are other extra parameters. These are can be ignored as they are not being used at this time.