Import button + File browse field in admin product grid in magento - magento

I want to add an Import button and a file browse button next to the Add Product button in the product grid page in magento admin.
When the user choose a file and clicks the Import button
I'll upload the file to var/import, open a new tab and run the import profile.
How can I add the form (import button + file browse field) to the top of the grid?
Thanks

Use XML Layouts to set your custom template for product grid container block and add your custom form block there. You need to extend adminhtml_catalog_product_index layout handle for that:
<adminhtml_catalog_product_index>
<reference name="product_list">
<!-- Set your custom template -->
<action method="setTemplate"><template>path/to/your_template.phtml</template></action>
<!-- Add your custom block -->
<block name="import_form" as="import_form" type="your_module/form_block_name"></block>
</reference>
</adminhtml_catalog_product_index>
Then you need to define your block and template. Your custom block should be extended from Mage_Adminhtml_Block_Widget_Form and template should be a copy of adminhtml/default/default/template/catalog/product.phtml but with modifications to display your custom block, like in the following example:
<div class="content-header">
<table cellspacing="0">
<tr>
<td style="width:50%;"><h3 class="icon-head head-products"><?php echo Mage::helper('catalog')->__('Manage Products') ?></h3></td>
<td class="a-right">
<?php echo $this->getButtonsHtml() ?>
</td>
</tr>
</table>
</div>
<!-- Start of Displaying of your custom import form -->
<?php echo $this->getChildHtml('import_form');?>
<!-- End of Displaying of your custom import form -->
<?php if( !$this->isSingleStoreMode() ): ?>
<?php echo $this->getChildHtml('store_switcher');?>
<?php endif;?>
<div>
<?php echo $this->getGridHtml() ?>
</div>

you can use Mage_Adminhtml_Block_Widget_Container::addButton() to do this. Search magento's code for calls to this function to see how it should be used, create your own container block, replace magento's container block for the product with it by using a layout file and you're done.

Hi
thats right use Mage_Adminhtml_Block_Widget_Container::addButton() method & here is the syntax
$data = array(
'label' => 'Import Zipcode Data',
'onclick' => "setLocation('".$this->getUrl('*/*/import')."')"
);
$this->addButton ('import_zip_code', $data, 0, 100, 'header', 'header');
of course u can have any label & id of button that u want. setLocation allows u to set the target where u want to go when u click on this button.

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

October CMS - sorting records - example of the partial for the toolbar icons?

I'm excited that the October CMS recently added back-end functionality for sorting records in the list view. But I'm having some trouble getting it to work. The documentation is here. I've followed the direction like so:
In my controller, I implemented the ReorderController:
<?PHP namespace BTruchan\Team\Controllers;
use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Classes\Controller;
use System\Classes\SettingsManager;
class Members extends \Backend\Classes\Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.ReorderController'
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public $reorderConfig = 'config_reorder.yaml';
public $requiredPermissions = ['btruchan.team.manage'];
public function __construct()
{
parent::__construct();
BackendMenu::setContext('BTruchan.Team', 'team');
}
public function index()
{
$this->makeLists();
$this->makeView('reorder');
}
}
?>
I've created the reorder view file (reorder.htm) which contains:
<?= $this->reorderRender() ?>
My config_reorder.yaml file contains:
# ===================================
# Reorder Behavior Config
# ===================================
# Reorder Title
title: Reorder Members
# Attribute name
nameFrom: name
# Model Class name
modelClass: BTruchan\Team\Models\Members
# Toolbar widget configuration
#toolbar:
# Partial for toolbar buttons
# buttons: reorder_toolbar
You'll notice that the reorder_toolbar partial is commented out. That's because I really don't know what's supposed to go in that toolbar. I haven't been able to find any documentation that shows the contents for the _reorder_toolbar.htm file.
Unsurprisingly, with the code commented out, it throws an error:
Undefined variable: reorderToolbarWidget
Some additional information:
It was suggested that I read up on list toolbars here.
So I added the following toolbar partial (named _reorder_toolbar.htm):
<div data-control="toolbar">
<a
href="<?= Backend::url('btruchan/team/members/create') ?>"
class="btn btn-primary oc-icon-plus">
New Team Member
</a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="Delete Team Member: Are you sure?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', false)"
data-stripe-load-indicator>
Delete
</button>
</div>
But I'm still getting an error:
Undefined variable: reorderToolbarWidget
/var/www/terrasearch/public/modules/backend/Behaviors/reordercontroller/partials/_container.htm
line 1
The code, in October CMS, which that error message is referring is:
<?php if ($reorderToolbarWidget): ?>
<!-- Reorder Toolbar -->
<div id="<?= $this->getId('reorderToolbar') ?>" class="reorder-toolbar">
<?= $reorderToolbarWidget->render() ?>
</div>
<?php endif ?>
<!-- Reorder List -->
<?= Form::open() ?>
<div
id="reorderTreeList"
class="control-treelist"
data-control="treelist"
I've tried to trace this error down. It seems like, in \public\modules\backend\behaviors\ReorderController.php, the reorder() function is not being called, which means that the prepareVars() function is also not being called. This prevents the following code from being executed:
$this->vars['reorderToolbarWidget'] = $this->toolbarWidget;
ReorderController.php:: makeToolbarWidget() is being called and seems to be OK. I've checked $this->toolbarWidget, and it seems to contain perfectly good data. (It isn't NULL).
The ReorderController is a behavior, so it's meant to be called as a controller destination (e.g. example.com/backend/btruchan/team/members/reorder). It's not coded to be called as a view the way you have it in your index function.
In the ReorderController source, the reorder function is the only method that calls the prepareVars protected function which is the only place that the reorderToolbarWidget is defined for the page. That prepareVars function isn't available from the host controller.
So, rather than try to create a view with $this->makeView('reorder');, create a toolbar button in the _list_toolbar.htm partial that points to the reorder destination url. For example:
<div data-control="toolbar">
New Member
Reorder Members
</div>
When you click on the "Reorder Members" button, you'll be directed to a new page with the records that can be reordered.
You can use the _reorder_toolbar.htm partial to add anything you want at the top of the reorder page. Or, not use it at all.

