Magento How to display the search results from search query in a custom page - magento

In magento,
I would like to display the products retrieved from the search query in a custom pages.
By default these products are displaying in catalogsearch/result/?q="some text".
I would like to restrict this redirection and these search results have to be displayed on my custom pages (say index.php itself).
Can any one provide me the solution for this?
Thanks in advance
Mani

Go to
\app\design\frontend\default\your theme\layout/catalogsearch.xml
in line no 52:
<action method="setTemplate"><template>page/3columns.phtml</template></action>
change into:
<action method="setTemplate"><template>page/{YOUR PHTML FILE}</template></action>

You can do this via jQuery ajax request.
Onclick operation over the search button send the request to
catalogsearch/result/?q="some text"
You need to replace the entire html because on search we are getting entire magento search page(Not feasible)
OR
Create a custom module and override catalogsearch.xml remove header footer left and right navigation section and set body only.
This will do the job!!! Its working for me.
NOTE:CUSTOM MODULE DEVELOPED CAN BE USED TO OVERRIDE BLOCK,CONTROLLER ACTION AND ALSO WE CAN CHANGE AS PER REQUIREMENT

Related

where i can change the words of Newsletter in Magento2

i am very new of Magento2, I saw in the "page" that this form should be used to call out the newsletter form :
{{block class="Magento\Newsletter\Block\Subscribe"
name="static.newsletter"
template="Magento_Newsletter::subscribe.phtml"}}
But I would like to change the words of this form, or add more words there. I have already tried looking for in the system but didn't find it and I dont know where to change it. Does anyone can help ?
There are 2 approaches for changing words inside that form.
If you want to change this form for everywhere on your Magento system, you can override it inside your theme.
app/design/frontend/[Vendor]/[Theme]/Magento_Newsletter/templates/subscribe.phtml
If you want to change this form to a specific page, you can create your own template and assign it.

Is it possible to identify file name passing url in magento?

How to identify coding having this file at magento .
For example,
Link Mean
how to identify which file its denotes ?
http://localhost/index.php/about-magento-demo-store/ is not a file, it's CMS page content which is actually a row stored in the cms_page table in your database that gets filtered through a template to produce html page content that is pushed to your browser.
Look under the CMS=>Pages menu, you'll find a grid and if you search in the url key column for about-magento-demo-store, you can find the page content there.
Magento's content does not exist as static pages, it is data stored in the database that gets selected, filtered through templates and assembled into HTML that gets final styling from CSS. It only becomes a page, once it is downloaded by the web browser.
1)Url redirects
look at the core_url_rewrite table and find the url that you requested.
if you find it, and target path starts like catalog/category/view/id/5,
that means catalog module, category controller, view action which you can find in
app/code/core/Mage/Catalog/controllers/CategoryController.php the method is viewAction.
2)Cms Pages
it can be a cms page
3)One of modules controller
It is the best way to install a profiler and see which controller handles your request.

How to include hooks in CMS pages?

I've created a custom hook, so that I can include my custom module in any .tpl file by a single line: {hook h='calcSubstrate'}.
However, I can't use it in CMS page, at least not by using the admin panel - including smarty code in a CMS page won't render, the code would appear just as it is, as a text: {hook h='calcSubstrate'}.
Alternatively, if that would be easier/faster - how can I choose on which pages my module would appear?
The editor for CMS page won't recognize any Smarty code. To include hooks in chosen articles/pages, I can think of two options:
Include the hook in the template (cms.tpl), and check for the id of the current page to conditionally display the module. The list of the page ids can be made as the module's configuration.
Build a module to add functionality similar to Wordpress's shortcode to the CMS content. I do this with module instead of overriding the CmsController class, hence I have to display the content with {$cms->content|module}. You can look at the simplified code here for inspiration: https://gist.github.com/tungd/cef0ca1ac1063c1ee90b. Of course you can make it more generic like Wordpress, by having only one Smarty modifier do_shortcode that does everything (just like Wordpress's do_shortcode function).
Last time I did this it was because my client want to put slideshows in some CMS pages, and I chose the second approach because it gives a lot of flexibility about when the module is displayed and where it is displayed between the content. For something else, for example Contact Form, or Map, this would be overkill and the first approach is better.

Custom e-commerce tracking code for Magento

Which file do I need to add custom e-commerce tracking code to in Magento?
Knowing that will give me a good start because Magento is huge and do not know where to start.
Once I know the correct file I need to add javascript into the checkout completed page, the javascript will be interjected with some values
items bought
total cost
cost / item
etc
The javascript I have and can handle just fine, its the Magento bit I am struggling with;
Where should I add this javascript?
Once I find this file can I easily output the transactions details the javascript tracker requires.
Note that the javascript is for https://www.gosquared.com/
I think you have to add this script in success.phtml from checkout/success.phtml in this file you got $order object and you get all information from this object like your transaction id,product information just like ex.
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$transactionid=$this->getOrderId()
foreach ($order->getItemsCollection() as $item)
{
$item->getData();
$proidcol[]=$item->getData('product_id');
$pronamecol[]=$item->getData('name');
$proqtycol[]=$item->getData('qty_ordered');
$productpricecol[]=$item->getPrice();
}
in this $pronamecol you can get all product name array from order and then implement this in java-script code using for loop ,,I think you can easily do that
1 To add the javascript to the success page, you can use this in your layout local.xml file:
<checkout_onepage_success>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/path/to/file.js</name></action>
</reference>
<checkout_onepage_success>
Instead of head, you could also use before_body_end (so the javascript gets added at the bottom of the page).
2 Can't tell for you at the moment, what information does your javascript need? Do you need to add information to it manually?

Magento - How to swap the add to cart form to my own form

I am writing a module that hides the add to cart button and price (product view) and displays a short form (contact us kind of thing) in its place (based on a product attribute).
Because there is a form that wraps up most of the important info on the product view page I can’t simply inject my own phtml file with its own form because that would leave nested forms.
So it now looks like I have to override the entire catalog/product/view.phtml file with my own just to change the form action. Like so:
<catalog_product_view>
<reference name="product.info">
<action method="setTemplate">
<template>mycompany/mymodule/catalog/product/view.phtml</template>
</action>
</reference>
</catalog_product_view>
Then within my view file I change the form action accordingly.
$formAction = $this->getSubmitUrl($_product);
if($_product->getData("myattribute")){
$formAction = $this->getBaseUrl().'mycontroller/';
}
<form action="<?php echo $formAction ?>" ...[snip]
This seems like massive overkill just to change a forms action.
The way I see it I have 2 options:
1) Add some javascript to my submit button onclick event that changes the default form action to go to my controller. This way hijacking the add to cart form. (But this will have issues if javascript is disabled)
2) Have an observer that checks every single add to cart event to see if it needs to add to the cart or should process my form instead. (The form will be displayed on the product page if needed)
(At the moment I’m not thinking about integrating with custom themes etc…I just want to get my head around one thing at a time! - Well ok, maybe one eye on custom themes..)
Can anyone suggest a better or more efficient way to achieve this? Or if not which option would you recommend, 1 or 2?
Thanks
In my opinion, the massive overkill method sounds like the best route to go. You get the change in form action that you wanted and it looks to be Magento friendly.
If you really don't want to do that, then I would recommend going with option two. You do not want to rely on the entire internet having Javascript enabled when they visit your site (the overall percentage of people who have this disabled will be very small, but they could be a massive thorn in your side).

Resources