A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1254 lines
52 KiB

  1. <?php
  2. require(__DATAGEN_CLASSES__ . '/OrderGen.class.php');
  3. /**
  4. * The Order class defined here represents the "order" table
  5. * in the database, and extends from the code generated abstract OrderGen
  6. * class, which contains all the basic CRUD-type functionality as well as
  7. * basic methods to handle relationships and index-based loading.
  8. *
  9. * This class overrides several generated methods and also provides several
  10. * other processing methods including sending emails on status change, setting
  11. * shipping/billing addresses, creating shipping labels, etc..
  12. *
  13. * $Id: Order.class.php 514 2009-03-19 15:43:15Z erikwinn $
  14. * @package Quinta
  15. * @subpackage Models
  16. *
  17. */
  18. class Order extends OrderGen
  19. {
  20. /**
  21. * An array of new order items for a newly created order.
  22. * Note: These OrderItems do not have the order_id set until SaveOrderItems is called and this
  23. * may be called only after an the Order has been saved.
  24. *
  25. * @var array aryNewOrderItems - an array of OrderItems
  26. */
  27. public $aryNewOrderItems;
  28. /**
  29. * An image to be used to print a shipping label
  30. *@var gdimage objShippingLabelImage
  31. */
  32. protected $objShippingLabelImage;
  33. /**
  34. * The weight and size members are for use during checkout - as yet they are temporary values
  35. * and not tracked in the database by order since they are in the Product information.
  36. *
  37. *@todo - Consider putting dimensions (weight, size, etc ) into the Order table as well
  38. * as they could also be (sorry) dimensional attributes ..
  39. *@var integer the total weight in pounds
  40. */
  41. protected $intTotalPounds = 0;
  42. /**
  43. *@var float the total weight in ounces
  44. */
  45. protected $fltTotalOunces = 0;
  46. /**
  47. * This refers to the X axis, translates to "width" for shipping, "width" in product
  48. * Why not "fltWidth"? Products may be eg. CAD designs, in which case "width" is ambiguous.
  49. * Basing this on screen coordinates is more precise.
  50. *@var float the total width in inches
  51. */
  52. protected $fltXAxisSize = 0.0;
  53. /**
  54. * This refers to the Y axis, translates to "length" for shipping, "height" in product
  55. *@var float the total height in inches
  56. */
  57. protected $fltYAxisSize = 0.0;
  58. /**
  59. * This refers to the Z axis, translates to "height" for shipping, "depth" in product
  60. *@var float the total height in inches
  61. */
  62. protected $fltZAxisSize = 0.0;
  63. /**
  64. *@var boolean blnIsInternational - true if the ShippingCountryId != shipping origin country.
  65. */
  66. protected $blnIsInternational;
  67. /**
  68. *@var boolean intShippingAddressId - the shipping address used to initialize the fields or null.
  69. */
  70. protected $intShippingAddressId;
  71. /**
  72. *@var boolean intBillingAddressId - the billing address used to initialize the fields or null.
  73. */
  74. protected $intBillingAddressId;
  75. /**
  76. * Default "to string" handler
  77. * Allows pages to _p()/echo()/print() this object, and to define the default
  78. * way this object would be outputted.
  79. *
  80. * Can also be called directly via $objOrder->__toString().
  81. *
  82. * @return string a nicely formatted string representation of this object
  83. */
  84. public function __toString()
  85. {
  86. return sprintf('Order# %s', $this->intId);
  87. }
  88. /**
  89. * This function sets the StatusId for the Order. Depending on the status it also
  90. * can send an email notification to the customer. The Order is also Saved with
  91. * the new status.
  92. */
  93. public function SetStatus($intStatusId)
  94. {
  95. switch($intStatusId)
  96. {
  97. case OrderStatusType::Pending:
  98. $this->SendPendingNotice();
  99. break;
  100. case OrderStatusType::Paid:
  101. $this->SendPaidNotice();
  102. break;
  103. case OrderStatusType::Shipped:
  104. if( 'PickUp' == $this->ShippingMethod->Carrier)
  105. $this->SendLocalPickupNotice();
  106. else
  107. $this->SendShippingNotice();
  108. break;
  109. case OrderStatusType::Cancelled:
  110. $this->SendCancellationNotice();
  111. break;
  112. case OrderStatusType::Problem:
  113. $this->SendProblemNotice();
  114. break;
  115. default:
  116. }
  117. $this->StatusId = $intStatusId;
  118. $this->Save(false, true);
  119. $this->Reload();
  120. }
  121. /**
  122. * Initializes the taxes by destination ..
  123. */
  124. public function InitTax()
  125. {
  126. $objTaxRate = TaxRate::LoadByZoneId($this->ShippingZoneId);
  127. if($objTaxRate)
  128. $this->fltTax = $this->ProductTotalCharged * $objTaxRate->Rate;
  129. }
  130. /**
  131. *Send a pending payment confirmation notification to the customer
  132. */
  133. public function SendPendingNotice()
  134. {
  135. $objPerson = Person::Load($this->Account->PersonId);
  136. $strText = Quinta::Translate('Dear') . ' ' . $objPerson->FullName . ",\n\n";
  137. $strText .= Quinta::Translate('Thank You for your order! Your payment is currently pending.') . "\n";
  138. $strText .= Quinta::Translate('You will receive a notification as soon as the payment has been confirmed.') . "\n\n";
  139. $strText .= $this->formatEmailOrderItemsInfo();
  140. $strText .= ' --------------------------------------------------' . "\n";
  141. $strText .= Quinta::Translate(' Thank You for placing an order with us!') . "\n";
  142. $strText .= Quinta::Translate(' If you have any questions please email support at ') ;
  143. $strText .= STORE_EMAIL_ADDRESS . "\n";
  144. $strText .= STORE_NAME . ' ' . Quinta::Translate('Customer Service') . "\n";
  145. $this->SendEmail($strText, STORE_NAME . ' Pending Payment Confirmation - Order #' . $this->Id );
  146. }
  147. /**
  148. *Send a payment received confirmation notification to the customer
  149. */
  150. public function SendPaidNotice()
  151. {
  152. $objPerson = Person::Load($this->Account->PersonId);
  153. $strText = Quinta::Translate('Dear') . ' ' . $objPerson->FullName . ",\n\n";
  154. $strText .= Quinta::Translate('Thank You for your order!') . "\n\n";
  155. $strText .= $this->formatEmailOrderItemsInfo();
  156. $strText .= ' --------------------------------------------------' . "\n";
  157. $strText .= $this->formatEmailOrderPaymentMethod();
  158. $strText .= ' --------------------------------------------------' . "\n";
  159. $strText .= $this->formatEmailOrderShippingMethod();
  160. $strText .= ' --------------------------------------------------' . "\n";
  161. $strText .= $this->formatEmailOrderShippingAddress();
  162. $strText .= ' --------------------------------------------------' . "\n";
  163. $strText .= $this->formatEmailOrderBillingAddress();
  164. $strText .= ' --------------------------------------------------' . "\n";
  165. $strText .= Quinta::Translate(' Thank You for placing an order with us!') . "\n";
  166. $strText .= Quinta::Translate(' You will recieve a shipping confirmation as soon as your order is shipped.') . "\n";
  167. $strText .= Quinta::Translate(' If you have any questions please email support at ') ;
  168. $strText .= STORE_EMAIL_ADDRESS . "\n Thank You, \n";
  169. $strText .= STORE_NAME . ' ' . Quinta::Translate('Customer Service') . "\n";
  170. $this->SendEmail($strText, STORE_NAME . ' Payment Confirmation - Order #' . $this->Id );
  171. }
  172. /**
  173. *Send a shipping confirmation notification to the customer
  174. */
  175. public function SendShippingNotice()
  176. {
  177. $objPerson = Person::Load($this->Account->PersonId);
  178. $strText = Quinta::Translate('Dear') . ' ' . $objPerson->FullName . ",\n\n";
  179. $strText .= Quinta::Translate('Your order has been shipped!') . "\n\n";
  180. $strText .= ' --------------------------------------------------' . "\n";
  181. $strText .= $this->formatEmailOrderShippingMethod();
  182. $strText .= ' --------------------------------------------------' . "\n";
  183. $strText .= $this->formatEmailOrderShippingAddress();
  184. $strText .= ' --------------------------------------------------' . "\n";
  185. $strText .= Quinta::Translate(' Thank You for placing an order with us!') . "\n";
  186. $strText .= Quinta::Translate(' If you have any questions please email support at ') ;
  187. $strText .= STORE_EMAIL_ADDRESS . "\n Thank You, \n";
  188. $strText .= STORE_NAME . ' ' . Quinta::Translate('Customer Service') . "\n";
  189. $this->SendEmail($strText, STORE_NAME . ' Shipping Confirmation - Order #' . $this->Id );
  190. }
  191. /**
  192. *Send a local pickup confirmation notification to the customer
  193. */
  194. public function SendLocalPickupNotice()
  195. {
  196. $objPerson = Person::Load($this->Account->PersonId);
  197. $strText = Quinta::Translate('Dear') . ' ' . $objPerson->FullName . ",\n\n";
  198. $strText .= Quinta::Translate(' Your order is ready!') . "\n\n";
  199. $strText .= Quinta::Translate(' You can pickup your order during regular business hours.') . "\n";
  200. $strText .= Quinta::Translate(' Our address is: ') . "\n\n";
  201. $strText .= STORE_ADDRESS1 . "\n";
  202. $strText .= STORE_ADDRESS2 . "\n";
  203. $strText .= STORE_CITY . "\n";
  204. $strText .= STORE_STATE . "\n";
  205. $strText .= STORE_POSTAL_CODE . "\n";
  206. $strText .= ' Phone: ' . STORE_PHONE . "\n";
  207. $strText .= ' --------------------------------------------------' . "\n";
  208. $strText .= Quinta::Translate(' Thank You for placing an order with us!') . "\n";
  209. $strText .= Quinta::Translate(' If you have any questions please email support at ') ;
  210. $strText .= STORE_EMAIL_ADDRESS . "\n Thank You, \n";
  211. $strText .= STORE_NAME . ' ' . Quinta::Translate('Customer Service') . "\n";
  212. $this->SendEmail($strText, STORE_NAME . ' Local Pickup Confirmation - Order #' . $this->Id );
  213. }
  214. /**
  215. *Send a cancelation confirmation notification to the customer
  216. *@todo - make cancellation email notice ..??
  217. */
  218. public function SendCancellationNotice()
  219. {
  220. }
  221. /**
  222. *Send a problem notification to the customer
  223. */
  224. public function SendProblemNotice()
  225. {
  226. $objPerson = Person::Load($this->Account->PersonId);
  227. $strText = Quinta::Translate('Dear') . ' ' . $objPerson->FullName . ",\n\n";
  228. $strText .= Quinta::Translate(' We have encountered a problem processing your order!') . "\n\n";
  229. $strText .= Quinta::Translate(' Thank You for placing an order with us - we have run into a '
  230. . 'problem that requires your attention.') . "\n";
  231. $strText .= Quinta::Translate(' Please reply to this or email support at ') ;
  232. $strText .= STORE_EMAIL_ADDRESS . " for further information with the Order number ("
  233. . $this->Id . ") in the Subject line of the email. \nThank You, \n";
  234. $strText .= STORE_NAME . ' ' . Quinta::Translate('Customer Service');
  235. $this->SendEmail($strText, STORE_NAME . ' Problem Alert - Order #' . $this->Id );
  236. }
  237. /**
  238. *Send an email message to the customer for this order.
  239. *@param string strEmailBody - the text body of the email
  240. *@param string strSubject - the subject line
  241. */
  242. public function SendEmail($strEmailBody, $strSubject)
  243. {
  244. $objPerson = Person::Load($this->Account->PersonId);
  245. $objEmail = new QEmailMessage();
  246. $objEmail->Subject = $strSubject;
  247. $objEmail->From = STORE_NAME . ' <' . STORE_EMAIL_ADDRESS . '>';
  248. $objEmail->To = $objPerson->FullName . ' <' . $objPerson->EmailAddress . '>';
  249. $objEmail->Body = $strEmailBody;
  250. QEmailServer::Send($objEmail);
  251. }
  252. /**
  253. *Print a shipping label for this order.
  254. */
  255. public function CreateShippingLabel()
  256. {
  257. if('PickUp' == $this->ShippingMethod->Carrier)
  258. return null;
  259. // $this->ShippingMethod->TestMode = true;
  260. $this->ShippingMethod->Init($this);
  261. $objImage = $this->objShippingMethod->GetShippingLabel();
  262. if($this->objShippingMethod->HasErrors)
  263. die($this->objShippingMethod->Errors);
  264. return $objImage;
  265. }
  266. /**
  267. * This function adds an OrderItem to the NewOrderItems array - subsequently it will be
  268. * associated with this order and saved with the other new items. The order_id is not
  269. * checked and may be null, it will be set on saving. If another OrderItem for the Product
  270. * already exists in the array, the quantity of the new item will be added to the existing item.
  271. *
  272. *@param OrderItem objNewOrderItem - a new order item for the new order.
  273. */
  274. public function AddNewOrderItem(OrderItem $objNewOrderItem)
  275. {
  276. if(is_null( $objNewOrderItem->ProductId))
  277. throw new QCallerException('Cannot add an OrderItem without a ProductId!');
  278. $blnItemExists = false;
  279. if($objNewOrderItem->Quantity > 0)
  280. {
  281. if(is_array($this->aryNewOrderItems))
  282. {
  283. foreach( $this->aryNewOrderItems as $objItem )
  284. {
  285. if( $objItem->ProductId == $objNewOrderItem->ProductId )
  286. {
  287. $objItem->Quantity += $objNewOrderItem->Quantity;
  288. $blnItemExists = true;
  289. break;
  290. }
  291. }
  292. }
  293. if( ! $blnItemExists )
  294. $this->aryNewOrderItems[] = $objNewOrderItem;
  295. }
  296. }
  297. /**
  298. * This function saves the array of new order items to the database making of them "real"
  299. * order items.
  300. */
  301. public function SaveNewOrderItems()
  302. {
  303. if( is_null($this->Id) )
  304. throw new QCallerException('Cannot save OrderItems for an unsaved Order!');
  305. if( is_array($this->aryNewOrderItems) && ! empty( $this->aryNewOrderItems ) )
  306. {
  307. foreach( $this->aryNewOrderItems as $objOrderItem )
  308. {
  309. $objOrderItem->OrderId = $this->Id;
  310. $objOrderItem->StatusId = OrderItemStatusType::Ordered;
  311. $objOrderItem->Save();
  312. }
  313. }
  314. }
  315. /**
  316. * This function returns the array of new order items. It is provided to avoid buggy PHP get magic
  317. * when returning arrays of objects.
  318. * Note that the OrderItems may not have order_id set as they are new items for a new order
  319. *@return array of OrderItems
  320. */
  321. public function GetNewOrderItemsArray()
  322. {
  323. if( is_array($this->aryNewOrderItems))
  324. return $this->aryNewOrderItems;
  325. return array();
  326. }
  327. /**
  328. * This fuction initializes the Shipping address fields
  329. *@param Address objAddress - address to use for initialization
  330. */
  331. public function SetShippingAddress(Address $objAddress)
  332. {
  333. $this->ShippingNamePrefix = $objAddress->Person->NamePrefix;
  334. $this->ShippingFirstName = $objAddress->Person->FirstName;
  335. $this->ShippingMiddleName = $objAddress->Person->MiddleName;
  336. $this->ShippingLastName = $objAddress->Person->LastName;
  337. $this->ShippingNameSuffix = $objAddress->Person->NameSuffix;
  338. $this->ShippingCompany = $objAddress->Person->CompanyName;
  339. $this->ShippingStreet1 = $objAddress->Street1;
  340. $this->ShippingStreet2 = $objAddress->Street2;
  341. $this->ShippingSuburb = $objAddress->Suburb;
  342. $this->ShippingCounty = $objAddress->County;
  343. $this->ShippingCity = $objAddress->City;
  344. $this->ShippingZoneId = $objAddress->ZoneId;
  345. $this->ShippingCountryId = $objAddress->CountryId;
  346. $this->ShippingPostalCode = $objAddress->PostalCode;
  347. $this->ShippingAddressId = $objAddress->Id;
  348. $intStoreCountryId = CountryType::GetId(STORE_COUNTRY);
  349. if($objAddress->CountryId != $intStoreCountryId)
  350. $this->blnIsInternational = true;
  351. else
  352. $this->blnIsInternational = false;
  353. }
  354. /**
  355. * This fuction initializes the Billing address fields
  356. *@param Address objAddress - address to use for initialization
  357. */
  358. public function SetBillingAddress(Address $objAddress)
  359. {
  360. $this->BillingNamePrefix = $objAddress->Person->NamePrefix;
  361. $this->BillingFirstName = $objAddress->Person->FirstName;
  362. $this->BillingMiddleName = $objAddress->Person->MiddleName;
  363. $this->BillingLastName = $objAddress->Person->LastName;
  364. $this->BillingNameSuffix = $objAddress->Person->NameSuffix;
  365. $this->BillingCompany = $objAddress->Person->CompanyName;
  366. $this->BillingStreet1 = $objAddress->Street1;
  367. $this->BillingStreet2 = $objAddress->Street2;
  368. $this->BillingSuburb = $objAddress->Suburb;
  369. $this->BillingCounty = $objAddress->County;
  370. $this->BillingCity = $objAddress->City;
  371. $this->BillingZoneId = $objAddress->ZoneId;
  372. $this->BillingCountryId = $objAddress->CountryId;
  373. $this->BillingPostalCode = $objAddress->PostalCode;
  374. $this->BillingAddressId = $objAddress->Id;
  375. }
  376. /**
  377. * This fuction returns the Shipping address fields as an Address object - it attempts
  378. * to return an existing address by searching for a match on fields, if that fails it
  379. * calls createShippingAddress and returns a new Address object initilized with the
  380. * values in the order.
  381. *@return Address objAddress - address containing Shipping address fields
  382. */
  383. public function GetShippingAddress()
  384. {
  385. if($this->AccountId)
  386. $intAccountId = $this->AccountId;
  387. elseif(IndexPage::$objAccount)
  388. $intAccountId = IndexPage::$objAccount->Id;
  389. else
  390. $intAccountId = null;
  391. $aryPersonConditions = array();
  392. if($intAccountId)
  393. $aryPersonConditions[] = QQ::Equal(QQN::Person()->Account->Id, $intAccountId);
  394. $aryPersonConditions[] = QQ::Equal(QQN::Person()->FirstName, $this->ShippingFirstName);
  395. $aryPersonConditions[] = QQ::Equal(QQN::Person()->LastName, $this->ShippingLastName);
  396. $objPerson = Person::QuerySingle( QQ::AndCondition($aryPersonConditions) );
  397. //for imported orders the person may not yet exist so ..
  398. if(!$objPerson instanceof Person)
  399. {
  400. $objPerson = new Person();
  401. $objPerson->FirstName = $this->ShippingFirstName;
  402. $objPerson->LastName = $this->ShippingLastName;
  403. $objPerson->EmailAddress = $this->Account->Person->EmailAddress;
  404. $objPerson->OwnerPersonId = $this->Account->Person->Id;
  405. $objPerson->IsVirtual = true;
  406. $objPerson->Save();
  407. }
  408. $aryConditions = array();
  409. // $aryConditions[] = QQ::Equal(QQN::Address()->PersonId, $this->Account->PersonId );
  410. $aryConditions[] = QQ::Equal(QQN::Address()->PersonId, $objPerson->Id );
  411. if(!empty($this->ShippingStreet1))
  412. $aryConditions[] = QQ::Equal(QQN::Address()->Street1, $this->ShippingStreet1);
  413. if(!empty($this->ShippingStreet2))
  414. $aryConditions[] = QQ::Equal(QQN::Address()->Street2, $this->ShippingStreet2);
  415. if(!empty($this->ShippingSuburb))
  416. $aryConditions[] = QQ::Equal(QQN::Address()->Suburb, $this->ShippingSuburb);
  417. $aryConditions[] = QQ::Equal(QQN::Address()->City, $this->ShippingCity);
  418. $aryConditions[] = QQ::Equal(QQN::Address()->ZoneId, $this->ShippingZoneId);
  419. $aryConditions[] = QQ::Equal(QQN::Address()->CountryId, $this->ShippingCountryId);
  420. $objAddress = Address::QuerySingle( QQ::AndCondition( $aryConditions ));
  421. if($objAddress instanceof Address)
  422. return $objAddress;
  423. return $this->createShippingAddress();
  424. }
  425. /**
  426. * This fuction returns the Billing address fields as an Address object - it attempts
  427. * to return an existing address by searching for a match on fields, if that fails it
  428. * calls createBillingAddress and returns a new Address object initilized with the
  429. * values in the order.
  430. *@return Address objAddress - address containing Billing address fields
  431. */
  432. public function GetBillingAddress()
  433. {
  434. if($this->AccountId)
  435. $intAccountId = $this->AccountId;
  436. elseif(IndexPage::$objAccount)
  437. $intAccountId = IndexPage::$objAccount->Id;
  438. else
  439. $intAccountId = null;
  440. $aryPersonConditions = array();
  441. if($intAccountId)
  442. $aryPersonConditions[] = QQ::Equal(QQN::Person()->Account->Id, $intAccountId);
  443. $aryPersonConditions[] = QQ::Equal(QQN::Person()->FirstName, $this->ShippingFirstName);
  444. $aryPersonConditions[] = QQ::Equal(QQN::Person()->LastName, $this->ShippingLastName);
  445. $objPerson = Person::QuerySingle( QQ::AndCondition($aryPersonConditions) );
  446. //for imported orders the person may not yet exist so ..
  447. if(!$objPerson instanceof Person)
  448. {
  449. $objPerson = new Person();
  450. $objPerson->FirstName = $this->ShippingFirstName;
  451. $objPerson->LastName = $this->ShippingLastName;
  452. $objPerson->EmailAddress = $this->Account->Person->EmailAddress;
  453. $objPerson->OwnerPersonId = $this->Account->Person->Id;
  454. $objPerson->IsVirtual = true;
  455. $objPerson->Save();
  456. }
  457. $aryConditions = array();
  458. // $aryConditions[] = QQ::Equal(QQN::Address()->PersonId, $this->Account->PersonId );
  459. $aryConditions[] = QQ::Equal(QQN::Address()->PersonId, $objPerson->Id );
  460. if(!empty($this->BillingStreet1))
  461. $aryConditions[] = QQ::Equal(QQN::Address()->Street1, $this->BillingStreet1);
  462. if(!empty($this->BillingStreet2))
  463. $aryConditions[] = QQ::Equal(QQN::Address()->Street2, $this->BillingStreet2);
  464. if(!empty($this->BillingSuburb))
  465. $aryConditions[] = QQ::Equal(QQN::Address()->Suburb, $this->BillingSuburb);
  466. $aryConditions[] = QQ::Equal(QQN::Address()->City, $this->BillingCity);
  467. $aryConditions[] = QQ::Equal(QQN::Address()->ZoneId, $this->BillingZoneId);
  468. $aryConditions[] = QQ::Equal(QQN::Address()->CountryId, $this->BillingCountryId);
  469. $objAddress = Address::QuerySingle( QQ::AndCondition( $aryConditions ));
  470. if($objAddress instanceof Address)
  471. return $objAddress;
  472. return $this->createBillingAddress();
  473. }
  474. /**
  475. * Insert this order, including the id, and timestamps - Save() autoincrements Id, this function
  476. * is for overriding that behaviour (eg. for imports).
  477. * @todo - merge with Save()?
  478. */
  479. public function Insert()
  480. {
  481. $objDatabase = Order::GetDatabase();
  482. $strQuery = 'INSERT INTO `order` (
  483. `id`,
  484. `account_id`,
  485. `creation_date`,
  486. `last_modification_date`,
  487. `completion_date`,
  488. `shipping_cost`,
  489. `product_total_cost`,
  490. `shipping_charged`,
  491. `handling_charged`,
  492. `tax`,
  493. `product_total_charged`,
  494. `shipping_name_prefix`,
  495. `shipping_first_name`,
  496. `shipping_middle_name`,
  497. `shipping_last_name`,
  498. `shipping_name_suffix`,
  499. `shipping_company`,
  500. `shipping_street1`,
  501. `shipping_street2`,
  502. `shipping_suburb`,
  503. `shipping_county`,
  504. `shipping_city`,
  505. `shipping_zone_id`,
  506. `shipping_country_id`,
  507. `shipping_postal_code`,
  508. `billing_name_prefix`,
  509. `billing_first_name`,
  510. `billing_middle_name`,
  511. `billing_last_name`,
  512. `billing_name_suffix`,
  513. `billing_company`,
  514. `billing_street1`,
  515. `billing_street2`,
  516. `billing_suburb`,
  517. `billing_county`,
  518. `billing_city`,
  519. `billing_zone_id`,
  520. `billing_country_id`,
  521. `billing_postal_code`,
  522. `notes`,
  523. `shipping_method_id`,
  524. `payment_method_id`,
  525. `status_id`,
  526. `type_id`
  527. ) VALUES (
  528. ' . $objDatabase->SqlVariable($this->intId) . ',
  529. ' . $objDatabase->SqlVariable($this->intAccountId) . ',
  530. ' . $objDatabase->SqlVariable($this->strCreationDate) . ',
  531. ' . $objDatabase->SqlVariable($this->strLastModification) . ',
  532. ' . $objDatabase->SqlVariable($this->dttCompletionDate) . ',
  533. ' . $objDatabase->SqlVariable($this->fltShippingCost) . ',
  534. ' . $objDatabase->SqlVariable($this->fltProductTotalCost) . ',
  535. ' . $objDatabase->SqlVariable($this->fltShippingCharged) . ',
  536. ' . $objDatabase->SqlVariable($this->fltHandlingCharged) . ',
  537. ' . $objDatabase->SqlVariable($this->fltTax) . ',
  538. ' . $objDatabase->SqlVariable($this->fltProductTotalCharged) . ',
  539. ' . $objDatabase->SqlVariable($this->strShippingNamePrefix) . ',
  540. ' . $objDatabase->SqlVariable($this->strShippingFirstName) . ',
  541. ' . $objDatabase->SqlVariable($this->strShippingMiddleName) . ',
  542. ' . $objDatabase->SqlVariable($this->strShippingLastName) . ',
  543. ' . $objDatabase->SqlVariable($this->strShippingNameSuffix) . ',
  544. ' . $objDatabase->SqlVariable($this->strShippingCompany) . ',
  545. ' . $objDatabase->SqlVariable($this->strShippingStreet1) . ',
  546. ' . $objDatabase->SqlVariable($this->strShippingStreet2) . ',
  547. ' . $objDatabase->SqlVariable($this->strShippingSuburb) . ',
  548. ' . $objDatabase->SqlVariable($this->strShippingCounty) . ',
  549. ' . $objDatabase->SqlVariable($this->strShippingCity) . ',
  550. ' . $objDatabase->SqlVariable($this->intShippingZoneId) . ',
  551. ' . $objDatabase->SqlVariable($this->intShippingCountryId) . ',
  552. ' . $objDatabase->SqlVariable($this->strShippingPostalCode) . ',
  553. ' . $objDatabase->SqlVariable($this->strBillingNamePrefix) . ',
  554. ' . $objDatabase->SqlVariable($this->strBillingFirstName) . ',
  555. ' . $objDatabase->SqlVariable($this->strBillingMiddleName) . ',
  556. ' . $objDatabase->SqlVariable($this->strBillingLastName) . ',
  557. ' . $objDatabase->SqlVariable($this->strBillingNameSuffix) . ',
  558. ' . $objDatabase->SqlVariable($this->strBillingCompany) . ',
  559. ' . $objDatabase->SqlVariable($this->strBillingStreet1) . ',
  560. ' . $objDatabase->SqlVariable($this->strBillingStreet2) . ',
  561. ' . $objDatabase->SqlVariable($this->strBillingSuburb) . ',
  562. ' . $objDatabase->SqlVariable($this->strBillingCounty) . ',
  563. ' . $objDatabase->SqlVariable($this->strBillingCity) . ',
  564. ' . $objDatabase->SqlVariable($this->intBillingZoneId) . ',
  565. ' . $objDatabase->SqlVariable($this->intBillingCountryId) . ',
  566. ' . $objDatabase->SqlVariable($this->strBillingPostalCode) . ',
  567. ' . $objDatabase->SqlVariable($this->strNotes) . ',
  568. ' . $objDatabase->SqlVariable($this->intShippingMethodId) . ',
  569. ' . $objDatabase->SqlVariable($this->intPaymentMethodId) . ',
  570. ' . $objDatabase->SqlVariable($this->intStatusId) . ',
  571. ' . $objDatabase->SqlVariable($this->intTypeId) . ' )';
  572. try{
  573. $objDatabase->NonQuery($strQuery);
  574. } catch (QCallerException $objExc) {
  575. $objExc->IncrementOffset();
  576. throw $objExc;
  577. }
  578. $this->__blnRestored = true;
  579. }
  580. /**
  581. * Save this Order - overrides the generated class implementation to be able to update last_modification_date
  582. *
  583. * @param bool $blnForceInsert
  584. * @param bool $blnForceUpdate
  585. * @return integer - the Id of this Order
  586. */
  587. public function Save($blnForceInsert = false, $blnForceUpdate = false)
  588. {
  589. // Get the Database Object for this Class
  590. $objDatabase = Order::GetDatabase();
  591. if(! $this->dttCompletionDate instanceof QDateTime)
  592. $this->dttCompletionDate = new QDateTime();
  593. $mixToReturn = null;
  594. $strLastModification = date("Y-m-d H:i:s");
  595. try {
  596. if ((!$this->__blnRestored) || ($blnForceInsert))
  597. {
  598. // Perform an INSERT query
  599. $strQuery = 'INSERT INTO `order` (
  600. `account_id`,
  601. `last_modification_date`,
  602. `completion_date`,
  603. `shipping_cost`,
  604. `product_total_cost`,
  605. `shipping_charged`,
  606. `handling_charged`,
  607. `tax`,
  608. `product_total_charged`,
  609. `shipping_name_prefix`,
  610. `shipping_first_name`,
  611. `shipping_middle_name`,
  612. `shipping_last_name`,
  613. `shipping_name_suffix`,
  614. `shipping_company`,
  615. `shipping_street1`,
  616. `shipping_street2`,
  617. `shipping_suburb`,
  618. `shipping_county`,
  619. `shipping_city`,
  620. `shipping_zone_id`,
  621. `shipping_country_id`,
  622. `shipping_postal_code`,
  623. `billing_name_prefix`,
  624. `billing_first_name`,
  625. `billing_middle_name`,
  626. `billing_last_name`,
  627. `billing_name_suffix`,
  628. `billing_company`,
  629. `billing_street1`,
  630. `billing_street2`,
  631. `billing_suburb`,
  632. `billing_county`,
  633. `billing_city`,
  634. `billing_zone_id`,
  635. `billing_country_id`,
  636. `billing_postal_code`,
  637. `notes`,
  638. `shipping_method_id`,
  639. `payment_method_id`,
  640. `status_id`,
  641. `type_id`
  642. ) VALUES (
  643. ' . $objDatabase->SqlVariable($this->intAccountId) . ',
  644. ' . $objDatabase->SqlVariable($strLastModification) . ',
  645. ' . $objDatabase->SqlVariable($this->dttCompletionDate) . ',
  646. ' . $objDatabase->SqlVariable($this->fltShippingCost) . ',
  647. ' . $objDatabase->SqlVariable($this->fltProductTotalCost) . ',
  648. ' . $objDatabase->SqlVariable($this->fltShippingCharged) . ',
  649. ' . $objDatabase->SqlVariable($this->fltHandlingCharged) . ',
  650. ' . $objDatabase->SqlVariable($this->fltTax) . ',
  651. ' . $objDatabase->SqlVariable($this->fltProductTotalCharged) . ',
  652. ' . $objDatabase->SqlVariable($this->strShippingNamePrefix) . ',
  653. ' . $objDatabase->SqlVariable($this->strShippingFirstName) . ',
  654. ' . $objDatabase->SqlVariable($this->strShippingMiddleName) . ',
  655. ' . $objDatabase->SqlVariable($this->strShippingLastName) . ',
  656. ' . $objDatabase->SqlVariable($this->strShippingNameSuffix) . ',
  657. ' . $objDatabase->SqlVariable($this->strShippingCompany) . ',
  658. ' . $objDatabase->SqlVariable($this->strShippingStreet1) . ',
  659. ' . $objDatabase->SqlVariable($this->strShippingStreet2) . ',
  660. ' . $objDatabase->SqlVariable($this->strShippingSuburb) . ',
  661. ' . $objDatabase->SqlVariable($this->strShippingCounty) . ',
  662. ' . $objDatabase->SqlVariable($this->strShippingCity) . ',
  663. ' . $objDatabase->SqlVariable($this->intShippingZoneId) . ',
  664. ' . $objDatabase->SqlVariable($this->intShippingCountryId) . ',
  665. ' . $objDatabase->SqlVariable($this->strShippingPostalCode) . ',
  666. ' . $objDatabase->SqlVariable($this->strBillingNamePrefix) . ',
  667. ' . $objDatabase->SqlVariable($this->strBillingFirstName) . ',
  668. ' . $objDatabase->SqlVariable($this->strBillingMiddleName) . ',
  669. ' . $objDatabase->SqlVariable($this->strBillingLastName) . ',
  670. ' . $objDatabase->SqlVariable($this->strBillingNameSuffix) . ',
  671. ' . $objDatabase->SqlVariable($this->strBillingCompany) . ',
  672. ' . $objDatabase->SqlVariable($this->strBillingStreet1) . ',
  673. ' . $objDatabase->SqlVariable($this->strBillingStreet2) . ',
  674. ' . $objDatabase->SqlVariable($this->strBillingSuburb) . ',
  675. ' . $objDatabase->SqlVariable($this->strBillingCounty) . ',
  676. ' . $objDatabase->SqlVariable($this->strBillingCity) . ',
  677. ' . $objDatabase->SqlVariable($this->intBillingZoneId) . ',
  678. ' . $objDatabase->SqlVariable($this->intBillingCountryId) . ',
  679. ' . $objDatabase->SqlVariable($this->strBillingPostalCode) . ',
  680. ' . $objDatabase->SqlVariable($this->strNotes) . ',
  681. ' . $objDatabase->SqlVariable($this->intShippingMethodId) . ',
  682. ' . $objDatabase->SqlVariable($this->intPaymentMethodId) . ',
  683. ' . $objDatabase->SqlVariable($this->intStatusId) . ',
  684. ' . $objDatabase->SqlVariable($this->intTypeId) . '
  685. )
  686. ';
  687. $objDatabase->NonQuery($strQuery);
  688. // Update Identity column and return its value
  689. $mixToReturn = $this->intId = $objDatabase->InsertId('order', 'id');
  690. } else {
  691. // Perform an UPDATE query
  692. if (!$blnForceUpdate)
  693. {
  694. // Perform the Optimistic Locking check
  695. $objResult = $objDatabase->Query('
  696. SELECT
  697. `last_modification_date`
  698. FROM
  699. `order`
  700. WHERE
  701. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  702. ');
  703. $objRow = $objResult->FetchArray();
  704. if ($objRow[0] != $this->strLastModification)
  705. throw new QOptimisticLockingException('Order');
  706. }
  707. // Perform the UPDATE query
  708. $objDatabase->NonQuery('
  709. UPDATE
  710. `order`
  711. SET
  712. `account_id` = ' . $objDatabase->SqlVariable($this->intAccountId) . ',
  713. `last_modification_date` = ' . $objDatabase->SqlVariable($strLastModification) . ',
  714. `completion_date` = ' . $objDatabase->SqlVariable($this->dttCompletionDate) . ',
  715. `shipping_cost` = ' . $objDatabase->SqlVariable($this->fltShippingCost) . ',
  716. `product_total_cost` = ' . $objDatabase->SqlVariable($this->fltProductTotalCost) . ',
  717. `shipping_charged` = ' . $objDatabase->SqlVariable($this->fltShippingCharged) . ',
  718. `handling_charged` = ' . $objDatabase->SqlVariable($this->fltHandlingCharged) . ',
  719. `tax` = ' . $objDatabase->SqlVariable($this->fltTax) . ',
  720. `product_total_charged` = ' . $objDatabase->SqlVariable($this->fltProductTotalCharged) . ',
  721. `shipping_name_prefix` = ' . $objDatabase->SqlVariable($this->strShippingNamePrefix) . ',
  722. `shipping_first_name` = ' . $objDatabase->SqlVariable($this->strShippingFirstName) . ',
  723. `shipping_middle_name` = ' . $objDatabase->SqlVariable($this->strShippingMiddleName) . ',
  724. `shipping_last_name` = ' . $objDatabase->SqlVariable($this->strShippingLastName) . ',
  725. `shipping_name_suffix` = ' . $objDatabase->SqlVariable($this->strShippingNameSuffix) . ',
  726. `shipping_company` = ' . $objDatabase->SqlVariable($this->strShippingCompany) . ',
  727. `shipping_street1` = ' . $objDatabase->SqlVariable($this->strShippingStreet1) . ',
  728. `shipping_street2` = ' . $objDatabase->SqlVariable($this->strShippingStreet2) . ',
  729. `shipping_suburb` = ' . $objDatabase->SqlVariable($this->strShippingSuburb) . ',
  730. `shipping_county` = ' . $objDatabase->SqlVariable($this->strShippingCounty) . ',
  731. `shipping_city` = ' . $objDatabase->SqlVariable($this->strShippingCity) . ',
  732. `shipping_zone_id` = ' . $objDatabase->SqlVariable($this->intShippingZoneId) . ',
  733. `shipping_country_id` = ' . $objDatabase->SqlVariable($this->intShippingCountryId) . ',
  734. `shipping_postal_code` = ' . $objDatabase->SqlVariable($this->strShippingPostalCode) . ',
  735. `billing_name_prefix` = ' . $objDatabase->SqlVariable($this->strBillingNamePrefix) . ',
  736. `billing_first_name` = ' . $objDatabase->SqlVariable($this->strBillingFirstName) . ',
  737. `billing_middle_name` = ' . $objDatabase->SqlVariable($this->strBillingMiddleName) . ',
  738. `billing_last_name` = ' . $objDatabase->SqlVariable($this->strBillingLastName) . ',
  739. `billing_name_suffix` = ' . $objDatabase->SqlVariable($this->strBillingNameSuffix) . ',
  740. `billing_company` = ' . $objDatabase->SqlVariable($this->strBillingCompany) . ',
  741. `billing_street1` = ' . $objDatabase->SqlVariable($this->strBillingStreet1) . ',
  742. `billing_street2` = ' . $objDatabase->SqlVariable($this->strBillingStreet2) . ',
  743. `billing_suburb` = ' . $objDatabase->SqlVariable($this->strBillingSuburb) . ',
  744. `billing_county` = ' . $objDatabase->SqlVariable($this->strBillingCounty) . ',
  745. `billing_city` = ' . $objDatabase->SqlVariable($this->strBillingCity) . ',
  746. `billing_zone_id` = ' . $objDatabase->SqlVariable($this->intBillingZoneId) . ',
  747. `billing_country_id` = ' . $objDatabase->SqlVariable($this->intBillingCountryId) . ',
  748. `billing_postal_code` = ' . $objDatabase->SqlVariable($this->strBillingPostalCode) . ',
  749. `notes` = ' . $objDatabase->SqlVariable($this->strNotes) . ',
  750. `shipping_method_id` = ' . $objDatabase->SqlVariable($this->intShippingMethodId) . ',
  751. `payment_method_id` = ' . $objDatabase->SqlVariable($this->intPaymentMethodId) . ',
  752. `status_id` = ' . $objDatabase->SqlVariable($this->intStatusId) . ',
  753. `type_id` = ' . $objDatabase->SqlVariable($this->intTypeId) . '
  754. WHERE
  755. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  756. ');
  757. }
  758. } catch (QCallerException $objExc) {
  759. $objExc->IncrementOffset();
  760. throw $objExc;
  761. }
  762. $this->__blnRestored = true;
  763. // Update Local Timestamp
  764. $objResult = $objDatabase->Query('
  765. SELECT
  766. `creation_date`
  767. FROM
  768. `order`
  769. WHERE
  770. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  771. ');
  772. $objRow = $objResult->FetchArray();
  773. $this->strCreationDate = $objRow[0];
  774. $this->strLastModification = $strLastModification;
  775. return $mixToReturn;
  776. }
  777. /**
  778. * Utility function to format the list of Order information in a customer email notification
  779. * @return string - a string containing the formatted information
  780. */
  781. protected function formatEmailOrderItemsInfo()
  782. {
  783. $strToReturn = Quinta::Translate(' The following is your order information') . ":\n\n";
  784. $strToReturn .= ' --------------------------------------------------' . "\n";
  785. $strToReturn .= Quinta::Translate('Order Number') . ': ' . $this->Id . "\n";
  786. $strToReturn .= Quinta::Translate('Detailed Invoice') . ': http://' . Quinta::$ServerName . __QUINTA_SUBDIRECTORY__
  787. . '/index.php/AccountHome/Order/' . $this->Id . "\n";
  788. $strToReturn .= Quinta::Translate('Date Ordered') . ': ' . $this->CreationDate . "\n" ;
  789. $strToReturn .= ' --------------------------------------------------' . "\n";
  790. $strToReturn .= Quinta::Translate('Products on Order') . ":\n\n" ;
  791. foreach( OrderItem::LoadArrayByOrderId($this->Id) as $objOrderItem )
  792. {
  793. $objProduct = Product::Load($objOrderItem->ProductId);
  794. $strToReturn .= $objOrderItem->Quantity . ' ' . $objProduct->Name . ': ' . $objProduct->Model
  795. . ' [' . number_format($objProduct->Height, 2 ) . '" x ' . number_format($objProduct->Width, 2) . '" ]'
  796. . ' at ' . money_format('%n', $objProduct->RetailPrice )
  797. . '/ea. = ' . money_format('%n', $objProduct->RetailPrice * $objOrderItem->Quantity ) . "\n";
  798. }
  799. $strToReturn .= "\n" . Quinta::Translate('Subtotal') . ': ' . money_format('%n', $this->ProductTotalCharged);
  800. $strToReturn .= "\n" . Quinta::Translate('Shipping') . ': ' . money_format('%n', $this->ShippingCharged);
  801. $strToReturn .= "\n" . Quinta::Translate('Handling') . ': ' . money_format('%n', $this->HandlingCharged);
  802. $strToReturn .= "\n" . Quinta::Translate('Total') . ': ' . money_format('%n', ($this->HandlingCharged
  803. + $this->ShippingCharged
  804. + $this->ProductTotalCharged) ) . "\n";
  805. return $strToReturn;
  806. }
  807. /**
  808. * Utility function to format the Payment method in a customer email notification
  809. * @return string - a string containing the formatted information
  810. */
  811. protected function formatEmailOrderPaymentMethod()
  812. {
  813. $objPaymentMethod = PaymentMethod::Load($this->PaymentMethodId);
  814. $strToReturn = Quinta::Translate('Payment Method') . ": \n";
  815. $strToReturn .= PaymentType::ToString($objPaymentMethod->PaymentTypeId) . ' via ' . $objPaymentMethod->ServiceProvider . "\n";
  816. return $strToReturn;
  817. }
  818. /**
  819. * Utility function to format the Shipping method in a customer email notification
  820. * @return string - a string containing the formatted information
  821. */
  822. protected function formatEmailOrderShippingMethod()
  823. {
  824. $objShippingMethod = ShippingMethod::Load($this->ShippingMethodId);
  825. $strToReturn = Quinta::Translate('Shipping Method') . ": \n";
  826. $strToReturn .= $objShippingMethod->Title . ' ' . $objShippingMethod->ServiceType . "\n";
  827. $strToReturn .= Quinta::Translate('Estimated Transit time: ') . $objShippingMethod->TransitTime . "\n";
  828. return $strToReturn;
  829. }
  830. /**
  831. * Utility function to format the Shipping Address information in a customer email notification
  832. * @return string - a string containing the formatted information
  833. */
  834. protected function formatEmailOrderShippingAddress()
  835. {
  836. $strToReturn = Quinta::Translate('Delivery Address:') . "\n\n";
  837. if('' != $this->ShippingCompany )
  838. $strToReturn .= $this->ShippingCompany . "\n";
  839. if('' != $this->ShippingNamePrefix )
  840. $strToReturn .= $this->ShippingNamePrefix . ' ';
  841. $strToReturn .= $this->ShippingFirstName . ' ';
  842. if('' != $this->ShippingMiddleName )
  843. $strToReturn .= $this->ShippingMiddleName . ' ';
  844. $strToReturn .= $this->ShippingLastName. ' ';
  845. if('' != $this->ShippingNameSuffix )
  846. $strToReturn .= $this->ShippingNameSuffix . ' ';
  847. $strToReturn .= "\n" . $this->ShippingStreet1 . "\n";
  848. if('' != $this->ShippingStreet2)
  849. $strToReturn .= $this->ShippingStreet2 . "\n";
  850. if('' != $this->ShippingSuburb)
  851. $strToReturn .= $this->ShippingSuburb . "\n";
  852. if('' != $this->ShippingCounty)
  853. $strToReturn .= $this->ShippingCounty . "\n";
  854. $strToReturn .= $this->ShippingCity . "\n";
  855. $strToReturn .= ZoneType::ToString($this->ShippingZoneId) . "\n";
  856. $strToReturn .= $this->ShippingPostalCode . "\n";
  857. $strToReturn .= CountryType::ToString($this->ShippingCountryId) . "\n";
  858. return $strToReturn;
  859. }
  860. /**
  861. * Utility function to format the Billing Address information in a customer email notification
  862. * @return string - a string containing the formatted information
  863. */
  864. protected function formatEmailOrderBillingAddress()
  865. {
  866. $strToReturn = Quinta::Translate('Billing Address:') . "\n\n";
  867. if('' != $this->BillingCompany )
  868. $strToReturn .= $this->BillingCompany . "\n";
  869. if('' != $this->BillingNamePrefix )
  870. $strToReturn .= $this->BillingNamePrefix . ' ';
  871. $strToReturn .= $this->BillingFirstName . ' ';
  872. if('' != $this->BillingMiddleName )
  873. $strToReturn .= $this->BillingMiddleName . ' ';
  874. $strToReturn .= $this->BillingLastName. ' ';
  875. if('' != $this->BillingNameSuffix )
  876. $strToReturn .= $this->BillingNameSuffix . ' ';
  877. $strToReturn .= "\n" . $this->BillingStreet1 . "\n";
  878. if('' != $this->BillingStreet2)
  879. $strToReturn .= $this->BillingStreet2 . "\n";
  880. if('' != $this->BillingSuburb)
  881. $strToReturn .= $this->BillingSuburb . "\n";
  882. if('' != $this->BillingCounty)
  883. $strToReturn .= $this->BillingCounty . "\n";
  884. $strToReturn .= $this->BillingCity . "\n";
  885. $strToReturn .= ZoneType::ToString($this->BillingZoneId) . "\n";
  886. $strToReturn .= $this->BillingPostalCode . "\n";
  887. $strToReturn .= CountryType::ToString($this->BillingCountryId) . "\n";
  888. return $strToReturn;
  889. }
  890. /**
  891. * This fuction returns the Shipping address fields as an Address object
  892. *@return Address objAddress - address containing Shipping address fields
  893. */
  894. protected function createShippingAddress()
  895. {
  896. $objShippingAddress = new Address();
  897. $objShippingAddress->PersonId = $this->Account->PersonId;
  898. $objShippingAddress->Street1 = $this->ShippingStreet1;
  899. $objShippingAddress->Street2 = $this->ShippingStreet2;
  900. $objShippingAddress->Suburb = $this->ShippingSuburb;
  901. $objShippingAddress->County = $this->ShippingCounty;
  902. $objShippingAddress->City = $this->ShippingCity;
  903. $objShippingAddress->ZoneId = $this->ShippingZoneId;
  904. $objShippingAddress->CountryId = $this->ShippingCountryId;
  905. $objShippingAddress->PostalCode = $this->ShippingPostalCode;
  906. $objShippingAddress->TypeId = AddressType::Shipping;
  907. $objShippingAddress->Save();
  908. return $objShippingAddress;
  909. }
  910. /**
  911. * This fuction returns the Billing address fields as an Address object
  912. *@return Address objAddress - address containing Billing address fields
  913. */
  914. protected function createBillingAddress()
  915. {
  916. $objBillingAddress = new Address();
  917. $objBillingAddress->PersonId = $this->Account->PersonId;
  918. $objBillingAddress->Street1 = $this->BillingStreet1;
  919. $objBillingAddress->Street2 = $this->BillingStreet2;
  920. $objBillingAddress->Suburb = $this->BillingSuburb;
  921. $objBillingAddress->County = $this->BillingCounty;
  922. $objBillingAddress->City = $this->BillingCity;
  923. $objBillingAddress->ZoneId = $this->BillingZoneId;
  924. $objBillingAddress->CountryId = $this->BillingCountryId;
  925. $objBillingAddress->PostalCode = $this->BillingPostalCode;
  926. $objBillingAddress->TypeId = AddressType::Billing;
  927. $objBillingAddress->Save();
  928. return $objBillingAddress;
  929. }
  930. public function __get($strName)
  931. {
  932. switch ($strName) {
  933. case 'FullBillingName':
  934. $strToReturn = '';
  935. if('' != $this->BillingNamePrefix )
  936. $strToReturn .= $this->BillingNamePrefix . ' ';
  937. $strToReturn .= $this->BillingFirstName . ' ';
  938. if('' != $this->BillingMiddleName )
  939. $strToReturn .= $this->BillingMiddleName . ' ';
  940. $strToReturn .= $this->BillingLastName. ' ';
  941. if('' != $this->BillingNameSuffix )
  942. $strToReturn .= $this->BillingNameSuffix . ' ';
  943. return $strToReturn;
  944. case 'FullShippingName':
  945. $strToReturn = '';
  946. if('' != $this->ShippingNamePrefix )
  947. $strToReturn .= $this->ShippingNamePrefix . ' ';
  948. $strToReturn .= $this->ShippingFirstName . ' ';
  949. if('' != $this->ShippingMiddleName )
  950. $strToReturn .= $this->ShippingMiddleName . ' ';
  951. $strToReturn .= $this->ShippingLastName. ' ';
  952. if('' != $this->ShippingNameSuffix )
  953. $strToReturn .= $this->ShippingNameSuffix . ' ';
  954. return $strToReturn;
  955. case 'ShippingCountry':
  956. return ($this->ShippingCountryId) ? CountryType::$NameArray[$this->ShippingCountryId] : null;
  957. case 'BillingCountry':
  958. return ($this->BillingCountryId) ? CountryType::$NameArray[$this->BillingCountryId] : null;
  959. case 'ShippingZone':
  960. case 'ShippingState':
  961. return ($this->ShippingZoneId) ? ZoneType::$NameArray[$this->ShippingZoneId] : null;
  962. case 'BillingZone':
  963. case 'BillingState':
  964. return ($this->BillingZoneId) ? ZoneType::$NameArray[$this->BillingZoneId] : null;
  965. case 'TotalPounds':
  966. return $this->intTotalPounds;
  967. case 'TotalOunces':
  968. return $this->fltTotalOunces;
  969. case 'XAxisSize':
  970. return $this->fltXAxisSize;
  971. case 'YAxisSize':
  972. return $this->fltYAxisSize;
  973. case 'ZAxisSize':
  974. return $this->fltZAxisSize;
  975. case 'IsInternational':
  976. if(isset($this->blnIsInternational))
  977. return $this->blnIsInternational;
  978. else
  979. return ($this->ShippingCountryId != CountryType::GetId(STORE_COUNTRY) );
  980. case 'ShippingAddressId':
  981. return $this->intShippingAddressId;
  982. case 'BillingAddressId':
  983. return $this->intBillingAddressId;
  984. case 'ExtraDocumentImages':
  985. return $this->ShippingMethod->ExtraDocumentImages;
  986. case 'CustomsFormImages':
  987. return $this->ShippingMethod->CustomsFormImages;
  988. default:
  989. try {
  990. return parent::__get($strName);
  991. } catch (QCallerException $objExc) {
  992. $objExc->IncrementOffset();
  993. throw $objExc;
  994. }
  995. }
  996. }
  997. public function __set($strName, $mixValue)
  998. {
  999. switch ($strName)
  1000. {
  1001. case 'Restored':
  1002. try {
  1003. return ($this->__blnRestored = QType::Cast($mixValue, QType::Boolean));
  1004. } catch (QInvalidCastException $objExc) {
  1005. $objExc->IncrementOffset();
  1006. throw $objExc;
  1007. }
  1008. case 'Id':
  1009. try {
  1010. return ($this->intId = QType::Cast($mixValue, QType::Integer));
  1011. } catch (QInvalidCastException $objExc) {
  1012. $objExc->IncrementOffset();
  1013. throw $objExc;
  1014. }
  1015. case 'StatusId':
  1016. try {
  1017. $intStatusIdCheck = QType::Cast($mixValue, QType::Integer);
  1018. $blnStatusChanged = ($intStatusIdCheck != $this->intStatusId);
  1019. $this->intStatusId = QType::Cast($mixValue, QType::Integer);
  1020. } catch (QInvalidCastException $objExc) {
  1021. $objExc->IncrementOffset();
  1022. throw $objExc;
  1023. }
  1024. if($this->Id)
  1025. {
  1026. if($blnStatusChanged)
  1027. {
  1028. $objOrderStatusHistory = new OrderStatusHistory();
  1029. $objOrderStatusHistory->OrderId = $this->Id;
  1030. $objOrderStatusHistory->StatusId = $this->intStatusId;
  1031. $objOrderStatusHistory->Save();
  1032. switch($mixValue)
  1033. {
  1034. ///set completion date when shipped:
  1035. case OrderStatusType::Shipped:
  1036. $this->dttCompletionDate = QDateTime::Now();
  1037. break;
  1038. //add other cases as needed ..
  1039. }
  1040. }
  1041. }
  1042. return $this->intStatusId;
  1043. case 'CreationDate':
  1044. try {
  1045. return ($this->strCreationDate = QType::Cast($mixValue, QType::String));
  1046. } catch (QInvalidCastException $objExc) {
  1047. $objExc->IncrementOffset();
  1048. throw $objExc;
  1049. }
  1050. case 'LastModification':
  1051. try {
  1052. return ($this->strLastModification = QType::Cast($mixValue, QType::String));
  1053. } catch (QInvalidCastException $objExc) {
  1054. $objExc->IncrementOffset();
  1055. throw $objExc;
  1056. }
  1057. case 'CompletionDate':
  1058. if(is_string($mixValue))
  1059. try {
  1060. return($this->dttCompletionDate = new QDateTime($mixValue));
  1061. } catch (QCallerException $objExc) {
  1062. $objExc->IncrementOffset();
  1063. throw $objExc;
  1064. }
  1065. else
  1066. try {
  1067. return ($this->dttCompletionDate = QType::Cast($mixValue, 'QDateTime'));
  1068. } catch (QInvalidCastException $objExc) {
  1069. $objExc->IncrementOffset();
  1070. throw $objExc;
  1071. }
  1072. /* try {
  1073. return ($this->strCompletionDate = QType::Cast($mixValue, QType::String));
  1074. } catch (QInvalidCastException $objExc) {
  1075. $objExc->IncrementOffset();
  1076. throw $objExc;
  1077. }*/
  1078. case 'TotalPounds':
  1079. try {
  1080. return ($this->intTotalPounds = QType::Cast($mixValue, QType::Integer));
  1081. } catch (QInvalidCastException $objExc) {
  1082. $objExc->IncrementOffset();
  1083. throw $objExc;
  1084. }
  1085. case 'TotalOunces':
  1086. try {
  1087. return ($this->fltTotalOunces = QType::Cast($mixValue, QType::Float));
  1088. } catch (QInvalidCastException $objExc) {
  1089. $objExc->IncrementOffset();
  1090. throw $objExc;
  1091. }
  1092. case 'XAxisSize':
  1093. try {
  1094. return ($this->fltXAxisSize = QType::Cast($mixValue, QType::Float));
  1095. } catch (QInvalidCastException $objExc) {
  1096. $objExc->IncrementOffset();
  1097. throw $objExc;
  1098. }
  1099. case 'YAxisSize':
  1100. try {
  1101. return ($this->fltYAxisSize = QType::Cast($mixValue, QType::Float));
  1102. } catch (QInvalidCastException $objExc) {
  1103. $objExc->IncrementOffset();
  1104. throw $objExc;
  1105. }
  1106. case 'ZAxisSize':
  1107. try {
  1108. return ($this->fltZAxisSize = QType::Cast($mixValue, QType::Float));
  1109. } catch (QInvalidCastException $objExc) {
  1110. $objExc->IncrementOffset();
  1111. throw $objExc;
  1112. }
  1113. case 'IsInternational':
  1114. try {
  1115. return ($this->blnIsInternational = QType::Cast($mixValue, QType::Boolean));
  1116. } catch (QInvalidCastException $objExc) {
  1117. $objExc->IncrementOffset();
  1118. throw $objExc;
  1119. }
  1120. case 'ShippingAddressId':
  1121. try {
  1122. return ($this->intShippingAddressId = QType::Cast($mixValue, QType::Integer));
  1123. } catch (QInvalidCastException $objExc) {
  1124. $objExc->IncrementOffset();
  1125. throw $objExc;
  1126. }
  1127. case 'BillingAddressId':
  1128. try {
  1129. return ($this->intBillingAddressId = QType::Cast($mixValue, QType::Integer));
  1130. } catch (QInvalidCastException $objExc) {
  1131. $objExc->IncrementOffset();
  1132. throw $objExc;
  1133. }
  1134. default:
  1135. try {
  1136. return (parent::__set($strName, $mixValue));
  1137. } catch (QCallerException $objExc) {
  1138. $objExc->IncrementOffset();
  1139. throw $objExc;
  1140. }
  1141. }
  1142. }
  1143. public function Dump()
  1144. {
  1145. $strToReturn = '';
  1146. $strToReturn .= ' | intId => ' . $this->intId;
  1147. $strToReturn .= ' | strCreationDate => ' . $this->strCreationDate;
  1148. $strToReturn .= ' | strLastModification => ' . $this->strLastModification;
  1149. $strToReturn .= ' | dttCompletionDate => ' . $this->dttCompletionDate;
  1150. $strToReturn .= ' | fltShippingCost => ' . $this->fltShippingCost;
  1151. $strToReturn .= ' | fltProductTotalCost => ' . $this->fltProductTotalCost;
  1152. $strToReturn .= ' | fltShippingCharged => ' . $this->fltShippingCharged;
  1153. $strToReturn .= ' | fltHandlingCharged => ' . $this->fltHandlingCharged;
  1154. $strToReturn .= ' | fltTax => ' . $this->fltTax;
  1155. $strToReturn .= ' | fltProductTotalCharged => ' . $this->fltProductTotalCharged;
  1156. $strToReturn .= ' | strShippingNamePrefix => ' . $this->strShippingNamePrefix;
  1157. $strToReturn .= ' | strShippingFirstName => ' . $this->strShippingFirstName;
  1158. $strToReturn .= ' | strShippingMiddleName => ' . $this->strShippingMiddleName;
  1159. $strToReturn .= ' | strShippingLastName => ' . $this->strShippingLastName;
  1160. $strToReturn .= ' | strShippingNameSuffix => ' . $this->strShippingNameSuffix;
  1161. $strToReturn .= ' | strShippingCompany => ' . $this->strShippingCompany;
  1162. $strToReturn .= ' | strShippingStreet1 => ' . $this->strShippingStreet1;
  1163. $strToReturn .= ' | strShippingStreet2 => ' . $this->strShippingStreet2;
  1164. $strToReturn .= ' | strShippingSuburb => ' . $this->strShippingSuburb;
  1165. $strToReturn .= ' | strShippingCounty => ' . $this->strShippingCounty;
  1166. $strToReturn .= ' | strShippingCity => ' . $this->strShippingCity;
  1167. $strToReturn .= ' | intShippingZoneId => ' . $this->intShippingZoneId;
  1168. $strToReturn .= ' | intShippingCountryId => ' . $this->intShippingCountryId;
  1169. $strToReturn .= ' | strShippingPostalCode => ' . $this->strShippingPostalCode;
  1170. $strToReturn .= ' | strBillingNamePrefix => ' . $this->strBillingNamePrefix;
  1171. $strToReturn .= ' | strBillingFirstName => ' . $this->strBillingFirstName;
  1172. $strToReturn .= ' | strBillingMiddleName => ' . $this->strBillingMiddleName;
  1173. $strToReturn .= ' | strBillingLastName => ' . $this->strBillingLastName;
  1174. $strToReturn .= ' | strBillingNameSuffix => ' . $this->strBillingNameSuffix;
  1175. $strToReturn .= ' | strBillingCompany => ' . $this->strBillingCompany;
  1176. $strToReturn .= ' | strBillingStreet1 => ' . $this->strBillingStreet1;
  1177. $strToReturn .= ' | strBillingStreet2 => ' . $this->strBillingStreet2;
  1178. $strToReturn .= ' | strBillingSuburb => ' . $this->strBillingSuburb;
  1179. $strToReturn .= ' | strBillingCounty => ' . $this->strBillingCounty;
  1180. $strToReturn .= ' | strBillingCity => ' . $this->strBillingCity;
  1181. $strToReturn .= ' | intBillingZoneId => ' . $this->intBillingZoneId;
  1182. $strToReturn .= ' | intBillingCountryId => ' . $this->intBillingCountryId;
  1183. $strToReturn .= ' | strBillingPostalCode => ' . $this->strBillingPostalCode;
  1184. $strToReturn .= ' | strNotes => ' . $this->strNotes;
  1185. $strToReturn .= ' | intShippingMethodId => ' . $this->intShippingMethodId;
  1186. $strToReturn .= ' | intPaymentMethodId => ' . $this->intPaymentMethodId;
  1187. $strToReturn .= ' | intStatusId => ' . $this->intStatusId;
  1188. $strToReturn .= ' | intTypeId => ' . $this->intTypeId;
  1189. return $strToReturn;
  1190. }
  1191. }//end class
  1192. ?>