File: examples/cart/app/controllers/cart.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil  >  PHP Skeleton Framework  >  examples/cart/app/controllers/cart.php  >  Download  
File: examples/cart/app/controllers/cart.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Skeleton Framework
Extensive Web application development framework
Author: By
Last change:
Date: 5 years ago
Size: 1,612 bytes


Class file image Download

class cart extends A_Controller_Action

    public function
$request = $locator->get('Request');
$response = $locator->get('Response');
$session = $locator->get('Session');
// load product model
$product = $this->_load()->model('product');
// get cart from session
$cartsession = new A_Cart_Session($session);
$cart = $cartsession->getInstance();

// process cart params to add, delete, change items
$cartrequest = new A_Cart_Request($cart);

// get any items added so we can fetch associated product records
$newitems = $cartrequest->getNewItems();
        if (
$newitems) {
// get SKUs for query
$skus = array();
            foreach (
$newitems as $item) {
$skus[] = $item->getProductID();
// get all new product records in one query
$rows = $product->findProductsSkus($skus);
// assign product data to cart items for display
foreach ($newitems as $item) {
$sku = $item->getProductID();
                foreach (
$rows as $row) {
                    if (
$row['sku'] == $sku) {
$item->setData('name', $row['name']);
$item->setData('color', $row['color']);
$item->setData('size', $row['size']);
// add new items now that they have had product data assigned
$response->setPartial('content', 'cart', array('product'=>$product, 'cart'=>$cart, 'cartrequest'=>$cartrequest));

For more information send a message to info at phpclasses dot org.