Magento FPC and $_SESSION object - magento

How to use a cache when you have content depending on SESSION variable?
Does it work with Varnish-like cache? Does it require FPC?
let me explain.
My customers can select their model of Car (manufacturer, model, year), once selected this is stored in SESSION object.
(Of course every product is linked to a list of Cars in the back end.)
The thing is, on the frontend, There is a module that automatically filters the products according to the Car selected by the customer.
I'm not only talking about a user that would search for a product by entering a keyword on the search bar.
I'm also talking about the category pages.
When the customer visits the website, clicking on a category, then the list of products within this category is filtered too!
So while the customer navigates, he only see compatible products with his car.
I failed to use VARNISH because of this (VARNISH is based on url only, and the selected Car is not part of every url...).
That's why I'm wondering if there is any concept of Cache that would take into account SESSION variables?
thanks,
Rod

Related

How to make an API endpoint in Laravel, that can be used to search any table we want?

Background
Let us consider a hypothetical scenario. Suppose we have five different tables in our database,
Customers
Categories
Products
Orders
OderDetails
Our client wants us to add a search bar to the frontend, where a user can search for a specific product and upon tapping the search button, matching products has to be displayed on the frontend.
My Approach for Tackling This Problem
In order to add the aforementioned functionality, I came across the following strategy.
👉 I would add an input box to ender the product name and a submit button.
👉 Upon pressing the submit button, a GET request will be sent to the backend. On the query parameters, the product name that has been entered by the user will be included
👉 Once the GET request is received to the backend, I will pass it down to the ProductsController and from within a method defined inside the ProductController, I will use the Product model to query the products table to see if there are any matching results.
👉 If there are any matching results, I will send them to the frontend inside a JSON object and if there aren't any matching results, I will set a success flag to false inside the JSON object and send it to the frontend
👉 In the frontend, if there are any matching results, I will display them on the screen. Else, I will display "No Results Found!"
Problem with My Approach
Everything works fine if we only want to search the products table. But what if, later our client tells us something like "Remember that search functionality you added for the products? I thought that functionality should be added to orders as well. I think as the list of orders by a user grows and grows, they should be able to search for their previous orders too."
👉 Now, since in our previous approach to search products was implemented in the ProductController using the Product model, when we are adding the same functionality to Orders, WE WOULD HAVE TO DO THE SAME THINGS WE DID IN THE ProductsController AGAIN INSIDE THE OrdersController USING THE Order model. It does not take seconds to understand that this leads to duplication of code.
Problem Summary
❓ How do we add an API endpoint in laravel for a search functionality that can be used to search any table in our database and get results, instead of the search functionality being scoped to a specific controller and a corresponding model?
A good start would be to create a trait called something like searchable and add it to all the models you want to search and put any shared logic between the different models in there. Possibly you'd want to manually allow different columns so in each model you have an array of searchable columns which you'd refer to in your trait.
Your controller would have to point to the related model and call a method in the trait that searches.
As others have pointed out this is a high level question so I won't go too much in detail. Of course there are a million ways to implement this, just try and keep shared logic in place.

select city popup in magento

I have a magento store. I want to operate in a city. When one customer visit the store he/she will asked to select his/her area from a dropdown list in a popup. Then the customer is allowed to see the products in the store and shop online.
Example: Suppose My city is Bhubaneswar
Areas: Acharya Vihar, Vani Vihar, Rasulgarh, Barmunda.
U can create different stores for different places and put this Mage::app()->setCurrentStore($store_id); to make your storeid your current one
For each store you can map several areas, this mapping could be represented in your city area table, by adding a store_id column.
The customer selects the desired store by selecting the city/area, you can then redirect to the desired url with the store scope here you should use
Mage::getUrl($path, array(
'_store'=>'your_store_id'
));
To restrict the store as you said, there are different approaches, one is having a default store that is not associated with any area, then you make the categories/products available/enabled only for the stores other than this default one.

How do you query the category id or name in Opencart 1.5.5.1 Joomla 3.3.0

So I am modifying a module and I've successfully queried the product ID. So if I am browsing products and go into the product details page, I can see my product ID using
JRequest::getInt('product_id');
but for some reason I cannot get the category ID. I've tried.
JRequest::getInt('category_id');
and it always comes out to zero no matter what category I go to. Anyone else experience this? I could get it from the nonSEF url but there's gotta be another way. My goal is to basically query the category ID when I am browsing that category or if I am in the product details of a product.
I assume, you're using some OpenCart component for Joomla. In this case, you have to look into controller and model files for OpenCart. It's not THAT easy to get certain values sometimes, because these are 2 different engines.
In short, you may have to use VQMod for OpenCart, add category_id to data array and only then JRequest it. Solely depends on task.

