Fast login form on the right side in magento - magento

I want to add same login form in my site
is there any module available for that or we can have something else coding changes for this
please suggest me something
i want something like this :
http://livedemo00.template-help.com/magento_42632/

You could create a block of type customer/form_login. Using the XML as follows
<block type="customer/form_login" name="customer_small_login" template="customer/form/small-login.phtml" />
You can view the customer/form/login.phtml form for reference of what kind of fields your block is expecting.0
You can then add this to your sidebar using
<?php $this->getChildHtml('customer_small_login'); ?>
NOTE: Ensure your adding you XML block as a child node of the sidebar which you wish to include it in.

Related

Magento getChildHTML from a different class

On the login page's phtml file there is a line that adds the html for a remember me checkbox using: <?php echo $this->getChildHtml('persistent.remember.me'); ?>
I want this same checkbox to also appear in a different part of the website, but when I add this same line to that section's phtml, nothing shows up. I logged out the classes of the $this object in the two files, for the login page its Mage_Customer_Block_Form_Login, and for the other section its Mage_Page_Block_Html_Header.
I'm guessing the difference in classes causes the remember me to not be found in the other sections call to add it. Is there any way to add this remember me html to this page even though their $this classes are not the same?
You can use following code in place of your code
$this->getLayout()->createBlock('persistent/form_remember')->setTemplate('persistent/remember_me.phtml')->toHtml();
Or add following code to add block in your page's handle to use your same code with $this
<block type="persistent/form_remember" name="persistent.remember.me" template="persistent/remember_me.phtml" />

Magento 2 Load specific attribute on front end

I'm trying to modify the product page. I know what files I need to change, however I can't seem to work out what specific thing I need to do.
How do you load a specific attribute to display on the product page? I want a specific one to appear in a more prominent position than the "More Information" tab.
I can sort out the styling and layout stuff, I just need to know how to grab a specific attribute.
Additional question: I've set one up as "Image Swatch". Is there a way to get it to display the image on the front end (it only seems to images when it's a product option).
Best way - Create a block
You can edit the relevant XML file to create a block and position it where you need it. You can add a container (a div with a specific class) if you need to;
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.sku" template="product/view/attribute.phtml" after="product.info.type">
<arguments>
<argument name="at_call" xsi:type="string">getSku</argument>
<argument name="at_code" xsi:type="string">sku</argument>
<argument name="css_class" xsi:type="string">sku</argument>
</arguments>
</block>
In the phtml template
If your working inside a phtml template you co do the below;
<?php $_product = $block->getProduct(); ?>
<?php echo $_product->getAttributeText('size');?>
Reference
http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html#xml-manage-block
If anyone has a better way it would be interesting to find out.
You can also load attribute in custom template by:
<?php /* #escapeNotVerified */ echo $product->getResource()->getAttribute('my_attribute_id')->getFrontend()->getValue($product); ?>

Call magento template via $this->getChildHtml()

I have a contact form template (modal.phtml), which I want to add to all pages on my site, but I need to be able to position it precisely, so I want to insert into the relevant page templates using $this->getChildHtml('contacts-modal'), instead of inserting via layout xml. So in page/2columns-right.phtml, I want to use that call to insert the template stored in contacts/modal.phtml. The layout xml i have below is automatically inserting this template - how do i go about correcting this? Thanks for any pointers, and apologies if this is a very basic thing!
<reference name="content">
<block type="core/template" name="contacts-modal" as="contacts-modal" template="contacts/modal.phtml"/>
</reference>
If you want to insert the template with $this->getChildHtml('contacts-modal') you have to declare it in the layout xml, look into the class Mage_Core_Block_Abstract to see how getChildHtml works.
If you want to add it to other pages that don't have 2columns-right as main template, you have to add the xml reference like you did with 2columns-right, or you can use inside the parent template echo $this->getLayout()->createBlock('core/template')->setTemplate('contacts/modal.phtml')

Magento: overriding frontend phtml files without placing in default/default

