Also in presentation/link.php, delete the ToAddProduct() method, and add a method named
ToCart() that creates the Add Product and View Cart links:
// Create a shopping cart link
public static function ToCart($action = 0, $target = null)
{
$link = '';
switch ($action)
{
case ADD_PRODUCT:
$link = 'index.php?CartAction=' . ADD_PRODUCT . '&ItemId=' . $target;
break;
default:
$link = 'cart-details/';
}
CHAPTER 12 ?– CREATING YOUR OWN SHOPPING CART 380
return self::Build($link);
}
5. Open presentation/products_list.php, and find the following code from the init() method of the
ProductList class:
// Create the Add to Cart link
$this->mProducts[$i]['link_to_add_product'] =
Link::ToAddProduct($this->mProducts[$i]['product_id']);
Replace it with the following code that builds the Add to Cart links for our shopping cart:
// Create the Add to Cart link
$this->mProducts[$i]['link_to_add_product'] =
Link::ToCart(ADD_PRODUCT, $this->mProducts[$i]['product_id']);
6. Open presentation/product.php, and find the following code from the init() method of the Product
class:
// Create the Add to Cart link
$this->mProduct['link_to_add_product'] =
Link::ToAddProduct($this->_mProductId);
Replace it with the following code that builds the Add to Cart links for our shopping cart:
// Create the Add to Cart link
$this->mProduct['link_to_add_product'] =
Link::ToCart(ADD_PRODUCT, $this->_mProductId);
How It Works: Adding Products Links
You created Add to Cart buttons that link to index.
Pages:
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491