How to display two currency in magento cart - magento

I want to display two currencies in Magento's cart and invoice. I have make it in product page by this code
<div class="currency">
<?php if( Mage::app()->getStore()->getCurrentCurrencyCode() == 'USD'): ?>
<span class="price">(<?php echo round(Mage::helper('directory')->currencyConvert( $_product->getFinalPrice(), 'USD', 'AUD'), 2 ); ?>) AUD</span>
<?php else: ?>
<span class="price">(<?php echo round(Mage::helper('di`enter code here`rectory')->currencyConvert( $_product->getFinalPrice(), 'AUD', 'USD'), 2 ); ?>) USD</span>
<?php endif; ?>
</div>
and now I want to display this in the email invoice.

in the email template ti has this line
{{layout handle="sales_email_order_items" order=$order}}
looking up sales layouts we find app\design\frontend[package][theme]\layout\sales.xml
from there you can see the .phtml files used to render the items section of the email, edit the ones you need, keep in mind that these are also used on the front end.
if you want to separate the .phtml files so that the frontend and email template can use different files, copy/paste/rename sales_email_order_items in the .xml file and change the template= parts to the new templates, be sure that in your email template you change the handle stated above to what you renamed the layout to otherwise it'll use the original one.
your code should work fine, you may just need to change $_product->getFinalPrice() if it doesn't work and $_product may not be in the template or be a different class since your dealing with the the collection that deals with sales_flat_order rather than catalog_product

Related

Joomla : render custom fields in search results

Is it possible to display core custom fields in search results ? I can add custom fields in template override for article view like this :
<?php echo $this->item->jcfields[1]->value; ?>
It works fine for com_content but it doesn't display anything in search results (com_search).
Is there a way to render my custom fields in the search results ?
Thank you.
You can create a template overwrite for the com search component like other overwrites by creating a 'html/com_content/com_search/search' folder in your current template.
In this you copy the content of /components/com_search/views/search/tmpl
You can find a description with examples here: https://docs.joomla.org/Customising_the_Smart_Search_results_page
This is targeted at Smart Search (com_finder), however you can follow this by replacing com_finder for com_search.
Then you customize and add the custom fields in the file: default_results.php in your overwrite file.
Please note that the custom fields are a string in the $result object
["jcfields"]=>
string(26) "Custom Field,Search123,1,2"
echo "My fields: ".$result->jcfields;
If you want to do this for Smart Search in Joomla 4, here is the solution.
Create a template override of the file: components/com_finder/tmpl/search/default_result.php
At the start of the file (after line 20), add this code:
// Creates an array with all the CF of the current article.
$articleCustomFields = Joomla\Component\Fields\Administrator\Helper\FieldsHelper::getFields('com_content.article', $this->result, true);
// Creates an associative array using the custom field id as a key.
$articleCustomFields = \Joomla\Utilities\ArrayHelper::pivot($articleCustomFields, 'id');
Then print the custom fields in the page:
<ul class="fields-container">
<?php
// We are using the custom fields with ids 10 and 3
if (!empty($articleCustomFields[10]->value)) : ?>
<li class="field-entry">
<span class="field-label"><?= $articleCustomFields[10]->label ?>:</span>
<span class="field-value"><?= $articleCustomFields[10]->value; ?></span>
</li>
<?php
endif; ?>
<?php
if (!empty($articleCustomFields[3]->value)) : ?>
<li class="field-entry">
<span class="field-label"><?= $articleCustomFields[3]->label ?>:</span>
<span class="field-value"><?= $articleCustomFields[3]->value; ?></span>
</li>
<?php
endif; ?>
</ul>
If you are looking for a complete tutorial, please have a look at:
https://blue-coder.com/help/blog/adding-custom-fields-in-the-search-results

Magento Special price validation