I have a custom info.phtml file which is already working if placed at app\design\frontend\default\default\template\sales\order\info.phtml.
However, I do not want to use this approach since this is part of a module, so if later someone else overrides this file it'll brake the functionality. I've read about using custom blocks but I tried many different approaches without success.
Actually, the path you cite will only work when the theme package is set to default. The intended fallback theme for all files since CE1.4 is base/default. There's quite a lot to consider here, so let's break it down. Of course, being the end implementer of a Magento instance is luxurious because you can use any number of customization options without worrying about how to support other developers' needs. However, when developing a third party module for release to/consumption by others (as you are, it seems), then you have some tough decisions to make if you wish to ensure that output is modified in the way which your module intends/needs. Let's look at the template you mention, which is part of the means by which output is generated. This example contains several of the factors involved in the generation of output.
app/design/frontend/base/default/template/sales/order/info.phtml:
<?php $_order = $this->getOrder() ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title title-buttons">
<h1><?php echo $this->__('Order #%s - %s', $_order->getRealOrderId(), $_order->getStatusLabel()) ?></h1>
<?php echo $this->getChildHtml('buttons') ?>
</div>
Are you in the right place?
The first question to ask is, "What do I need to change, and where?" If the answer lies in the output of a child block (e.g. the output of $this->getChildHtml('buttons')), then customizing the output means specifying an alternate child (with multiple possibilities for customization). If not, then the change is likely local to the template/block environment.
Is the change entity-related?
For third-party devs, the ideal solution is to avoid theme-dependent output whenever possible. For example, if you needed to change or add to the data available directly from one of the constituent objects, it is possible to modify that object or its behavior via Magento's configuration XML using configuration-based rewrites or via the event-observer architecture. In the current example, $this->getOrder() is an instance of Mage_Sales_Model_Order, $this is an instance of Mage_Sales_Block_Order_Info, and it is possible to rewrite either of these to a different class. Also, the sales_order_load_after method can be observed to modify properties of the order object.
Can translations be used?
If there is a need to modify just a string, it is often possible to effect this change via Magento's translation functionality. In a template, any string rendered via the __() method is passed through translation. This is very easy to modify for the end-implementer in a theme-specific translate.csv file. For third-party developers a little configuration XML allows to specify an additional translation CSV file, even for a core module.
Am I stuck with markup?
If there is a need to change the view markup being presented, it's necessary to modify the source of the markup, which most often is a template file. This can be effected in a couple of ways. In the case of the order info block, the sales/order/info.phtml template is defined in the Magento constructor:
class Mage_Sales_Block_Order_Info extends Mage_Core_Block_Template
{
//snip...
protected function _construct()
{
parent::_construct();
$this->setTemplate('sales/order/info.phtml');
}
//snip...
}
This usually means that there is no specified template in layout XML. The next step is to determine if the block is in fact instantiated via layout XML or in the controller. In the case of the latter, there's no way to manipulate the block via layout XML, so you'll need to use one of many possible Magento/PHP options to change the _template property. If the block is instantiated via layout XML, great - it's easy to specify some custom layout XML to point to an alternate template which will not be present in any theme; you just need to know the handle(s) and names which the block has been given, which can be determined by searching for the block instantiation markup (e.g. search *app/design/frontend/* for type="sales/order_info". This will lead you to *.../base/default/layout/sales.xml*:
<sales_order_view translate="label">
<label>Customer My Account Order View</label>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="sales/order_info" as="info" name="sales.order.info">
<block type="sales/order_info_buttons" as="buttons" name="sales.order.info.buttons" />
</block>
<!-- etc. -->
It's possible to then use the handles and names to update the block's _template property in your module's custom layout update XML file, e.g.:
<sales_order_view>
<reference name="sales.order.info">
<action method="setTemplate"><tpl>my/custom/template.phtml</...>
<!--
Instead of <reference> you can use the 'block' attribute:
<action method="setTemplate" block="sales.order.info"><tpl>my/custom/template.phtml</...>
-->
This would allow you to put your custom template in the base/default template directory, where it belongs. However, you'll notice that this block is instantiated in a number of handle:
You might want to use a utility handle and <update /> directive to encapsulate the instructions into one place and provide it to all of the stock handles.
Nothing's foolproof!
This is one of several approaches, but it's not foolproof. Depending on your extension consumer audience, you might want to scan layout XML and template directories for customizations of/changes from the stock template and provide a notice to the admin.
If you need your custom info.phtml as part of a module, then declare it in module's xml. Then you can place your custom phtml file in app\design\frontend\whatever\somethingelse\template\sales\order and it will override it. For example, see this thread about how to override existing template file.
This is done from layout xml of your module.
Just put the code below in your layout xml with needed changes as per your namespace, module and controller action which call that file:
<checkout_onepage_index>//Use correct Controller action
<reference name="checkout.onepage.payment">//Change reference name as per your need
<action method="setTemplate">
<template>giftcard/checkout/onepage/payment.phtml</template>//Path of phtml file in yourmodule template folder
</action>
</reference>
</checkout_onepage_index>

Setting canonical tags for categories in Magento

Is this possible, or is there some code that can be added so I can set a different canonical URL for categories in Magento? I can set for products fine.
Just found this question while searching for info about canonical URL support.
I'm not sure which version added this (couldn't find anything in release notes), but it is now supported out of the box in 1.7.0.2.
In admin: SYSTEM >> CONFIG >> CATALOG >> SEARCH ENGINE OPTIMIZATION
Last two options enable canonical URLs for categories and products.
Out of the box there is nothing for this that I am aware of. You will need to develop or build your own method of doing this.
You will need to create an entry in a layout.xml file to put an additional template in the head section of the page when you are on a category page (this would likely be in a catalog_Category_view block). You would also probably need a view file as well as a Block object to fetch the URL you want to use (technically you could put that in the view file, but having the block object is more "Magento").
Your layout.xml block would look something like this
<catalog_category_view>
<reference name="head">
<block type="canonical/canonical" name="head_url" as="head_url" template="ocaff/canonical/head.phtml" />
</reference>
</catalog_category_view>
This block references a head.phtml file. That file would contain:
<link rel="canonical" href="<?php echo $this->getCanonicalUrl() ?>" />
This calls back to a block object that has a function called getCanonicalUrl(). In this function you will find and determine what you want the canonical to be. Most likely you want this to be the URL key, but you may have other logic in mind there.
Canonical urls for product and category pages are supported by Magento from 1.5
In admin: SYSTEM >> CONFIG >> CATALOG >> SEARCH ENGINE OPTIMIZATION

Resources