i have continued my developing my code on e-commerce website to grant the discount to client on basis of coupon code entered
<?php
/**
* Consider and apply voucher codes
* Types of voucher code
* - = FIXED AMOUNT OFF
* % = PERCENTAGE OFF
* s = SET NEW SHIPPING COST
* @param voucherCode String
* @return void
*/
if(isset($_POST["submit"])){
$code=$_POST["code"];
$coupon=new coupon();
$coupon->Vouchers($code);
}
class coupon {
function Vouchers( Registry $registry, $voucherCode )
{
//The voucher code value is checked to ensure it is not empty
// (as per point 1)
if( $voucherCode != '' )
{
// we need the date, to see if the voucher has expired
$cts = date('Y-m-d H:i:s');
$voucherCode=$this->registry;
$voucher_sql = "SELECT *, if('{$cts}' > expiry, 1, 0)
AS expired FROM code
WHERE code='{$voucherCode}' LIMIT 1";
$voucher_sql=$this->registry;
$this->registry->getObject('code')->executeQuery( $voucher_sql );
if( $this->registry->getObject('code')->numRows() == 0 )
{
$this->voucher_notice = 'Sorry, the voucher code you entered
is invalid';
}
else
{
$voucher = $this->registry->getObject('code')->getRows();
if( $voucher['active'] == 1 )
{
if( $voucher['expired'] == 1 )
{
$this->voucher_notice = 'Sorry, this voucher has
expired';
return false;
}
else
{
// check to see there are some vouchers, and customer
// has enough in their basket (points 3 and 4)
if( $voucher['num_vouchers'] != 0 )
{
if( $this->cost >= $voucher['min_cost'] )
{
$this->discountCode = $voucherCode;
$this->discountCodeId = $voucher['id'];
// If the discount operation is a percentage, then
// the discount value is applied to the basket cost
// to calculate that percentage. This amount is then
// deducted from the order cost, giving a "discount
// value"% discount from the order.
if( $voucher['operation'] == '%' )
{
$this->cost = $this->
cost - (($this->cost)/100)*$voucher['amount'];
$this->voucher_notice = 'A '
. $voucher['amount']
. '% discount has been applied to your order';
return true;
// If the discount operation is a subtraction, then
// the discount amount from the discount code is
// deducted from the order cost, and the order cost
// is updated to reflect this.
}
elseif( $voucher['operation'] == '-' )
{
$this->cost =
$this->cost - $voucher['amount'];
$this->voucher_notice = 'A discount of £'
. $voucher['amount']
. ' has been applied to your order';
return true;
// Finally, if the discount operation is set to s
// then, we set the shipping cost to the discount
// value. This could allow us to set free shipping,
// or just reduce shipping costs.
}
elseif( $voucher['operation'] == 's' )
{
$this->shipping_cost = $voucher['amount'];
$this->voucher_notice = 'Your orders shipping cost
has been reduced to £'
. $voucher['amount'];
return true;
}
}
else
{
$this->voucher_notice = 'Sorry, your order total is
not enough for your order to qualify for this
discount code';
return false;
}
}
else
{
$this->voucher_notice = 'Sorry, this was a limited
edition voucher code, there are no more instances
of that code left';
return false;
}
}
}
else
{
$this->voucher_notice = 'Sorry, the vocuher code you
entered is no longer active';
return false;
}
}
}
}
}
?>
it gives me the
Catchable fatal error: Argument 1 passed to coupon::Vouchers() must be an instance of Registry, array given, called in C:\Web Project\xampp\htdocs\shop\a.php on line 14 and defined in C:\Web Project\xampp\htdocs\shop\a.php on line 19
// this is my html form
<form method="post" action="a.php">
Enter The Coupon Code:<br />
<input id="cod" name="code[cod]" type="text" size="10" />
<br />
<input type="submit" name="submit" value="submit" />
</form>