Magento custom shipping module translations - magento

I created a custom shipping module which is working.
I want to set the 2 texts displayed on the checkout page to come from a translation file.
config.xml
<default>
<carriers>
<starmall>
<active>1</active>
<model>Starmall_Shippingcost_Model_Carrier_Starmall</model>
<title>Carrier Title</title>
<name>Method Name</name>
<price>0.00</price>
<specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
</starmall>
</carriers>
</default>
Admin screen:
Checkout frontend screen:
QUESTION: I want to set the "aaa" and "bbb" texts in code to come from a translation file.
I can set the "aaa" text in code using
$method->setMethodTitle(Mage::helper("starmall_config")->__("Starmall_shipping_method_title"));
Which then displays this:
How can I set the "bbb" text in code?
The following does not work:
$method->setCarrierTitle("xxxxxx");
$method->setTitle("xxxxx");

Yes use translation function !
$method->setCarrierTitle( Mage::helper('core')->__('string1') );
$method->setTitle(Mage::helper('core')->__('string2'));
Then add this string to your translation CSV file !

Related

How can I show custom attribute value as menu item label in magento 2?

I have created a custom attribute for menu title on category add/edit page in my magento 2 setup. I want to show the value of the attribute saved in database instead of the category title on main menu. How can I do this. Please help
I was searching online and didn't find any exact solution to my problem.
You need to code in the frontend theme and also in your module to display your display custom attribute on the placement of the category title.
Custom/Module/view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.view.container">
<block class="Magento\Catalog\Block\Category\View" name="category.heading" template="Example_CategoryHeading::category/heading.phtml" before="category.description"/>
</referenceContainer>
<referenceBlock name="page.main.title" remove="true"/>
</body>
</page>
Turn on the Template path hints and find the phtml file, where you can find the file location attribute to display in the menu title. Remember to override your custom theme or module.
For Template path hints:
On the Admin sidebar, go to Stores > Settings > Configuration.
In the left panel, expand Advanced and choose Developer.
Expand Expansion selector in the Debug section and do the following:
To get the category attribute:
$categoryId = 3;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
echo $category->getName();
echo $category->getData('<attribute_code>');
Remember, object manager is not recommended.
In the app/design/frontend/theme vendor/themename/Magento_Catalog/layout/ folder, the file catalog_category_view.xml is responsible for displaying the title. In this xml file, the setPageTitle action method is used, and you can override the category default title according to your requirement.

How to add custom content on Magento Catalog page under each product name?

I have created a custom module that attaches some information to each product. Now, I want to show the custom information on Catalog page under product name.
Here is snapshot to show you what I am trying to do.
Here is my layout xml
<?xml version="1.0"?>
<!--
/**
* Custom module
*/
-->
<layout>
<catalog_category_default translate="label">
<reference name="name.after">
<block type="catalog/product_list" name="custom_content" template="custommodule/default.phtml"/>
</reference>
</catalog_category_default>
</layout>
But this is not working. Is it possible to render custom content under product name without modifying any .phtml files?
Many Thanks!
I'm aware that this is a quick and dirty hack that more diligent magento devs will sneer at, but it will give you the result you want and is easy for you to impliment
The 'correct' solution probably involves writing a custom block and calling it in the foreach loop of your app/design/frontend/YourPackage/YourTheme/template/product/list.phtml - however, I can offer you a quick and dirty hackaround that shouldn't tax you too much. You can do it very easily by abusing the product attributes system.
First create a new product attribute in the attribute set used by your product.
We'll use this to store the custom content we want to inject between your product name and price. For the sake of this example we'll call it customcontent. Make sure you set the attribute's Visible on "Product View Page on Front-end" value to 'No'.
Edit your product and set this new attribute equal to your desired custom content - it's fine you use html tags in here too. By default, product attributes have (for some reason) an arbitrary limit of 30 characters but if you need it to hold a longer string you can easily change this by editing app/code/mage/eav/model/entity/Attribute.php and changing the value of ATTRIBUTE_CODE_MAX_LENGTH.
Then in your app/design/frontend/YourPackage/YourTheme/template/product/list.phtml and find the following line of code somewhere around line 49
<?php foreach ($_productCollection as $_product): ?>
directly after it insert the following:
<?php $_customcontent =$_product->getResource()->getAttribute('customcontent')->getFrontend()->getValue($_product);?>
You've now stored the string from your products customcontent attribute in a variable called $_customcontent
So if you find the following line in your list.phtml
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></h2>
you can easily add a new paragraph or heading beneath it and populate it with your custom content using
<?php echo $_customcontent ?>
I know this probably represents a deeply unorthodox solution, but it does work and can be acheived very quickly, and without requiring you to know anything about writing your own custom blocks.
Can you try :
<catalog_categoryd_default>
<reference name="content">
<block type="catalog/product_list" name="custom_content" template="custommodule/default.phtml" after="nameofTheNameBlock"/>
</reference>
</catalog_categoryd_default>

