I wrote a custom payment module. It seems to be working fine but I can't show the method form in the checkout process. I mean: I see my method, I can select it, but can't see the form.
I want to show a select box with a couple of options but no form is rendered.
app\code\local\Neurona\Sistarbanc\Block\Form\sistarbanc.php
class Neurona_Sistarbanc_Block_Form_Sistarbanc extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/form/sistarbanc.phtml');
}
....
And the form in app\design\frontend\base\default\template\payment\form\sistarbanc.phtml
Any help will be appreciated!!
EDIT
So, it seems to be working in the default ckeckout process but not in the onestepcheckout
EDIT 2
I found that in onestepheckout this is the way the payment method form is rendered:
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd id="container_payment_method_<?php echo $_code; ?>" class="payment-method" <?php if(!$this->getSelectedMethodCode()==$_code || !($hide_nonfree_methods && $_code == 'free')): ?> style="display:none"<?php endif; ?>>
<?php echo $html; ?>
</dd>
So, for my method $this->getPaymentMethodFormHtml($_method) is FALSE. ¿why?
Your template filename is Sisterbanc.phtml, but your block will try to load sisterbanc.phtml (uppercase "s" vs lowercase "s").
Maybe you need add this line in Model/Payment.php.
protected $_formBlockType = "sistarbanc/form/sistarbanc"
I don't know the reason why though. I compared with other payment module code, and got this.
Related
In Joomla Page heading showing inside of an article I want to change the position of page heading, is it possible to customize page heading position?
I had included following code in template/protostar/index.php
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif;
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && $this->item->paginationrelative)
{
echo $this->item->pagination;
}
?>
What you can do:
Just update one of the css files in the correct template to display the header correctly. If the header should only be reformatted on some pages and not all then you should be using different templates.
What you should do:
Otherwise (if you want to change the php instead) you can override the components/com_content/views/article/default.php using the standard joomla override method.
You can do both the above if necessary.
You should not need to override the index.php of your template in order to do this. However if you really want to i would use the code
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
}
Sorry if you want more you need to give more :)
PS. I am on joomla 2.5 but i know that for joomla 3 it is more or less the same thing.
Sources: http://forum.joomla.org/viewtopic.php?t=525350
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
does anyone know how do I include a block information when selecting a payment method in my checkout page? within that block I want to insert an html(image) from the payment gateway that I'm using.
I've tried to do this using jquery inserting the html needed when the page loads, the image appears quickly but some update in the layout of the checkout page removes the image, ie, it appears and disappears soon after.
I am very new to magento and any help would be welcome, thanks
I´m using magento 1.8.1
I assume that you are referring to the right blocks which output the checkout progress ( see below if you are referring to the actual payment method selection step ).
You don't need to do any client side scripting. Magento supports that by default.
Checkout progress ( right blocks on checkout page ):
You need to follow these steps:
Open your Payment Method model.
Add the following code:
protected $_infoBlockType = 'mymodule/info';
The block code should look like:
<?php
class Company_MyModule_Block_Info extends Mage_Payment_Block_Info_Cc
{
protected function _prepareSpecificInformation($transport = null)
{
$info = $this->getInfo();
$transport = new Varien_Object(array('My Var' => "My Value"));
return $transport;
}
}
Payment method selection step:
If you are referring to the actual payment method selection step, when you click on a payment method and a small form appears under it you need to:
Add the following code in your payment model:
protected $_formBlockType = "mymodule/form";
You also need to create the mymodule/form:
<?php
class Company_MyModule_Block_Form extends Mage_Payment_Block_Form_Cc
{
public function __construct()
{
parent::__construct();
$this->setTemplate('path/to/template.phtml');
}
}
The template file should look something like:
<?php $_code=$this->getMethodCode(); ?>
<fieldset class="form-list">
<ul style="display: none;" id="payment_form_<?php echo $_code ?>">
<li>
<p>here is my custom content!:)</p>
</li>
</ul>
</fieldset>
I want to show message on some condition in a template file(custom module template file).I am having following code.
<?php
if(count($collection)): ?>
<?php foreach($collection as $coll): ?>
some calculations
<?php endforeach; ?>
<?php else: ?>
<?php $message = $this->__('There is no data available'); ?>
<?php echo Mage::getSingleton('core/session')->addNotice($message);?>
<?php endif;?>
But this is not working properly. The message is displayed on other pages not on the same page.
If you really need to implement that right in the template, you may use the code below:
<?php echo $this->getLayout()->createBlock('core/messages')->addNotice('My Message')->toHtml(); ?>
But the solution described by Amit Bera sounds like a better way to resolve it.
Muk,According to your code
Mage::getSingleton('core/session')->addNotice($message);
add an notice to magento.This is code set notice to session and which is reflecting on page refresh according php session ,a session variable set value is reflecting after page refresh.
If you already added this notice on other page before came to your file then ,you need to add core/session to custom module template file controllers file.
Code is $this->_initLayoutMessages('core/session');
In controller you need below code in controller.
/* load the layout from xml */
$this->loadLayout();
$this->_initLayoutMessages('core/session');
/* rendering layout */
$this->renderLayout();
Read more at inchoo blog
I found that $this->loadLayout() is what reads and clears messages from the session, therefore if you add messages before calling $this->loadLayout() then those messages should be displayed on the current page.
Example:
public function chooseFileAction() {
// a quick and dirty way to find the larger out of post_max_size and upload_max_filesize
$post_max_size = ini_get('post_max_size'); $post_max_size_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $post_max_size)));
$upload_max_filesize = ini_get('upload_max_filesize'); $upload_max_filesize_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $upload_max_filesize)));
$maxsize = $post_max_size_int < $upload_max_filesize_int ? $post_max_size : $upload_max_filesize;
// display max file size to user in a message box
$msg = 'Max file size: ' . $maxsize;
Mage::getSingleton('core/session')->addNotice($msg);
$this->loadLayout();
$this->_title($this->__('Catalog'))->_title($this->__('File Upload'));
$this->_setActiveMenu('catalog/customfileupload');
$block = $this->getLayout()->createBlock('customfileupload/adminhtml_customfileupload_choosefile');
$this->_addContent($block);
$this->renderLayout();
}
Caveat: this is tested in Magento 1.9, not 1.7.
Currently I have a snippet of code that will forward a user to the product page if they search for a term and only 1 product is associated with that keyword.
<?php if($this->getResultCount() == 1): ?>
<?php $prodId = $this->_productCollection->getAllIds() ?>
<?php $singleProduct = Mage::getModel('catalog/product')->load($prodId) ?>
<?php header('Location: ' . $singleProduct->getProductUrl()) ?>
<?php exit; ?>
<?php elseif($this->getResultCount()): ?>
However, what I want to do now is actually serve up the product and all its details on the results page itself if its the only one with that tag/search term INSTEAD of redirecting to the product page. Im pretty new to php so please bear with me.
Block template is bad place for this. Good place - controller.
Maybe you need rewrite controller for this functionality.
For example/app/code/core/Mage/CatalogSearch/controllers/ResultController.php
In controller your code looks like:
$this->getResponse()->setRedirect($_product->getProductUrl());
I'm trying to add the "send to a friend" action to a category page.
In the product view i can see this code:
"canEmailToFriend()): ?>
<p class="email-friend"><?php echo $this->__('Email to a Friend') ?></p>
<?php endif; ?>
If I try to add this code to my "list.phtml" (where products grid is displayed) I receive this error:
Invalid method Mage_Catalog_Block_Product_List::canEmailToFriend(Array
saying that this methos is not available in this context...
Who can I add the funcionality of "sendtofriend" module to any page I need?
Thanks in advance
This is because the $this->canEmailToFriend() call is a block method belonging to the product page, a class called Mage_Catalog_Block_Product_View. The product listing page uses a block class called Mage_Catalog_Block_Product_List which does not include this code.
The method canEmailToFriend() contains (as defined in app/code/core/Mage/Catalog/Block/Product/View.php) the logic:
$sendToFriendModel = Mage::registry('send_to_friend_model');
return $sendToFriendModel && $sendToFriendModel->canEmailToFriend();
You could embed that directly in your template and then call the helper to output the link if $sendToFriendModel->canEmailToFriend(), but the best way to achieve this would be to move the canEmailToFriend functionality out into a new helper and call it from there.
I founded an alternative solution, just load sendfriend model
$sendToFriendModel = Mage::getModel('sendfriend/sendfriend');
Then use
<?php if ( $sendToFriendModel->canEmailToFriend() ) : ?>
<p class="email-friend"><span><span><?php echo $this->__('Email to a Friend') ?></span></span></p>
<?php endif;?>
Resource from C:/xampp/htdocs/magento/app/code/core/Mage/Sendfriend/controllers/ProductController.php
I think Mage::registry('send_to_friend_model') returns an object of the class Mage_Sendfriend_Model_Sendfriend. The canEmailToFriend() method in Mage_Sendfriend_Model_Sendfriend checks whether the "email to a friend" functionality is enabled:
You can find these two methods in app/code/core/Mage/Sendfriend/Model/Sendfriend.php:
/**
* Check if user is allowed to email product to a friend
*
* #return boolean
*/
public function canEmailToFriend()
{
return $this->_getHelper()->isEnabled();
}
/**
* Retrieve Data Helper
*
* #return Mage_Sendfriend_Helper_Data
*/
protected function _getHelper()
{
return Mage::helper('sendfriend');
}
So you could check that yourself in your template like so:
<?php if (Mage::helper('sendfriend')->isEnabled()) : ?>
<?php // Do stuff ?>
<?php endif ?>