Commits

nucklearproject  committed 5a5f968

Actualizaciojn

  • Participants
  • Parent commits b57f7b3

Comments (0)

Files changed (4)

File protected/components/SimpleCart.php

 		return TRUE;
 	}
 
+	// --------------------------------------------------------------------
+
+	/**
+	 * Cart Total
+	 *
+	 * @return	int
+	 */
+	public function total()
+	{
+		return $this->_cart_contents['cart_total'];
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Remove Item
+	 *
+	 * Removes an item from the cart
+	 *
+	 * @param	int
+	 * @return	bool
+	 */
+	 public function remove($rowid)
+	 {
+		// unset & save
+		unset($this->_cart_contents[$rowid]);
+		$this->_save_cart();
+		return TRUE;
+	 }
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Total Items
+	 *
+	 * Returns the total item count
+	 *
+	 * @return	int
+	 */
+	public function total_items()
+	{
+		return $this->_cart_contents['total_items'];
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Cart Contents
+	 *
+	 * Returns the entire cart array
+	 *
+	 * @param	bool
+	 * @return	array
+	 */
+	public function contents($newest_first = FALSE)
+	{
+		// do we want the newest first?
+		$cart = ($newest_first) ? array_reverse($this->_cart_contents) : $this->_cart_contents;
+
+		// Remove these so they don't create a problem when showing the cart table
+		unset($cart['total_items']);
+		unset($cart['cart_total']);
+
+		return $cart;
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Has options
+	 *
+	 * Returns TRUE if the rowid passed to this function correlates to an item
+	 * that has options associated with it.
+	 *
+	 * @param	mixed
+	 * @return	bool
+	 */
+	public function has_options($rowid = '')
+	{
+		return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0);
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Product options
+	 *
+	 * Returns the an array of options, for a particular product row ID
+	 *
+	 * @param	int
+	 * @return	array
+	 */
+	public function product_options($rowid = '')
+	{
+		return isset($this->_cart_contents[$rowid]['options']) ? $this->_cart_contents[$rowid]['options'] : array();
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Format Number
+	 *
+	 * Returns the supplied number with commas and a decimal point.
+	 *
+	 * @param	float
+	 * @return	string
+	 */
+	public function format_number($n = '')
+	{
+		return ($n === '') ? '' : number_format( (float) $n, 2, '.', ',');
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Destroy the cart
+	 *
+	 * Empties the cart and kills the session
+	 *
+	 * @return	void
+	 */
+	public function destroy()
+	{
+		$this->_cart_contents = array('cart_total' => 0, 'total_items' => 0);
+		unset(Yii::app()->session['cart_contents']);
+	}
 
 
 }

File protected/controllers/TestcartController.php

                 'name'    => 'T-Shirt',
                 'options' => array('Size' => 'M', 'Color' => 'Red')
              );
+			 
+			 $data3 = array(
+                'id'      => 'sku_123ABCJJJDDD',
+                'qty'     => 1,
+                'price'   => 39.00,
+                'name'    => 'T-Shirt',
+                'options' => array('Size' => 'M', 'Color' => 'Red')
+             );
 	
 	$update = array(
                 'rowid' => '0256a32c98ce49afbe2a4eb8c96c5884',
 		//$cart = new SimpleCart();
 		Yii::app()->cart->insert($data);
 		Yii::app()->cart->insert($data2);
+		Yii::app()->cart->insert($data3);
+		
+		
+		
+	
 
-
+//Yii::app()->cart->destroy();
 //Yii::app()->session['uno'] = $data;
 //var_dump(Yii::app()->session['uno']);
-var_dump(Yii::app()->session['cart_contents']);
+//var_dump(Yii::app()->cart->contents());
 
-Yii::app()->cart->update($update);
-var_dump(Yii::app()->session['cart_contents']);
+//echo "<hr>";
+//Yii::app()->cart->update($update);
+//var_dump(Yii::app()->session['cart_contents']);
 
+//echo "<hr>";
+//echo Yii::app()->cart->format_number(Yii::app()->cart->total());
+
+	}
+	
+	public function actionList(){
+		
+		$this->render('products');
+	}
+	
+	public function update(){
+	
+		
+	
 	}
   
   }

File protected/data/yii.db

Binary file modified.

File protected/views/testcart/products.php

+<pre>
+CODE:	var_dump(Yii::app()->cart->contents());
+</pre>
+<?php var_dump(Yii::app()->cart->contents()); ?>
+<hr />
+<?php echo CHtml::form(); ?>
+
+
+<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
+
+<tr  style="background-color: #ccc;">
+  <th>QTY</th>
+  <th>Item Description</th>
+  <th style="text-align:right">Item Price</th>
+  <th style="text-align:right">Sub-Total</th>
+</tr>
+
+<?php $i = 1; ?>
+
+<?php foreach (Yii::app()->cart->contents() as $items): ?>
+
+	<?php // echo form_hidden($i.'[rowid]', $items['rowid']); ?>
+
+	<tr>
+	<td><?php echo CHtml::textField($i.'[qty]', $items['qty'], array('maxlength' => '3', 'size' => '5')); ?></td>
+	 </td>
+	  <td>
+		<?php echo $items['name']; ?>
+
+			<?php if (Yii::app()->cart->has_options($items['rowid']) == TRUE): ?>
+
+				<p>
+					<?php foreach (Yii::app()->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
+
+						<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
+
+					<?php endforeach; ?>
+				</p>
+
+			<?php endif; ?>
+
+	  </td>
+	  <td style="text-align:right"><?php echo Yii::app()->cart->format_number($items['price']); ?></td>
+	  <td style="text-align:right">$<?php echo Yii::app()->cart->format_number($items['subtotal']); ?></td>
+	</tr>
+
+<?php $i++; ?>
+
+<?php endforeach; ?>
+
+<tr  style="background-color: #ccc;">
+  <td colspan="2"> </td>
+  <td style="text-align:right"><strong>Total</strong></td>
+  <td style="text-align:right"> $<?php echo Yii::app()->cart->format_number(Yii::app()->cart->total()); ?></td>
+</tr>
+
+</table>
+
+<div class="row buttons">
+		<?php echo CHtml::submitButton('Update Cart'); ?>
+	</div>
+
+<?php CHtml::endForm(); ?>
+