CakePHP-Cart icon indicating copy to clipboard operation
CakePHP-Cart copied to clipboard

Rewrite the Cart Session Component

Open ProLoser opened this issue 14 years ago • 0 comments

Notes from it's development:

DATA ARRAY NEEDS TO BE UPDATED!!!

/**
 * Shopping Cart Component
 *
 * @author  Dean Sofer (ProLoser)
 * @version 0.2
 * @package CakePHP Shopping Cart Plugin Suite
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Potential configuration options
 *

 var $components = array('ShoppingCart' => array(
    'useTable' => false,
    'nameField' => $this->Model->displayField,
    'priceField' => 'price',
    'taxableField' => 'taxable',
));

/**
 * Shopping Cart Data Array Example
 *

[Order] => array(
    [LineItem] => array(
        [1] => array(
            [Product] => $yourProductInfo,
            [taxable] => true,
            [name] => 'my name',
            [description] => 'this is a test',
            [price] => 13.25,
            [quantity] => 2,
        ),
        [2] => array(
            [Product] => $yourProductInfo,
            [taxable] => true,
            [name] => 'my name',
            [description] => 'this is a test',
            [price] => 13.25,
            [quantity] => 1,
        )
    ),
    [Billing] => $customerInfo,
    [Shipping] => $customerInfo,
    [Totals] => array(
        [subtotal] => 39.75,
        [Discount] => array(
            [0] => array(
                [label] => 'My happy discount',
                [amount] => -50.23,
                [quantity] => 1,
            ),
            [1] => array(
                [label] => 'Sale',
                [amount] => -5,
                [quantity] => 2,
            ),
        ),
        [tax] => 3.49,
        [shipping] => 10.00,
        [total] => 53.24,
    )
)

/**
 * There are 3 common ways to store $yourProductInfo. 
 * This all depends on how the products are normally tracked, 
 * however different product types cna be stored in 1 order.
 *
 // This would be used when 1 product 
 // table is associated by default. It can be used to reference 
 // the table for more information.
$yourProductInfo = $model_id; 

 // Loading the product record (or multiple related records) to 
 // keep the info handy. Product.id /should/ be present?
$yourProductInfo = array(
    [ModelA] =  array('id', 'field_b', 'field_c')
    [ModelB] =  array('modela_id', 'id', 'field_c')
 );

 // Custom data for usage with static products or other custom details
$yourProductInfo = array(
    'start_date',
    'end_date'
);

 */



//////////// JESSE ARRAY EXAMPLE FILE ////////////
Quick Usage:

    // Add product to Cart in Session
    $this->ShoppingCart->addItem($id);

    // Output Order Details
    pr($this->ShoppingCart->getOrderDetails());

The actual generated array in my Session after implementation:

Array
(
    [LineItem] => Array
        (
            [1] => Array
                (
                    [Product] => Array
                        (
                            [id] => 1
                            [parent_id] => 
                            [name] => Harry Potter: The Tales of Beedle the Bard
                            [type] => apparel
                            [description] => Cool book
                            [quantity] => 50
                            [price] => 19.99
                            [limit] => 10
                            [taxable] => yes
                            [visible] => yes
                            [created] => 2008-12-11 15:55:19
                            [modified] => 2008-12-11 15:55:19
                        )

                    [name] => Harry Potter: The Tales of Beedle the Bard
                    [price] => 19.99
                    [description] => Cool book
                    [taxable] => yes
                    [quantity] => 39
                    [subtotal] => 779.61
                )

            [2] => Array
                (
                    [Product] => Array
                        (
                            [id] => 2
                            [parent_id] => 
                            [name] => Twilight
                            [type] => generic
                            [description] => Another Cool Book
                            [quantity] => 50
                            [price] => 23.99
                            [limit] => 5
                            [taxable] => yes
                            [visible] => yes
                            [created] => 2008-12-11 15:57:20
                            [modified] => 2008-12-11 15:57:55
                        )

                    [name] => Twilight
                    [price] => 23.99
                    [description] => Another Cool Book
                    [taxable] => yes
                    [quantity] => 4
                    [subtotal] => 95.96
                )

        )

    [Totals] => Array
        (
            [subtotal] => 875.57
            [tax] => 0
            [shipping] => 0
            [total] => 875.57
        )

)

ProLoser avatar Jul 22 '11 20:07 ProLoser