Store a group of form fields in multidimensional array in Joomla

Here's the setup (using a made-up scenario), but applicable to my real situation:
For the purposes of this explanation, let's say that i design T-shirts (Let's call them ShirtA, shirtB, shirtC). Rather than selling them myself, i have several vendors that sell the product for me (we'll call them Vendors X, Y, and Z).
I have a table in my Joomla database for the vendors, and a table for the t-shirts.
When customers are buying from this vendor, they will visit my site and based on the ID url variable, will display a different vendor's page.
Each vendor can choose to sell all of my t-shirts, or only some of them. Additionally, the vendor can override the price that i have set in the t-shirt table, with their own.
In the admin section of the component, each vendor needs to be able to select which t-shirt they want to sell, and provide an optional price override.
This is how i imagine it looking...
Each vendor will have a column in their table that will contain the serialized data of a multidimensional array. The main array contains a sub-array for each t-shirt that i have in my t-shirt table. Each of those sub-arrays contains all of the override data (price, sizes offered, etc..).
How would i write the model, view, and/or edit page in a Joomla 2.5 component so that a vendor can select all of the options in the component admin page, and have it serialized in a column?
I am sorry if this is poorly explained and PLEASE PLEASE PLEASE don't hesitate to ask if you need further information in order to assist me.
Thanks!
I hate to say it, but I don't think that there is a "standard" method to do this in Joomla 2.5. Joomla has all kinds of ways to interact with the database and use their standard classes, but none of the classes are designed to work with serialized data to the best of my knowledge, so you would be stuck building all of the pieces by hand.
That being said, in general the model, should handle retrieving and storing the serialized data, the view would request any data in the database from the model, and the edit page should unserialize the data and display it in a way that your vendors can add their overrides. Beyond that it would be up to you to code each piece in your own way.

Magento: Add a "fake" product to cart/quote

I understand how to programmatically create a product and also add to cart. I know this might sound dumb but is it is possible to generate a product on the fly and add that to the cart/quote but never actually save it in the database.
We want to create a made to order interface and I was thinking at the end it could add a bundle product with all the selections but that bundle product wouldn't actually exist in the backend.
I figured as long as you can make sure the quote and order has what it needs in terms of the product it would be ok, but obviously there is probably a lot that is tied to looking up stuff in the db on a specific sku or ID. I know that if you delete a product and then look at an order in the admin that causes issues, at least it did for this one scenario I was dealing with.
I was thinking of creating a giant bundle product that had like 6 different bundle items and each item could potentially have like 500 products and then based on what the user selects I programmatically add the bundle to cart. But then I wasn't sure if there would be a negative affect with having a gigantic bundle product like that as well.
UPDATE:
I don't think this will work, obviously there are a lot of information tied to the product in the database and we setup a test and right away we get an error for $item->getProduct(). We are moving forward with creating a giant bundle product and also the generic product with adding custom options on the fly, which Anda pointed out below. Any other suggestions will be greatly appreciated.
I'm not sure that clockworkgeek's approach is going to work. On every page load, Magento loads the items from the cart to make sure that they are still valid (in-stock, prices correct, etc), and amends the cart to reflect those values. My understanding of the system in the past has been that a product in the cart needs to have a corresponding database value to survive this process.
The "giant bundle product" approach is a pain, but in the past has been the best approach I have found. Attempting to change the values of the product (such as price or attributes) will be overridden by the cart checks, so you need a product w/ maximal flexibility, such as an overly-customized bundle product or configurable product.
Hope that helps!
Thanks,
Joe
Why not create a generic product in db and then set the product customization as custom options (additional_options) on the fly depending on the user selection. You can add custom options to the product (actually to the quote item) without having to save them in the database. I did this once for a website that sells glasses with prescription. The prescription was added as an option.
You can programmatically create Mage_Sales_Model_Quote_Items and add them to the cart. You've noticed it needs a product to match it's product ID but it needn't be a useful one. It could be a blank, disabled product, also created in code. All that's needed is a stub.
The necessary stuff for the cart is stored in the quote item - fields like name, value and quantity. Those fields are then copied directly to the order without using a product.
Mage::getModel('catalog/product')
creates a new product. you can add it to a cart, by doing something like this:
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product')
->setStoreId($storeid)
->setTypeId($type_id)
->setQty($quantyty)
->setWhatAttributYouWant($attribute);
$cart->addProduct($product);
product attributes you can find in the DB in tables that start like catalog_product_... or take an already created product, and see what attributes it has in the _data array (with debugger or just print_r($product->getData))

Resources