PHP 5 e-commerce Development- P18 pps

5 67 0
PHP 5 e-commerce Development- P18 pps

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

Thông tin tài liệu

Products and Categories [ 68 ] Content versions The actual content of pages and other content types is stored in the content_versions table, which stores versions of the content, and the active version for each content element is referenced directly by the content table. This table requires the following structure: Field Type Description ID Integer (Auto increment, Primary Key) A reference for the framework to refer to different versions Name Varchar The name of the content Title Varchar The page title for the content (shown in the <title> tags of the page) Heading Varchar The heading for the page, commonly displayed within <h1> tags. Content Longtext The actual HTML content for the content (the page, product, or other suitable content type) Metakeywords Varchar The keywords metadata Metadescription Varchar The description metadata eld Metarobots Varchar The robots metadata eld; this could be from a predened list, so we may wish to have a metarobots table, or make this an ENUM eld Author Integer A reference to the user who created this version of the content Timestamp Timestamp The time and date that the version was created The SQL for this table is as follows: CREATE TABLE `content_versions` ( `ID` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `heading` varchar(255) NOT NULL, `content` longtext NOT NULL, `metakeywords` varchar(255) NOT NULL, `metadescription` varchar(255) NOT NULL, `metarobots` varchar(255) NOT NULL, `author` int(11) NOT NULL, `created` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`ID`), KEY `author` (`author`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 3 [ 69 ] This table should have the following references to foreign keys: ALTER TABLE `content_versions` ADD CONSTRAINT `content_versions_ibfk_1` FOREIGN KEY (`author`) REFERENCES `users` (`ID`) ON UPDATE CASCADE; Products As discussed earlier, products will be represented by extending the revisions table and combining it with a products table. Field Type Description ID Integer (Primary Key, Auto increment) A reference to the entry in the table. Content_version Integer Ties the product version data to a content version, associating relevant elds from that and from its associated record in the content table too. SKU Varchar The stock keeping unit reference for the product. Image Varchar A reference to an image path where the primary image for this product is stored. Weight Int The weight of the product. Featured Boolean If the product is featured. We may wish to use this to display products on the home page, or perhaps in a "featured products" box. The following SQL represents this table: CREATE TABLE `content_types_products` ( `ID` int(11) NOT NULL auto_increment, `content_version` int(11) NOT NULL, `price` float NOT NULL, `weight` int(11) NOT NULL, `SKU` varchar(255) NOT NULL, `stock` int(11) NOT NULL, `image` varchar(255) NOT NULL, `featured` tinyint(1) NOT NULL, PRIMARY KEY (`ID`), KEY `content_version` (`content_version`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Products and Categories [ 70 ] The table needs the following references to foreign keys: ALTER TABLE `content_types_products` ADD CONSTRAINT `content_types_products_ibfk_1` FOREIGN KEY (`content_version`) REFERENCES `content_versions` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE; Categories Categories themselves don't need to extend the data held within the content versions table, so we can use that table as is for categories. Pages within our framework To enable pages within our framework, we need to add a model, controller, and some templates (a view) to it. The model will connect to the database and represent the data contained within a page. The controller will work with the model to lookup the current page, and display it within the view. There is a lot of additional functionality, which we could look at implementing here, such as menu and submenu generation, breadcrumb generation, and so on. However, that is more of a content management system focus, and beyond the scope of this book. Model Our model requires the ability to connect to the database, search for a page given the path of a page, and represent the data of that page. It also needs to inform the framework if the path provided does not represent a page, so that we can generate a "Page not found" error. The constructor The simplest way for us to do this, is to have the constructor perform the page lookup, by passing a page path to it as a parameter. The constructor should then set the values of various properties within the model object to the values from within the database. If a page was not found, it needs to set a particular property to reect this. This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 3 [ 71 ] Other methods Other methods we need within our model are: isValid(): This method is used by the controller to lookup if the page is valid or not. isActive(): This method is used by the controller to lookup if the page is active or not. isSecure(): This method is used by the controller to determine if the page is secure, and if the visitor is permitted to see the page. getProperties(): This method returns the properties of the page, so they can be integrated with the view. This gives us the following code for our model: <?php // models/pages/model.php class Pagemodel { private $registry; private $valid = false; private $active = true; private $secure = false; private $pageheading; private $title; private $pagecontent; private $metakeywords; private $metadescription; private $metarobots; public function __construct( PHPEcommerceFrameworkRegistry $registry, $urlPath ) { $this->registry = $registry; $urlPath = $this->registry->getObject('db')->sanitizeData ( $urlPath ); $sql = "SELECT c.ID, c.active, c.secure, v.title, v.name, v.heading, v.content, v.metakeywords, v.metadescription, v.metarobots FROM content c, content_types t, content_versions v WHERE c.type=t.ID AND t.reference='page' AND c.path='{$urlPath}' AND v.ID=c.current_revision LIMIT 1"; $this->registry->getObject('db')->executeQuery( $sql ); if( $this->registry->getObject('db')->numRows() != 0 ) { • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Products and Categories [ 72 ] $this->valid = true; $pageData = $this->registry->getObject('db')->getRows(); $this->active = $pageData['active']; $this->secure = $pageData['secure']; $this->pageheading = $pageData['heading']; $this->title = $pageData['title']; $this->pagecontent = $pageData['content']; $this->metakeywords = $pageData['metakeywords']; $this->metadescription = $pageData['metadescription']; $this->metarobots = $pageData['metarobots']; } } public function isValid() { return $this->valid; } public function isActive() { return $this->active; } public function isSecure() { return $this->secure; } public function getProperties() { $tor = array(); foreach( $this as $field => $value ) { if( !is_object( $value ) ) { $tor[ $field ] = $value; } } return $tor; } } ?> This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 . varchar( 255 ) NOT NULL, `heading` varchar( 255 ) NOT NULL, `content` longtext NOT NULL, `metakeywords` varchar( 255 ) NOT NULL, `metadescription` varchar( 255 ) NOT NULL, `metarobots` varchar( 255 ) NOT. `price` float NOT NULL, `weight` int(11) NOT NULL, `SKU` varchar( 255 ) NOT NULL, `stock` int(11) NOT NULL, `image` varchar( 255 ) NOT NULL, `featured` tinyint(1) NOT NULL, PRIMARY KEY (`ID`), . be integrated with the view. This gives us the following code for our model: < ?php // models/pages/model .php class Pagemodel { private $registry; private $valid = false; private $active

Ngày đăng: 07/07/2014, 10:20

Mục lục

  • PHP e-commerce

    • e-commerce: who, what, where, why?

      • An overview of e-commerce

        • eBay

        • Brick 'N Mortar stores

        • Rolling out your own framework

          • Why PHP?

          • When to use an existing package?

            • Existing products

            • A look at e-commerce sites

              • iStockphoto

              • e-commerce: what does it need to do/have?

                • Products

                • Our framework: what is it going to do?

                • Our framework: why is it going to do it?

                  • Juniper Theatricals

                  • Planning our Framework

                    • Designing a killer framework

                      • Patterns

                        • Model-View-Controller (MVC)

                        • Building a killer framework

                          • Pattern implementation

                            • MVC

                            • Routing requests

                              • An alternative: with a router

                              • Processing the incoming URL within our registry object

                              • What about e-commerce?

                                • An e-commerce registry?

                                • Products and Categories

                                  • What we need

                                    • Product information

                                    • Structuring content within our framework

                                      • Pages

                                      • Building products, categories, and content functionality into our framework

                                        • Database

                                          • Content

                                          • Pages within our framework

                                            • Model

                                            • Product and category images

                                            • Routing products and categories

                                              • Featured products

                                              • Product Variations and User Uploads

                                                • Giving users choice

                                                  • Simple variants

                                                    • How could this work?

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

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

Tài liệu liên quan