Sorry that I'm a total newbie in magento.
I have a multi-vendor magento site where vendors can create product. But when setting product price some users often do some mistakes. Some times special prices are higher than original price. I like to check this mistake. I want a validation script so that when vendors (who have limited admin access) create a new product then they should keep a minimum difference between special price and original price where special price is always lower than original price.
Can any body give some hints?
Thanks
Hope following code will help you
<?php
$product= Mage::getModel('catalog/product')->load(product_id);
$price = $product->getPrice();
$webprice = $product->getwebprice();
$specialprice = $product->getFinalPrice();
if($specialprice==$price)
{?>
<span>$<?php echo number_format($price,2);?></span>
<?php } else if($specialprice<$price) { ?>
<div>
<span>Regular Price:</span>
<span>$ <?php echo number_format($price,2); ?></span>
</div>
<div>
<span>Web Special:</span>
<span>$ <?php echo number_format($specialprice,2); ?> </span>
</div>
<?php } ?>
Even if the user set special prices more than original price,Magento takes cares of it by not displaying that special price .However if you want to do some customization ,the path for price display is :app/design/frontend/default/default/template/catalog/product/price.phtmlIt would be wise if you copy the structure, paste it on your custom theme and continue with your modification.can add your javascript in list.phtml (same product folder).Hope it gives some hint.

joomla category list override to add id to each list item

I am trying to add a custom style to each list item within Joomla!s Category List output which gives me the following html
<div class="blog">
<div class="cat-children">
<ul>
<li class="first">
<span class="item-title">HYT
</span>
</li>
<li></li>
</ul>
</div>
</div>
I think what I need to do is add something like:
<li id="myID<?php echo $this->item->catid; ?> ">
The trouble is I can't find which file to override. I have looked in /templates/mytemplate/html/com_content/category/ as well as /components/com_content/views/category/tmpl yet none of the files seem to have a an unordered list within them that relates to cat-chidren.
So my first question is which file should I edit? And my second is what is the best syntax of this->item->[correct'Method'?] (is method the correct term or variable, I'm a little shaky on this!) to use so that each list item will have an id="myID[nameofarticle/subcatagory]"
You'll see cat-children in /components/com_content/views/category/tmpl/default.php
The ul is in another loaded subtemplate, loadTemplate('children'); ?> , i.e.
/components/com_content/views/category/tmpl/default_children.php
If you want to modify the li class you could stick something like this at line 26 (of your override not core file - but fine to just test on a core file)
<?php $class = ' class="cmyId' . $this->escape($child->title) . '"';?>
That would make each li appear as
So this
<li<?php echo $class; ?>>
<?php $class = ''; ?>
becomes this
<?php $class = ' class="cmyId' . $this->escape($child->title) . '"';?>
<li<?php echo $class; ?>>
<?php //$class = ''; ?>
Have tested it out on a 2.5 installation.
You should override several files stored in components/com_content/views/
Depending on the list you want to edit, you should then look in the folders:
- article
- category
- categories
- featured
In each of these folders you'll see a subfolder called 'tmpl', inside which there is a 'default.php' file. That's what you're looking for.
If you want to override the files remember that the best practice is to place the alternative files in your template's folder, building a similar path as the one in which the original file is (e.g. for the article folder: templates/YOURTEMPLATEFOLDER/html/com_content/article/default.php - NO tmpl folder needed, nor views folder).
An alternative and, in my opinion, easier way could be setting different templates for each category, and then assigning to each the list styles you prefer.
Or, even easier, you could simply edit your index.php file in the template's folder so that it echoes a specific css stylesheet depending on the $catId.
As your HTML code shows you are using Category Blog view, each article instance in the category is being rendered by blog_children.php file, as it shows /components/com_content/views/category/tmpl/blog.php
<?php echo $this->loadTemplate('children'); ?>
So /components/com_content/views/category/tmpl/blog_children.php is the file you need to edit or override in template html directory.
Then you can apply custom styling adding an id or class for each article with $child->id.

Magento - Limit number of products returned on specific pages?

I have some specific pages I am linking to from this page - http://www.formagdev1.com/shop-online.html
Top of page, New to the store and Customer Favorites both link to custom pages, but we'd like to limit the # of products displayed on those pages. Exclusive is fine, it can return a page with pagination as it currently does.
So if you click on New to the store, you'll get to a page that dumps an array with all the products with pagination. I would like to limit the amount of products on this page to 25, with no pagination. Same with Customer Favorites page.
I am using Grid Mode only, and the code I have currently building the array is -
<?php $_collectionSize = $_productCollection->count(); ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
The issue I am having is, if I just remove the toolbar top and bottom from the custom page, it removes it from ALL list of grid type pages, so the simple idea in this case doesn't seem to be working.
Is there a way to limit the number of products shown to 25 for these 2 specific pages, with NO pagination?
Any ideas?
Thanks!
Bill
Try limit $collection with:
->setPage(1, 25)
But works only if collection not already initialized.
Mage_Catalog_Block_Product_List is the Block that handles the list display. You could add a function here that defines if this is a no pagination category, say function isNoPagination(). You can then edit the catalog/product/list.phtml template to only display the toolbar when !$this->isNoPagination() and set max collection size to 25 when !$this->isNoPagination().
The function isNoPagination could be based on for example getLayer()->getCategoryId().
Thanks for the suggestions everyone. I ended up just doing this using XML in the deisng of the page, workes as I need it to now :-)