How do I remove all of the pages only the top toolbar in Magento

How do I remove all of the pages only on the top toolbar (Toolbar 1) in Magento?
Another way to change top toolbar template from product listing.
Instead of:<?php echo $this->getToolbarHtml() ?>
Replace it with this:<?php echo $this->getToolbarBlock()->setTemplate('catalog/product/list/toolbar-top.phtml')->toHtml(); ?>
Create new template as toolbar-top.phtml and comment pager code snippet.
Both the toolbars are coming from same Phtml file : catalog/product/list/toolbar.phtml.
In your list.phtml, there are two calls for
<?php echo $this->getToolbarHtml() ?>
You can remove any of the one to remove.
If you want to have different toolbars for both up and bottom, replicate toolbar.phtml to toolbarup.phtml & toolbarbottom.phtml. DO the changes as you wish and replace the toolbar.phtml in layout/catalog.xml with 2 entries of your custom toolbars.
You can do this by modifying catalog/product/list.phtml and catalog/prodct/list/toolbar.phtml from your theme.
First, the changes in catalog/product/list/toolbar.phtml.
Wrap the div with class pager in this if statement (the full div element not just the tag opening line):
<?php if (!$this->getHidePager()) : ?>
<!-- <div class="pager"> here -->
<?php endif;?>
now in catalog/product/list.phtml replace this line at the top of the file:
<?php echo $this->getToolbarHtml() ?>
with this one:
<?php echo $this->getToolbarBlock()->setHidePager(true)->toHtml();?>
and the same line at the bottom of the file with this one:
<?php echo $this->getToolbarBlock()->setHidePager(false)->toHtml();?>

Joomla 2.5 frontend pagination clicking on next button not working

I am using joomala 2.5 and developed my own component for showing table data in front end and added pagination. I'm getting pagination links, after clicking on the links 'next', 'prev' nothing happens.
What may be the problem?
In view.html.php I've added
$this -> pagination = $this->get('Pagination');
In default.php I've added
<div class="pagination">
<?php echo $this->pagination->getListFooter(); ?>
</div>
You haven't mentioned what you have done in you components model file. My advoice to you is just read this document carefully http://docs.joomla.org/J1.5:Using_JPagination_in_your_component & you will be easily apply pagination. The doc is perfect & its very simple to use pagination in Joomla.
Thank you.
Put your pagination buttons inside a tag and make sure the action url points to the same view (e.g. action = 'index.php?option=com_component&view=listview')
<form action=""...>
<div class="pagination">
<?php echo $this->pagination->getListFooter(); ?>
</div>
</form>

Magento shows attribute if value is left blank

I have a drop down magento attribute for warranty_labour. I'm pulling in the attribute using my themes product/view.phtml and then attaching an icon to show what warranty you get.
Ive used this code which successfully works:
<?php $warranty=$_product->getAttributeText('warranty_labour'); echo '<img style="padding-top: 10px;" src="/images/warrantylabour/'.str_replace(' ', '_',$warranty).'.png" alt="'.$warranty.'">'; ?>
The problem I find when a product doesn't have a warranty attribute set (left blank on the backend) I still get the code inserted on to the product source code on the frontend like this:
<img style="pad`ding-top: 10px;" src="/images/warrantylabour/.png" alt="">`
Is there a way I can stop this happening when a value isn't set in the attribute?
Don't forget logic! :-) Just test that $warranty has a value Using typical Magento template conventions:
<?php if($warranty=$_product->getAttributeText('warranty_labour')): ?>
<?php echo sprintf('<img style="padding-top: 10px;" src="/images/warrantylabour/%s.png" alt="%s"/>', str_replace(' ', '_',$warranty),$warranty) ?>
<?php endif; ?>
This kind of syntax might justify encapsulating this logic and string building into a helper method, I think.

Resources