I am not very familiar with PHP classes I just want to know is this the right way of using classes:
Code: Select all
class class1
{
...
.
.
}
class classb
{
obj = new class1;
}Thanks
Moderator: General Moderators
Code: Select all
class class1
{
...
.
.
}
class classb
{
obj = new class1;
}I bought a shopping cart know I am trying to customize it. In shopping cart they got one page there you can put your sutomize code. I got my code in Classes so when I try to put my code Then the shopping cart just display a blank page but if I put my code with out classes then it works fine.Jcart wrote:What are you trying to accomplish? There are many ways to "use" classes, I'm not sure if I can define a "right" way without knowing what you are trying to accomplish.
Code: Select all
class GBU_Order_custom extends GBU_Order {
var $class = 'GBU_Order_custom';
var $version = '6.6.0';
var $cerror;
var $KHXC_DB;
var $app;
// +------------------------------------------------------------------+
// | Constructor Function [KHXC]|
// +------------------------------------------------------------------+
function GBU_Order_custom () {
// +--
// | This is the class constructor function.
// +--
if ($this->debug) {$this->debugger("constructor: Accessed.");}
// +--
// | Determine the application we're running under and set the $app
// | class var to that app.
// +--
$this->app = $this->app_id(__FILE__);
if ($this->debug) {$this->debugger("constructor: Determined application id as '{$this->app}'");}
// +--
// | Quick object load: KHXC_DB
// +--
$this->KHXC_DB =& $this->quick_object('KHXC_DB','khxc','KHXC_DB_1');
if ($this->IsError($this->KHXC_DB)) {$this->cerror = $this->KHXC_DB; return;}
// +--
// | Return $this.
// +--
return;
} // End of function.
// +------------------------------------------------------------------+
// | Function: exec |
// +------------------------------------------------------------------+
function exec ($order = array()) {
// +--
// | This function contains custom code that can be processed when
// | an order is being processed. This class by default does nothing
// | except load the KHXC_DB_1 handle and check to be sure an order
// | array was passed and returns that array.
// +--
if (empty($order['order']['id'])) {
$message = "The exec() method in the {$this->class} class was
accessed without a valid order array.";
$result = $this->RaiseError($message);
if ($this->debug) {$this->debugger("exec: {$message}");}
return $result;
} // End of if statement.
// +--
// | DO COOL STUFF BELOW. MODIFY THE $order ARRAY AS NEEDED.
// +--
[b]Here I WANT TO PUT MY CODE [/b]
print "Counter".$cnt;
print "<br>";
print "Size of itme arrays".count($order['items']);
print "<br>";
print '<pre>'; print_r ($order); print '</pre>';
// +--
// | Log that we were here.
// +--
if ($this->debug) {$this->debugger("exec: Ran {$this->class} module for order '{$order['order']['id']}'.");}
// +--
// | Return the order array.
// +--
return $order;
} // End of function.
// +------------------------------------------------------------------+
// | End of Class [KHXC]|
// +------------------------------------------------------------------+
} // End of class.Code: Select all
<?php
class OrderForm
{
public $OrderNumber;
public $AccountNo;
public $BudgetHolder;
public $Store;
public $DeliveryName;
public $DeliveryOption;
public $DeliveryCharge;
public $Address;
public $Item;
public $CreditCardDetails;
public $OrderLevelDiscount;
}
class PlaceOrder
{
public $OrderForm;
}
$pOrder = new OrderForm;
$pOrder->OrderNumber = $order['order']['id'];
$pOrder->AccountNo = "WEB002";
$pOrder->BudgetHolder = "STAR01";
$pOrder->Store = "Star";
$pOrder->DeliveryName = $order['order']['fname'].$order['order']['lname'];
$pOrder->DeliveryOption = $order['items'][0]['shipmethod'];
$pOrder->DeliveryCharge = $order['order']['shiptotal'];
$pOrder->Address=array ( "AddressLine1" => $order['order']['addone'], "AddressLine2"=> $order['order']['addtwo'] , "Town" => $order['order']['city'], "County" => $order['order']['stateprov'], "PostCode" => $order['order']['postalcode'], "Country" => $order['order']['country']);
$cnt = 0;
for ($i = 0; $i < count($order['items']); $i++)
{
$cnt++;
$pOrder->Item[]=array ( "Sku" => $order['items'][$i]['itemnum'], "Description" => $order['items'][$i]['itemname'] , "Quantity" => $order['items'][$i]['itemquan'], "Price" => $order['items'][$i]['ordertotal'], "Discount" => 0, "VatAmount" => 0, "TotalAmountIncludingVat" => ($order['items'][$i]['itemquan']*$order['items'][$i]['ordertotal']));
print "Net Amount".($order['items'][$i]['itemquan']*$order['items'][$i]['ordertotal']);
}