Tải bản đầy đủ (.pdf) (5 trang)

PHP 5 e-commerce Development- P66 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (334.86 KB, 5 trang )

Interacting with Web Services
[ 308 ]
This is reected in the JavaScript as follows:
pageTracker._addTrans(
"111", // the order ID - this is a required field
"Props", // affiliation or store name
"10.50", // total - required
"0.00", // tax
"10.00", // shipping
"Newcastle", // city
"Tyne and Wear", // state or province
"UK" // country
);
Add item
For each item within the transaction, we must record:
The order ID
The product code or stock keeping unit (SKU)
The unit price for the item
The quantity of the item
We can also record:
The product name
The category or variation of the product
This is reected in the JavaScript as follows:
pageTracker._addItem(
"111", // order ID - necessary to associate item with transaction
"P1", // SKU/code - required
"Fake Water Jug", // product name
"Large", // category or variation
"10.50", // unit price - required
"1" // quantity - required
);


Track transaction
Once the transaction, and all items within the transaction, have all been added,
we track the transaction, by issuing the following JavaScript call:
pageTracker._trackTrans();






This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Appendix A
[ 309 ]
Further reading
• Tracking number of sales (but nothing else)—Analytics Talk—http://
www.epikone.com/blog/2008/06/25/google-analytics-e-commerce-
tracking-pt-3-why-everyone-should-use-it/
Tracking lead generation forms ( />blog/2008/07/02/google-analytics-e-commerce-tracking-pt-4-
tacking-lead-gen-forms/)
Tracking API: e-commerce ( />docs/gaJS/gaJSApiEcommerce.html)
Other services
Both Amazon and eBay (along with a number of other retailers) have APIs that allow
developers to sell products by listing them using an API.
Amazon
Amazon's Marketplace Web Service (Amazon MWS) allows sellers to list items for
sale on the Amazon marketplace through an API. By using this, we could automate
the process of listing products we have in our own e-commerce store, on the Amazon
marketplace website. This would extend opportunities for new customers to do
business with us. By suitably integrating the API with our framework, we could:

Automatically list our products on Amazon marketplace
Automatically remove our products from Amazon marketplace when stock
levels are low
A PHP client library is available for the Amazon MWS API, which can be used to
integrate with our framework: />eBay
eBay has a developer center for various languages and APIs, including searching,
managing feedback, and of course, creating listings. With this API we could:
Automatically create listings based on new products
Automatically create repeat listings for existing products that are still in stock
(perhaps, generating new ones each week)
Automatically post good feedback to the buyer once the order is complete







This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Interacting with Web Services
[ 310 ]
A number of PHP resources are available for working with the API, including
ones specic for their trading API, which would be of most use to us. Some of
these include:
/> />More to come
There are a few more web services, which we will look at interacting with in
Appendix C, Cookbook.
Summary
In this chapter, we have primarily looked at the Google merchant center and how we

would create a data feed of products which would automatically update with our
product catalog, to keep our information constantly up to date in Google product
search. We also had a brief look at:
What similar services are available
Google Analytics:
Tacking website statistics
Tracking sales
Order data
Item data
Amazon web services
eBay developer center




°
°




This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Downloadable Products
In this appendix, we are going to look at how we would rapidly extend our
framework to allow downloadable products. In this chapter, you will learn:
How to extend the types of products available in the framework
How to extend the payment and administration areas to unlock
downloadable products when payment is made
How to lock access to downloaded products when payment is refunded

How to create a centralized download area for customers to access
downloadable products
This is a very basic implementation of downloadable products functionality. Ideally,
we would also look into storing the les in a location that isn't accessible through the
Web. We would then either copy the le for each user who purchases the product in
a unique location, or create a script, which when an authorized user copies the le,
temporarily to a public location, allows a single download, and then removes
that copy.
Extending products
When we abstracted out content earlier in the book, we separated product-specic
data in a table, content_types_products. This is the table we need to extend to
enable downloadable products.
We should just need to add two new elds to this table:
Downloadable: This indicates if the product is downloadable.
File: This indicates the name of the le.






This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Downloadable Products
[ 312 ]
We also need to dene a setting, which will be the location of les that are
downloadable products.
ALTER TABLE `content_types_products`
ADD `downloadable` BOOL NOT NULL DEFAULT '0',
ADD `file` VARCHAR( 255 ) NULL

Extending the payment and
administration areas
To extend the payment and administration areas to allow customers to download
the les for their purchases, we should create a centralized record of these types of
purchases (we will discuss this later in more detail). This makes providing a nice
download area much easier.
At this stage, there are three things we need to do:
Create a new database table relating customers to their downloadable
purchases
Update the payment methods to automatically provide access to these
downloads by creating new records in the new table when payment
is received
Update the payment methods to automatically remove access to these
downloads by removing records from the new table when orders are
updated to "refunded".
Access database
Our table for providing access to download les needs the following elds::
An ID
A reference to the customer's ID
A reference to the product ID
The date access was granted
The location of the le
The location at present will just be copied from the products table. However, it
makes things easier for us if we extend the functionality to create a separate copy
of the le for each customer.









This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724

×