¿En este mensaje te envio un ejemplo de una clase en PHP y como lo podrias utilizar
<?php
class ShoppingCart {
var $items;
function add_items($product_id, $qty)
{
$this->items[$product_id]=$qty;
}
function update_items($product_id, $qty)
{
if(array_key_exists($product_id, $this->items))
{
if($this->items[$product_id]>$qty)
{
$this->items[$product_id]-=($this->items[$product_id]-$qty);
}
if($this->items[product_id]<$qty)
{
$this->items[$product_id]+=abs($this->items[$product_id]-$qty);
}
if($qty==0)
{
unset($this->items[product_id]);
}
}
}
function remove_item($product_id)
{
if(array_key_exists($product_id, $this->items))
{
unset($this->items[$product_id]);
}
}
function show_cart()
{
return $this->items;
}
}
$cart = new ShoppingCart;
$cart->add_items("Apples", 5);
$cart->add_items("Oranges", 15);
$cart->add_items("Peaches", 17);
$cart_items = $cart->show_cart();
foreach($cart_items as $key => $value)
{
echo "Item name = $key; Item quantity: $value <br>";
}
$cart->update_items("Peaches", 28);
$cart->update_items("Oranges", 7);
$cart_items=$cart->show_cart();
echo "================<br>";
foreach($cart_items as $key=>$value)
{
echo "$key = $value<br>";
}
$cart->remove_item("Oranges");
$cart_items=$cart->show_cart();
echo "================<br>";
foreach($cart_items as $key=>$value)
{
echo "$key = $value<br>";
}
?>
Y este es un ejemplo de envio de mensajes via php
<?php
$to = '
[email protected]';
$subject = 'titulo mail';
$message = 'Mensaje';
$headers = 'From:
[email protected]' . "\r\n" .
'Reply-To:
[email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>