Magento Info Block in Payment Method - magento

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>

Related

Prestashop: how to display messages in the cart

i'm working in a quota module for PrestaShop 1.6 and in one of the features is that a need to display a message in the cart's page and in that modal that opens when you add an item to the cart from the home page.
I'm working with the hookCart the hook function, public function hookCart($params), is in my module's class. From it I can get the instance of the Controller like this $this->context->controller
My question is how to display messages in these two views? I tried adding them to the errors array. I can see the message but not the way I'm supposed to display. I would like to display in those alert classes from bootstrap.
The views:
Can you help me?
To display a message on the checkout page you can use whatever front controller hook you want. I guess the one that makes most sense would be displayTop. We won't be outputting any html to the top but just add a message to the controller's errors array.
public function hookDisplayTop()
{
$controller = $this->context->controller;
if ($controller->php_self != 'order' && $controller->php_self != 'order-opc') {
return false;
}
/*
You can do custom logic here if you want to display message only
on some conditions or only on specific step of the checkout
*/
$controller->errors[] = $this->l('Some message');
return false;
}
For the popup the things get messy because:
Popup doesn't have an error display area
Blockcart AJAX uses weird logic that calls CartController which includes blockcart-ajax.php which loads blockcart module method which loads a JSON template file to output data (???)
One way to do this is to use the hook actionCartSave. This hook gets executed on pretty much all cart operations, so we need to make sure we are adding our message when a product is added to cart, uses ajax etc.
public function hookActionCartSave()
{
// If cart doesn't exist or product is not being added to cart in ajax mode - do nothing
if (!$this->context->cart || !Tools::getValue('id_product) || !Tools::getValue('add') || !Tools::getValue('ajax')) {
return false;
}
/*
You can do custom logic here if you want to display message only
on some conditions
*/
$this->context->smarty->assign('mycartpopupmessage', $this->l('Message');
return false;
}
Then you will have to modify themes/default-bootstrap/modules/blockcart/blockcart-json.tpl file to add your message into JSON template.
...
"wrappingCost": {$wrapping_cost|json_encode},
"nbTotalProducts": {$nb_total_products|intval},
"total": {$total|json_encode},
{if isset($mycartpopupmessage)}
"mycartpopupmessage": {$mycartpopupmessage|json_encode},
{/if}
....
Then you need to modify themes/default-bootstrap/js/modules/blockcart/ajax-cart.js and add the following
if (jsonData.mycartpopupmessage) {
$('#layer_cart .alert-message').html(jsonData.mycartpopupmessage);
$('#layer_cart .alert').removeClass('hidden');
}
else {
$('#layer_cart .alert').addClass('hidden');
}
And at last modify themes/default-bootstrap/modules/blockcart/blockcart.tpl
and add alert div
<div class="alert alert-danger hidden">
<button data-dismiss="alert" type="button" class="close">×</button>
<p>{l s='There is 1 error' mod='mymodule'}</p>
<ol>
<li class="alert-message"></li>
</ol>
</div>
Now you should be getting a bootstrap alert inside a popup.
Quite some native prestashop modules haven't been (I guess) updated in years as a lot of them are good candidates for an extensive rework or at least compliant with the MVC workflow which would make modifications like yours much more simple.

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.

Yii: Already add or edit record but view not update

I got a problem about browser cache when I already add/edit record in database. The data in database changed but in view not change. I must press F5 in browser for refresh that page and it'll show updated data.
Please guide to me how to solve this problem, Thanks.
Sorry I forgot to told you guys, In my application has two part.
Admin part (Backend) for add/edit data. (There's not any problem in
this part)
Front part for show data to viewer (Problem here! After
add/edit record in Admin part, this part not changed. I must refresh
page to see update)
This's my relevant code in Front part.
In Controller
class ProductController extends Controller
{
public function actionIndex()
{
$products = Product::model()->getProductList(); // use findAll() method
$this->render('index', array('products' => $products));
}
}
In Model
class Product extents CActiveRecord
{
/*
*
* The other code that generated by Gii
*
*/
public function getProductList()
{
return $this->findAll();
}
}
In View
<html>
<body>
<ul class="thumbnails thumbnails-product">
<?php foreach ($products as $product): ?>
<li class="span3" style="margin-left:0px;">
<div class="thumbnail">
<img class="img-thumb" src="../images/<?php echo $product->PDT_IMG" />
<?php echo CHtml::link($product->PDT_NAME, array('product/view/' . $product->PDT_ID)); ?>
<span class="price"><?php echo $product->PDT_PRICE; ?></span>
</div>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
If you want something to update on-the-fly, I think you're looking for in place editing.
You could take a look at this extension which does that for you.
Especially this part.
May be this can help you out:
Real-time display of server push data using Server-Sent Events (SSE)
this is server push technique by which we can fetch data in every changes made automatically and also after a certain time.
The problem has been solved.
I just add
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
Everytime that view load, it'll reread page and doesn't keep any cache.

magento custom payment method form not showing

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.

magento accesing "SendFriend" module from category page

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 ?>

Resources