How to theme views fields in Drupal 7 correctly

I need to theme views in Drupal 7. There is a content type 'Book' and I need to list 5 books and theme them in special manner(preview image, title and author).
When I override views-view-field.tpl.php and print raw SQL result, I see that all fields are displayed. This code
echo "<pre>";
print_r($row);
echo "</pre>";
gives
[entity] => stdClass Object
(
[title] => ...
....
[nid] => 34
...
[body] => Array
...
But I don't want pass [body] from database to php side, because it can be huge and cause a performance issue. I haven't selected [body] in view settings.
Is there a way to pass only certain fields to views-view-field.tpl.php?
Thanks in advance.
The variables available are written in the documentation inside the sites/all/modules/views/theme folder's files.
Usually, the variable you need to look at and modify on a views-view-fields.tpl.php template is $fields
I use the devel module (http://drupal.org/project/devel) to view the variables available:
<?php
//after enabling the devel module...
dpm($fields);
// This will print a Kuomo display on the page with the array's vars
?>
Generally, on a view of nodes,
<?php print $fields['title']->content; ?>
will print the node title. For fields, try
<?php print $fields['field_FIELDNAME']->content; ?>
If you have the memory, you can capture ALL vars available on the template in the Kuomo with
<?php dpm(get_defined_vars()); ?>
Make sure you clear your cache before you try to view the vars.
If what you want to do is theme a certain field you can create a template for that specific field like this one: views-view-field--field-nameofmyfield.tpl.php place it in your theme folder and rescan the templates in the Theme:information part of the View configuration.
For that to work you have to have the field added to Fields in the View.
To sort through your information in a theme use this:
<?php dpm ($rows); ?> // View all the information in the view
<?php foreach ($rows as $row_count => $row): ?>
<?php print $row['title'];
<?php print $row['nid'];
<?php endforeach; ?>
If you want to change of theme of view then Change views-view-fields.tpl.php like this:
<div class="pagecontent">
<div class="colleft">
<?php if($fields['field_file']->content){ ?><div class="views-field-file"><?php print $fields['field_file']->content; ?></div><?php } ?>
</div>
<div class="colright">
<div class="views-field-title"><?php print $fields['title']->content; ?></div>
<div class="views-field-body"><?php print $fields['body']->content; ?></div>
<div class="views-field-view-node"><?php print $fields['view_node']->content; ?></div>
</div>
</div>

Resources