magento $this->getCurrencies() can't work?

i put the code in my theme header.phtml
echo $this->getCurrencyCount() and $this->getCurrentCurrencyCode() both of them are no any output. but i have set 4 currencies for the site.
but in the same file, $this->getWelcome() have the right output.why?
when i echo Mage::app()->getStore()->getCurrentCurrencyCode(); in the file ,it has a value. thank you.
if i want to output the currency switcher. how do i do?
These function are from the Mage_Directory_Block_Currency model, not the Mage_Page_Block_Html_Header one.
You might look at the directory/currency.phtml file to handle this kind of task
IF you want to determine the best position in the page thanks to the header.phtml file, just define this block as a child of the header one.
In your theme layouts, in directory.xml, in the <default> area add this :
<reference name="header">
<block type="directory/currency" name="header_currency" before="catalog.leftnav" template="directory/currency.phtml"/>
</reference>
Then in the header.phtml file just add echo $this->getChildHtml('currency'); where you need it to show.
If you just need these variables without showing the currency block use in your header.phtml this code
$currency_block = new Mage_Directory_Block_Currency;
$currency_block->getCurrentCurrencyCode();
The last part is provided as is and is untested.

How to order item is displayed on the page of the Checkout / Onepage / Success

Magento Checkout process, the payment of page generally have this information:
===========================================
Your the order has been received.
Thank you for your purchase!
Your the order # is: 100 000 018.
You will receive an order confirmation email with details of your order and a link to track its progress.
Click here to the print a copy of your the order confirmation.
===========================================
If you want to increase the order item information, such as:
===========================================
The Items the Ordered
Product Name SKU Price Qty Subtotal's
ProductXXX XXX NT $ 543 1 NT $ 543
Subtotal's NT, $ 543
Shipping & Handling NT $ 5
The Grand the Total NT $ 548
===========================================
May I ask how to use the module to be completed?
I currently known, there are three major difficulties
Checkout to pay the shopping cart is empty
Checkout and Order screen (sales_order_view) is a different category
Success_checkout_Onepage, layout phtml is specified via XML, and may not be able to change the override to
I hope you can help me
Thank you
Hope it will help someone else, as I'm replying quite late.
Bought product order grid is similar to "checkout cart", "checkout review" and "account my order". The grids can be displayed at checkout success page.
All necessay steps are given in this link.
Thanks,
Kashif
The better way is create own module where rewrite standart action of Magento.
First of all rewrite success.phtml file (into your frontend layout file):
<checkout_onepage_success translate="label">
<reference name="content">
<reference name="checkout.success">
<action method="setTemplate"><template>your_module/success.phtml</template></action>
<reference>
</reference>
</checkout_onepage_success>
Rewrite Mage_Checkout_Block_Onepage_Success (into config.xml file of your module):
<global>
<blocks>
<checkout>
<rewrite>
<onepage_success>Your_module_name_Block_Success</links>
</rewrite>
</checkout>
...
Then we have to create this block (into our module) that should be exdends from Mage_Checkout_Block_Onepage_Success, example:
class Your_module_name_Block_Success extends Mage_Checkout_Block_Onepage_Success
{
// Write here only your methods example get last order's products
// All parent's methods also will work
}
Then you will describe method for getting products from order and execute it into your phtml file (see above).
Tip: copy html from original file (all will be working) and then customize it.

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