I would like to ask a theoritical question about how some web sites work. As an example.Let's say that I'm in the A market on line store. I placed a case of wine in the shopping trolley, The page appeared with this URL:
www.A.co.uk/webstore/basket.asp?calledby=normal&ProductCode=6379044
I continued shopping and then placed a different wine in the trolley and again the page appeared with this URL
www.A.co.uk/webstore/basket.asp?calledby=normal&ProductCode=6323456
I then Clicked the Back Button on the browser three times and the trolley page appeared again. This time contained ONLY the first item and NOT the second.
In another website I showed the following:
I selected a case of wine. As a result the form containing the wine was posted to this ASP page basket.asp?Item=3605681, where Item is the ID of the particular case of wine. However the page appeared in the browser had a different URL:
www.B.com/extra/basket.aspx?acstore=10&ba=0
I then added another case of different wine to basket. The address that appeared was exactly same as previous one.
When I clicked the Back Button The Shopping basket always showed that I have two items in the basket. How do you think that these Online stores have programmed the site so that shopping basket always shows its current state even if the user presses the Back Button several times? Also, what's the difference of these two situations?
The basket is likely stored in the session. More than often the session is in turn backed by cookies. In JSP/Servlet it's the JSESSIONID cookie. To test it yourself, locate the cookie in browser's cookie store and delete it. You'll see that a page refresh will result in an empty basket. For more detailed background information, please read How do servlets work? Instantiation, sessions, shared variables and multithreading.
In JSP/Servlet terms, the basket could be retrieved/precreated as follows:
Basket basket = (Basket) session.getAttribute("basket");
if (basket == null) {
basket = new Basket();
session.setAttribute("basket", basket);
}
// ...
This lives then as long as the user is interacting with the same webpage within the same session. Any products could be added to the basket as follows:
String productCode = request.getParameter("productCode");
Product product = someProductService.find(productCode);
if (product != null) {
basket.addProduct(product);
}
// ...
In JSP you could then display it as follows:
<table>
<c:forEach items="${basket.products}" var="product">
<tr>
<td>${product.code}</td>
<td>${product.description}</td>
<td>${product.quantity}</td>
<td>${product.price}</td>
</tr>
</c:forEach>
</table>
Related
I have created one custom module in Prestashop 1.7.8.7 which will add multiple shipping methods (Carrier) and will show shipping cost based on product dimensions and delivery address. So shipping carrier will look something like this on front-end checkout page. https://prnt.sc/E1avDASyJYYW
Now if someone select SameDay Courier Shipping then i need to show two radio button to select which service they want.
It will have two radio options like
Delivery pickup (by default this option will be selected)
Locker pickup
So if someone select Delivery pickup then it will have different shipping cost and if someone select Locker pickup then it will have different shipping cost.
Can anybody help me how can i achieve this functionality.
While digging, i found that we have file called DeliveryOptionsFinder.php and in that file we have one public function called getDeliveryOptions() where we have this line of code
if ($moduleId = Module::getModuleIdByName($carrier['external_module_name'])) {
$carrier['extraContent'] = Hook::exec('displayCarrierExtraContent', ['carrier' => $carrier], $moduleId);
}
}
So if i set is_module to 1 to all my carriers directly from DB then on frontend checkout page, no carriers is being displayed.
Thanks in advance.
I've already done something like this in the last 2 year as prestashop developer.
The truth is that you can't achieve what you want by "respecting" prestashop processes.
Maybe you can hook using a module the hookDisplayCarrierExtraContent($data) and then return the 2 radios if carrier is certain one (use $data).
But you can't handle a form submit or something else, or include it to prestashop checkout data.
But what you can do as workaround, for example, is the following.
In your module, as I said, hook the extra content, render a template with the 2 radios. Hook displayHeader too and use $this->context->controller->addJS() to add your own js if the current controller is the checkout one.
Then in this JS code you can handle the "change" event of the radios and send an ajax request to your module.
You can create inside {your_module}/controllers/front/ a controller called, for example, radio-choose and handle the js ajax request by saving inside your own table the choosen one.
Obviously you can disable the "next" button in checkout untill one of the two radios are selected, or maybe you can just set a radio button as default one to simplify.
For example your table "ps_cart_choosen_radio" could look like this |id_cart|choosen_radio|.
Then you have all the data you needed. When a cart is converted into an order you will have inside Order object (and ps_orders table as well) the id_cart.
Just select / join choosen radio from your own table by using order's id_cart.
"SELECT choosen_radio FROM ps_cart_choosen_radio WHERE id_cart = {$order.id_cart}"
If you need to show data depending on choosen_radio in frontend you can hook everywhere an order is present and select these data. Or maybe you can edit carrier name in ps_orders table by adding a piece of string. Let' say carrier is "express" and customer choosed "24h". You can update that column with carrier name by changing it to "express-24h" so around the whole prestashop ecosystem everybody will see that's a 24h choice.
Remember that the carrier name related to an order is not the carrier name inside the carriers table. So you can edit it without having trouble.
All these problems comes from the "need" to show some nested choices instead of listing all these in the main selections. In that case it would be easy (just create carrier in the prestashop backoffice)
I set up a product collection type, added three records and in the browser type
localhost:1337/api/products/2 and it correctly displays record 2:
{"data":{"id":2,"attributes":{"title":"Gillette Razor","price":9.99,"description":"/assets/product-images/product-2.png","featured":true,"createdAt":"2022-08-20T12:23:10.685Z","updatedAt":"2022-08-20T12:29:45.062Z","publishedAt":null}},"meta":{}}
(also works for /1 and /3, showing those products).
But, when I try to see ALL products by typing:
localhost:1337/api/products I get:
{"data":[],"meta":{"pagination":{"page":1,"pageSize":25,"pageCount":0,"total":0}}}
I have given "public" access to "find" and "findOne". Server is running. Why is it not producing a list of the three products entered?
The solution was the data has to be "published" (default is "draft") for the /api/products to show all records, even though the /api/products/x had no issue revealing product x details without being published.
After marking the data as published localhost:1337/api/products now gives me ALL of my products:
{"data":[{"id":1,"attributes":{"title":"razor blade","price":1.99,"description":"/assets/product-images/product-1.png","featured":false,"createdAt":"2022-08-20T12:22:12.498Z","updatedAt":"2022-08-20T15:37:08.598Z","publishedAt":"2022-08-20T15:37:08.597Z"}},{"id":2,"attributes":{"title":"Gillette Razor","price":9.99,"description":"/assets/product-images/product-2.png","featured":true,"createdAt":"2022-08-20T12:23:10.685Z","updatedAt":"2022-08-20T15:37:01.649Z","publishedAt":"2022-08-20T15:37:01.648Z"}},{"id":3,"attributes":{"title":"Barber Razor","price":7.99,"description":"/assets/product-images/product-3.png","featured":null,"createdAt":"2022-08-20T12:23:52.749Z","updatedAt":"2022-08-20T15:36:52.579Z","publishedAt":"2022-08-20T15:36:52.577Z"}}],"meta":{"pagination":{"page":1,"pageSize":25,"pageCount":1,"total":3}}}
I have a form on one page which prompts a user to enter their email address. When they click "next" I want Apex to redirect the user to a different page which shows them a report which selects the records from the users table where the email address matches the one that they entered.
E.g.
SELECT *
FROM USERS
WHERE EMAIL_ADDRESS = (the email address that they entered on the previous page);
Can someone please explain the easiest way to do this?
I have only in the last 5 seconds heard about 'Apex' Lol ... But I think I found what you need to do.
You need to define a 'Branch' which will allow you to POST to whichever page you need to.
Here's some documentation on 'Branches': http://docs.oracle.com/cd/B32472_01/doc/appdev.300/b32469/pdf_report.htm#BABICIJG
Also this snipet may help:
It's [The 'branch'] in the middle (page processing section) of the
development page at the bottom. The branch will be executed whenever a
post submission occurs but you can put conditions on the branch.
Which I found at: http://dbaforums.org/oracle/index.php?showtopic=8139
The "Next" button should not redirect but should submit. The value of the page item has to be pushed to the session state for it to be available in the (apex) session. On submit you can then define a branch which will take you to the page with your report. Your report can then reference the page item by using bind variable notation in the region source:
SELECT * FROM USERS WHERE EMAIL_ADDRESS = :Px_EMAIL_ADDRESS
I have asked this question in the Opencart forums but have yet to receive any responses, so i thought i might ask the experts here #stackoverflow :)
I am trying to see exactly how i can pass the 'quantity' of the items ordered to the success.php page so i can then pass that to another php script that will generate an array based on the quantity.
This is my goal:
Customer Buys 5 items
Customer checks out and processes CC through Paypal Pro
Paypay returns a successful transaction
Now i want the success.php page to pass a variable($quantity) to
myNewScript.php page
myNewScript.php page will generate some random strings and then i
want to attach these random strings to the confirmation email that
opencart generates and sends to the customer.
Where should i start.
You will need to do this in checkout/success controller. Get the $quantity and use redirect function to redirect to your custom page:
$this->redirect($this->url->link('checkout/myNewScript','quantity='.$quantity));
So one of my clients has a request to do rule based static blocks on their home page. The page will basically swap out several static blocks for others based on the perceived gender of the person viewing the site. It will get this data from the session that the user is currently in, or the data associated with the users account. Basically, if a user searches in a specific set of categories (Men's or Women's categories) it should swap the static blocks out on the home page, so when that user visits the site again they will have a more personalized experience. There will be a default set of blocks if the user is new to the site.
Something like this (and excuse my shabby php):
if($categories = $user->getViewedCategories()){
foreach($categories as $category){
switch($category){
case 14: //insert womens category id here
echo $staticBlockWomen
break;
case 16: //insert mens category id here
echo $staticBlockMen
break;
}
}
} else {
echo $staticBlockDefault
}
I know Magento tracks a users path through a site, and I know that other elements in Magento can have rules based on this data (the dynamic banners and checkout rules), but I am really lost on where to get started.
If someone could point me in the right direction, any help would be appreciated!
Cheers,
Matthew
I'm assuming you know the basics of Magento (at least how to create new blocks and how to manage the layout using xml).
If you need more info about that,
You can accomplish what you need in a few steps:
1 - create the blocks you need (create a new module and block classes inside it within the corresponding .phtml files)
2 - from the admin panel, select the category for which you want to add a block and navigate to "Custom Design" tab, then add in the "Custom Layout Update" textarea something like this:
<reference name="content" >
<block type="mymodule/myblock" name="myblock" />
</reference>
This way, every time the selected category is viewed by the custmer, a block of type "mymodule/myblock" will be added in the content area.