Beginning PHP and Postgre SQL E-Commerce From Novice to Professional phần 9 ppt

63 198 0
Beginning PHP and Postgre SQL E-Commerce From Novice to Professional phần 9 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

// Audit $processor->CreateAudit('Funds deducted from customer credit card account.', 20402); // Update order status $processor->UpdateOrderStatus(5); // Continue processing $processor->mContinueNow = true; // Audit $processor->CreateAudit('PsTakePayment finished.', 20401); } } ?> When this pipeline stage finishes, processing moves straight on to PsShipGoods. PsShipGoods This pipeline section is remarkably similar to PsCheckStock, as it sends an email to the supplier and stops the pipeline until the supplier has confirmed that stock has shipped. This time you do need customer information, however, because the supplier needs to know where to ship the order! Add the following code to a new file in the business folder named ps_ship_goods.php: <?php class PsShipGoods implements IPipelineSection { private $_mProcessor; public function Process($processor) { // Set processor reference $this->_mProcessor = $processor; // Audit $processor->CreateAudit('PsShipGoods started.', 20500); // Send mail to supplier $processor->MailSupplier('HatShop ship goods.', $this->GetMailBody()); // Audit $processor->CreateAudit('Ship goods e-mail sent to supplier.', 20502); // Update order status $processor->UpdateOrderStatus(6); CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 483 648XCH14.qxd 11/17/06 3:47 PM Page 483 // Audit $processor->CreateAudit('PsShipGoods finished.', 20501); } As before, a private method called GetMailBody is used to build the message body for the email sent to the supplier: private function GetMailBody() { $body = 'Payment has been received for the following goods:'; $body.= "\n\n"; $body.= $this->_mProcessor->GetOrderAsString(false); $body.= "\n\n"; $body.= 'Please ship to:'; $body.= "\n\n"; $body.= $this->_mProcessor->GetCustomerAddressAsString(); $body.= "\n\n"; $body.= 'When goods have been shipped, please confirm via ' . 'http://www.hatshop.com/admin.php'; $body.= "\n\n"; $body.= 'Order reference number: '; $body.= $this->_mProcessor->mOrderInfo['order_id']; return $body; } } ?> When this pipeline stage finishes, processing pauses. Later, when the supplier confirms that the order has been shipped, processing moves on to PsShipOk. PsShipOk This pipeline section is very similar to PsStockOk, although it has slightly more to do. Because you know that items have shipped, you can add a shipment date value to the orders table. Technically, this isn’t really necessary because all audit entries are dated. However, this method means that you have all the information easily accessible in one database table. Add the following code to a new file in the business folder named ps_ship_ok.php: <?php class PsShipOk implements IPipelineSection { public function Process($processor) CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II484 648XCH14.qxd 11/17/06 3:47 PM Page 484 { // Audit $processor->CreateAudit('PsShipOk started.', 20600); // Set order shipment date $processor->SetDateShipped(); // Audit $processor->CreateAudit('Order dispatched by supplier.', 20602); // Update order status $processor->UpdateOrderStatus(7); // Continue processing $processor->mContinueNow = true; // Audit $processor->CreateAudit('PsShipOk finished.', 20601); } } ?> When this pipeline stage finishes, processing moves straight on to PsFinalNotification. PsFinalNotification This last pipeline section is very similar to the first because it sends an email to the customer. This time, you’re confirming that the order has shipped. Add the following code to a new file in the business folder named ps_final_notification.php: <?php class PsFinalNotification implements IPipelineSection { private $_mProcessor; public function Process($processor) { // Set processor reference $this->_mProcessor = $processor; // Audit $processor->CreateAudit('PsFinalNotification started.', 20700); // Send mail to customer $processor->MailCustomer('HatShop order dispatched.', $this->GetMailBody()); // Audit CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 485 648XCH14.qxd 11/17/06 3:47 PM Page 485 $processor->CreateAudit('Dispatch e-mail send to customer.', 20702); // Update order status $processor->UpdateOrderStatus(8); // Audit $processor->CreateAudit('PsFinalNotification finished.', 20701); } It uses a familiar-looking GetMailBody method to build the body of the email: private function GetMailBody() { $body = 'Your order has now been dispatched! ' . 'The following products have been shipped:'; $body .= "\n\n"; $body .= $this->_mProcessor->GetOrderAsString(false); $body .= "\n\n"; $body .= 'Your order has been shipped to:'; $body .= "\n\n"; $body .= $this->_mProcessor->GetCustomerAddressAsString(); $body .= "\n\n"; $body .= 'Order reference number: '; $body .= $this->_mProcessor->mOrderInfo['order_id']; $body .= "\n\n"; $body .= 'Thank you for shopping at HatShop.com!'; return $body; } } ?> When this pipeline section finishes, the order status is changed to 8, which represents a completed order. Further attempts to process the order using OrderProcessor will result in an exception being thrown. CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II486 648XCH14.qxd 11/17/06 3:47 PM Page 486 Testing the Pipeline Now let’s do a simple test to make sure the code you just wrote is working as expected. Exercise: Testing the Pipeline 1. Add the following highlighted lines in the include/app_top.php file. (Also feel free to remove the reference to ps_dummy.php, which is no longer required.) require_once BUSINESS_DIR . 'order_processor.php'; require_once BUSINESS_DIR . 'ps_initial_notification.php'; require_once BUSINESS_DIR . 'ps_check_funds.php'; require_once BUSINESS_DIR . 'ps_check_stock.php'; require_once BUSINESS_DIR . 'ps_stock_ok.php'; require_once BUSINESS_DIR . 'ps_take_payment.php'; require_once BUSINESS_DIR . 'ps_ship_goods.php'; require_once BUSINESS_DIR . 'ps_ship_ok.php'; require_once BUSINESS_DIR . 'ps_final_notification.php'; 2. Modify the code of the GetCurrentPipelineSection method in OrderProcessor (inside business/order_processor.php) as follows: // Gets current pipeline section private function GetCurrentPipelineSection() { switch($this->mOrderInfo['status']) { case 0: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsInitialNotification(); break; case 1: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsCheckFunds(); break; case 2: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsCheckStock(); break; case 3: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsStockOk(); break; CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 487 648XCH14.qxd 11/17/06 3:47 PM Page 487 case 4: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsTakePayment(); break; case 5: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsShipGoods(); break; case 6: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsShipOk(); break; case 7: $this->_mOrderProcessStage = $this->mOrderInfo['status']; $this->_mCurrentPipelineSection = new PsFinalNotification(); break; case 8: $this->_mOrderProcessStage = 100; throw new Exception('Order already been completed.'); break; default: $this->_mOrderProcessStage = 100; throw new Exception('Unknown pipeline section requested.'); } } 3. Open business/orders.php and modify the $mOrdersStatusOptions member of the Orders class to manage the new order status codes. Note that this change affects the old orders, which used different status codes: public static $mOrderStatusOptions = array ( 'Order placed, notifying customer', // 0 'Awaiting confirmation of funds', // 1 'Notifying supplier-stock check', // 2 'Awaiting stock confirmation', // 3 'Awaiting credit card payment', // 4 'Notifying supplier-shipping', // 5 'Awaiting shipment confirmation', // 6 'Sending final notification', // 7 'Order completed', // 8 'Order canceled'); // 9 CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II488 648XCH14.qxd 11/17/06 3:47 PM Page 488 4. Open presentation/smarty_plugins/function.load_admin_order_details.php, and add the highlighted new member to the AdminOrderDetails class: public $mTaxCost = 0.0; public $mOrderProcessMessage; 5. Modify the code of the init method in the AdminOrderDetails class located in presentation/ smarty_plugins/function.load_admin_order_details.php as highlighted. This will handle the functionality necessary when the visitor clicks the Process button. if (isset ($_GET['submitProcessOrder'])) { $processor = new OrderProcessor($this->mOrderId); try { $processor->Process(); $this->mOrderProcessMessage = 'Order processed, status now: ' . $processor->mOrderInfo['status']; } catch (Exception $e) { $this->mOrderProcessMessage = 'Processing error, status now: ' . $processor->mOrderInfo['status']; } } 6. Open the presentation/templates/admin_order_details.tpl file, and add the highlighted code: <span class="admin_page_text"> Editing details for order ID: {$admin_order_details->mOrderInfo.order_id} [ {strip} <a href="{$admin_order_details->mAdminOrdersPageLink|prepare_link:"https"}"> back to admin orders </a> {/strip} ] </span> <br /><br /> {if $admin_order_details->mOrderProcessMessage} <strong>{$admin_order_details->mOrderProcessMessage}</strong> <br /><br /> {/if} <form action="{"admin.php"|prepare_link:"https"}" method="get"> 7. Execute the code, create a new order, and then open that order in the orders admin page. In the orders admin page, click the Process Order button. 8. You should get a customer notification email (see Figure 14-1). CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 489 648XCH14.qxd 11/17/06 3:47 PM Page 489 Figure 14-1. Customer order confirmation email 9. Check your supplier email for the stock check email (see Figure 14-2). Figure 14-2. Stock check email CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II490 648XCH14.qxd 11/17/06 3:47 PM Page 490 10. Continue processing in the admin order details page by clicking the Process Order button again, calling the Process method of the OrderProcessor class for the second time. 11. Check your email for the ship goods email (see Figure 14-3). Figure 14-3. Ship goods email 12. Continue processing in the admin order details page by clicking Process and calling the Process method of the OrderProcessor class for the third and last time. 13. Check your email for the shipping confirmation email (see Figure 14-4). CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 491 648XCH14.qxd 11/17/06 3:47 PM Page 491 Figure 14-4. Customer shipping notification email (dispatched.png) 14. Examine the new audit entries for the order as shown in Figure 14-5. CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II492 648XCH14.qxd 11/17/06 3:47 PM Page 492 [...]... $page->assign('customerLoginOrLogged', $customerLoginOrLogged); You can now use the HatShop web store to place orders, but they will pause when it gets to stock confirmation To continue, you’ll implement the interface for suppliers and administrators to use to force orders to continue processing Updating the Orders Admin Page The basic functionality of this page is to allow suppliers and administrators to view... are completely separate from the Inter net, and although it’s possible to get direct access to them, this isn’t likely to be a reasonable option To do so, you might have to enter into some serious negotiation with the owner of the network you want to use The owner will want to be completely sure that you are a reliable customer who is capable of enforcing the necessary safeguards to prevent an attack... You also have to add a new method to the Orders class from business/orders .php to cater to the new data tier function added in the previous section Add the GetAuditTrail method to the Orders class in business/orders .php, as follows: // Gets the audit table entries associated with a specific order public static function GetAuditTrail($orderId) { // Build the SQL query $sql = 'SELECT * FROM orders_get_audit_trail(:order_id);';... running PHP under Windows, you just need to copy libeay32.dll and ssleay32.dll from the PHP package to the System32 folder of your Windows installation and uncomment the following line in php. ini (by default, located in your Windows installation folder) by removing the leading semicolon, and then restarting Apache: extension =php_ curl.dll For more details about the CURL library, check out the excellent tutorial... http://www.zend.com/ pecl/tutorials/curl .php The official documentation of PHP s CURL support is located at http://www .php. net/curl Exercise: Communicating with DataCash 1 Create a new file named datacash_request .php in the business folder, and add the following code to it: < ?php class DataCashRequest { // DataCash Server URL private $_mUrl; // Will hold the current XML document to be sent to DataCash private... pipeline to the next section if the Process button is clicked; the presence of this button on the page depends on the value of the mProcessButtonText member This value is set to “Confirm Stock” if the current pipeline section is 3 (awaiting stock confirmation), or to “Confirm Shipment” if the current pipeline section is 6 (awaiting shipment confirmation) If the current pipeline section is not set to 3... successfully, and the button is not shown The administrator can always check what happened to the order by checking the audit trail that is displayed on the page All that remains now is to check that everything is working properly To do this, use the web interface to place an order, and then check it out via the orders details admin section You should see that the order is awaiting confirmation of stock, as... times in a row from the order details admin page In practice, this won’t happen—it will be called once by presentation/smarty_plugins/function.load_checkout_info .php when a customer places an order and twice more by the supplier in presentation/smarty_plugin/ function.load_admin_order_details .php You’ll need to modify these web pages accordingly 495 648XCH14.qxd 496 11/17/06 3:47 PM Page 496 CHAPTER 14... communicating with DataCash because you’ll need to create XML documents to send to DataCash and to extract data from XML responses In the following few pages, we’ll take a quick look at the XML required for the operations you’ll be performing and the responses you can expect Pre-Authentication Request When you send a pre-authentication request to DataCash, you need to include the following information: • DataCash... email CustomerService@example.com 4 Add the following style to hatshop.css: a.mail { color: #0000ff; font-size: 11px; text-decoration: underline; } 497 648XCH14.qxd 498 11/17/06 3:47 PM Page 498 CHAPTER 14 ■ IIMPLEMENTING THE ORDER PIPELINE: PART II 5 Modify index .php by adding the highlighted code to load either order_done.tpl . PIPELINE: PART II 499 648XCH14.qxd 11/17/06 3:47 PM Page 499 Implementing the Business Tier You also have to add a new method to the Orders class from business/orders .php to cater to the new data. suppliers and administrators to use to force orders to continue pro- cessing. Updating the Orders Admin Page The basic functionality of this page is to allow suppliers and administrators to view. on to PsShipGoods. PsShipGoods This pipeline section is remarkably similar to PsCheckStock, as it sends an email to the supplier and stops the pipeline until the supplier has confirmed that stock

Ngày đăng: 12/08/2014, 14:21

Mục lục

  • Beginning PHP and PostgreSQL E-Commerce: From Novice to Professional

    • Chapter 15

    • Chapter 16

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan