Products Variations and User Uploads - Part II: By: Muhammad Zeeshan Ali
Products Variations and User Uploads - Part II: By: Muhammad Zeeshan Ali
1
Giving Users Choice …
• Changing our Product Query
– In order for the framework to detect if a product has any
variations or changeable attributes, we need to modify the
query.
– we use to get the product data, and change this to perform a
subquery, which groups together all of the attribute values and
their attributes that can be associated with the product.
– If there are no attribute values, then the model should have a
property set to define that it has no customizable attributes;
otherwise, the property should indicate that there are
customizable attributes. 2
Giving Users Choice …
• Switching the Template
– Our controller can then check this property value with the
model, and generate the relevant templates to form the view
accordingly.
– If the product has attributes, we iterate through them, and for
each attribute we generate a list of values associated with it.
3
Giving Users Choice …
• A look back at Simple Variants
– One advantage that they have over multiple variants becomes
obvious when page design becomes a concern.
– If we were to have a system that utilized simple variants, we
could display a simple table of product variants on the "main
products" page, listing the names of products, cost or cost
difference, and a purchase button.
4
Giving Users Choice …
• A look back at Simple Variants…
5
Giving Users Control
• Along with giving users a choice for products in our store,
we may also wish to give them some control over the
products; for example, this could include:
– Uploading a photograph or image
– Supplying some custom text
6
Giving Users Control …
• How to customize a product?
– We need to make it possible for our customers to customize the
product through both file and image uploads, and then entering
of free text.
– Uploads
• If the product is to allow the customer to upload an image, then the
template requires a file upload field within it, to facilitate that.
– Custom Text
• The simplest way to handle custom text is to have at most one free text
permitted per product.
• This would simply involve having an extra field in the table. 7
Giving Users Control …
8
Giving Users Control …
• Maintaining Uploads
– We will also need to consider maintaining uploads.
– If a file is uploaded and a product is added to a basket, and that
basket is never converted into an actual order, we will want to
remove that file.
– Similarly, once an order has been paid for, and processed fully,
we would also want to remove it.
9
Giving Users Control …
• Security Considerations
– There are also a number of security considerations which we
must bear in mind:
• By allowing customers to upload files, we could be open to abuse from
someone repeatedly uploading images to our server. We could implement
time delays to prevent this.
• Which types of files will we allow customers to upload? We should check
both the type of the file uploaded and the file extension against a list of
suitable values.
• What would the maximum file size be for files customers upload? If we set
this value to be too large, our server will get filled up quickly with custom
files.
• What safeguards are in place to prevent customers finding uploads of
10
other customers?
Giving Users Control …
• Database Changes
– To allow customers to customize products, we obviously need
to make some changes to our database structure to indicate
that a particular product is customizable.
– And can be customized either by the customer uploading a file
or entering some text.
11
Giving Users Control …
• Extending our products table
– The changes required to our products table are actually quite
simple; we only need to add two fields to the table:
• allow_upload (Boolean): This field is used to indicate if the customer is
permitted or able to upload a file when adding the product to their
basket.
• custom_text_inputs (longtext): This field is used to hold a serialized
array of free text fields, which we may wish to collect from our
customers.
12