How could you “design” a basket as part of a Zend Framework project?

I know ZF well and a bit of Magento, but I'm new to e-commerce and I’m sure that it’s best to follow when developing a basket model.

How will the basket design go?

I mean two models, Model_Cart and Model_Cart_Item , used in conjunction with Zend_Session to store the cart in a session.

What are your reviews?

How would you do that? What should I know about writing a trolley system?

Please note that I need a simple system, I do not even need to work with quantity

+4
source share
3 answers

If your models are easily serializable, you can simply add them to the session data, for example

 // storage $cartNamespace = new Zend_Session_Namespace('cart'); $cartNamespace->cart = $cart; // $cart is a Model_Cart with items // retrieval $cartNamespace = new Zend_Session_Namespace('cart'); if (isset($cartNamespace->cart) { $cart = $cartNamespace->cart; } 

POPO (simple old PHP objects) are very easy to serialize. If your models contain any specific runtime properties (database connections, file descriptors, etc.), you must implement a Serializable interface to handle any complexity.

You may also consider storing model data in a database. There are some discussions about storing shopping cart data can help you decide.

+3
source

You are on the right track.

I suggest creating a controller action helper class to help this task. This will make your controller code less cumbersome. Here is a good tutorial about action assistants .

Give the helper class the base method:

 $this->_helper->card->add($product, $qty); $this->_helper->card->remove($product); $this->_helper->card->getItems(); 

Something like that.

What should I know about writing a trolley?

This is more for the verification part ... Applies to the USA. The client must pay taxes if your business location matches the state of the user. For instance. If your business is registered in Florida, and the client is a regular customer from Florida, he must pay taxes, but clients from NY do not.

+1
source

Create the Cart and Cart_Item classes. The Cart class must contain methods for adding and removing Cart_Items, which are stored in an array in the Cart class. Also create a save method that serializes the state of the basket in the session, I also like to serialize the basket to the database table using the standard Zend_Db_Table_Abstract model.

I create controller actions that take the identifier and quantity of the product and pass them to the Cart class add / remove methods, after which the carts are saved.

I find it useful to implement a singleton pattern for this type of system, especially if Cart is updating itself from the design database.

As Alex said, helpers are useful, I like to use the view assistant, which will retrieve the current instance of the basket and allow you to easily pull out subtotals and a summary ect. in view.

In addition, condsider uses the Iterator, Countable, and ArrayAccess interfaces so you can navigate your cart to get all of your items.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1343697/


All Articles