Magento admin: Making simple admin import interface with start-button - magento-1.6

I am trying to make a Magento module, to enable our Magento-webshop customers to import all our products automatically. Since I'm not yet very proficient in Magento development, I run into a few stops on the way... :-)
Right now I try to make a AdminController in which the index page should simply display a text and a button to start the import process. It's the "addButton" part, that I have trouble with:
public function indexAction() {
$this->loadLayout();
$block = $this->getLayout()
->createBlock('core/text', 'example-block')
->setText("
<h1>Import/update products</h1>
<p>On this page you can start the import of all products from Misstoro.</p>
...bla bla bla...
");
$this->_addContent($block);
$url = $this->getUrl('*/*/do_import');
$this->_addButton('button_import', array(
'label' => Mage::helper('import')->__('Start import'),
'onclick' => 'setLocation(\'' . $url .'\')',
'class' => 'add',
));
$this->renderLayout();
}
$this->_addButton gives me an "Call to undefined method" error.
What is the right way to do this?
/ Carsten

Figured it out with a little more research:
$url = $this->getUrl('*/*/do_import');
$block = $this->getLayout()
->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('import')->__('Start import'),
'onclick' => 'setLocation(\'' . $url .'\')',
'class' => 'add',
));
$this->_addContent($block);

Related

Cakephp 3 Authentication plugin, login URL did not match

I want to use the Authentication plugin for CakePHP 3.8 and I'm having problems that are not in documentation.
After follow Getting Started (https://book.cakephp.org/authentication/1/en/index.html) I have one question.
Originally $fields were specified to change username and password relation in real database, same that Auth component, and login URL is where login form si loaded.
First, in getting started or any part of documentation doesn't says about a login view (form), so, like old Auth Component I created this to Users/login.ctp
<div class="users form">
<?= $this->Flash->render('auth') ?>
<?= $this->Form->create() ?>
<fieldset>
<legend><?= __('Please enter your email and password') ?></legend>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
</fieldset>
<?= $this->Form->button(__('Login')); ?>
<?= $this->Form->end() ?>
</div>
My code in Application.php includes this (with its respective uses and implements):
public function getAuthenticationService(ServerRequestInterface $request, ResponseInterface $response)
{
$service = new AuthenticationService();
$fields = [
'username' => 'email',
'password' => 'password'
];
// Load identifiers
$service->loadIdentifier('Authentication.Password', compact('fields'));
// Load the authenticators, you want session first
$service->loadAuthenticator('Authentication.Session');
$service->loadAuthenticator('Authentication.Form', [
'fields' => $fields,
'loginUrl' => '/users/login'
]);
return $service;
}
But when I try to login, I have this error, after var_dump in login.ctp I get this:
object(Authentication\Authenticator\Result)[124]
protected '_status' => string 'FAILURE_OTHER' (length=13)
protected '_data' => null
protected '_errors' =>
array (size=1)
0 => string 'Login URL `http://localhost/users/login` did not match `/users/login`.' (length=70)
If I comment 'loginUrl' => '/users/login' line, then login works fine.
Additional notes:
- I've tested with hashed and textplane passwords, same results.
- I've added $this->Authentication->allowUnauthenticated(['view', 'index', 'login', 'add']); in beforeFilter to access login.
- It's a clean cakephp 3.8 install, only database is the same for tests.
- I've added Crud only with cake console.
I would like to learn more about that loginURL, I should include some uses in UsersController? What causes this error?
Thank you
The error messages is currently a little misleading, as it doesn't show you the possible base directory, which is the actual issue that you are experiencing. I've proposed a fix for that, which may make into the next release.
When your application lives in a subdirectory, you need to make sure that your login URL configuration takes that into account, that is by either passing the URL including the base directory, which you could do either manually:
'loginUrl' => '/myapp/users/login'
or by using the router:
'loginUrl' => \Cake\Routing\Router::url('/users/login')
'loginUrl' => \Cake\Routing\Router::url([
'plugin' => null,
'prefix' => null,
'controller' => 'Users',
'action' => 'login'
])
Another option would be to use the routes based URL checker, which can be configured via the form authenticators urlChecker option, then you can define the login URL using URL arrays, without having to use the router:
'urlChecker' => 'Authentication.CakeRouter',
'loginUrl' => [
'plugin' => null,
'prefix' => null,
'controller' => 'Users',
'action' => 'login'
]
See also:
Authentication Cookbook > Authenticators > Form
Authentication Cookbook > URL Checkers

drupal generate fpdf files

I create website based on drupal 7 with module to generate pdf - i use fpdf library.
I dont know how I can make form to send some data to node where i have php code for generate pdf.
Also i still get error message:
FPDF error: Some data has already been output, can't send PDF file (output started at Z:\xampp\htdocs\domain\includes\common.inc:2748)
where i found:
ob_flush();
when i try change it to
ob_clean()
all nodes generate pdf :/
You can try use other module which is a simple - pdf_using_mpdf
With this module you can get PDF of some node calling www.YOUR_SITE.DOMAIN/node/NID_ID/pdf - where NID_ID is the id of node what you want to render as PDF.
Or also you can use hook_menu() if you need render as PDF only some fields of your node - add your item like
$items['%node/create_pdf'] = array(
'title' => '',
'description' => '',
'page callback' => 'custom_callback_create_pdf',
'page arguments' => array(1),
'access callback' => 'node_access',
'type' => MENU_CALLBACK,
);
Define you callback like
function custom_callback_create_pdf($node) {
// Check if current node has needed field.
if (isset($node->field_my_custom_field_of_node)) {
// Render only field 'field_my_custom_field_of_node';
$view = node_view($node);
$output = render($view['field_my_custom_field_of_node']);
return pdf_using_mpdf_api($output, $node->title);
}
else {
return pdf_using_mpdf_api("<html><body>Current page do not required field.</body></html>", $node->title);
}
}
and print button for download:
$pdf_button = l(t('Download as PDF'), 'node/' . $node->nid . '/create_pdf', array(
'attributes' => array(
'target' => '_blank',
'class' => array('render_as_pdf'),
),
));
echo '<p>' . $pdf_button . '</p>';

Using Yii2 Bootstrap widgets with Smarty

I've installed Yii2 together with Smarty for my views.
Smarty itself is working, but I can't figure out how to use the bootstrap widgets with smarty, nor find any examples.
With the default Yii renderer the widgets work great, and lots of examples are available. But when using Smarty templates documentation is nearly non existing.
How would I define this example with Smarty ?
echo Alert::widget([
'options' => [
'class' => 'alert-info',
],
'body' => 'Alert widget',
]);
Obviously the first thing would be
{use class="yii\bootstrap\Alert"}
But I can't find an example of how to define the widget itself.
You should simply try this :
{use class='#yii\bootstrap\Alert' type='function'}
{Alert body='Alert widget' options=['class' => 'alert-info']}
Read more : http://www.yiiframework.com/doc-2.0/guide-tutorial-template-engines.html#importing-static-classes-using-widgets-as-functions-and-blocks
After changing config/web.php and adding:
'globals' => ['html' => '\yii\helpers\Html'],
'uses' => ['yii\bootstrap'],
in the view section, it works.
{use class='yii\bootstrap\Alert' type='function'}
{Alert body='Alert' options=['class' => 'alert-info']}
So without the # soju suggested.

Yii - Ajax Get based on drop down selection

I am trying to display the price based on the selection of product from a drop down.
View contains:
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'plan-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo $form->dropDownListRow($model, 'plan_id',
$planList, array('id'=>'planid', 'prompt'=>'Select Plan',
'ajax' => array('type'=>'GET',
'url'=> Yii::app()->createUrl('mbr/plan/ajaxGetPrice'),
'update'=>'#price'))); ?>
<div id="price">0.00</div>
<?php $this->endWidget(); ?>
Action:
public function actionAjaxGetPrice()
{
Yii::log("Within AjaxGetPrice");
if (Yii::app()->request->isAjaxRequest)
Yii::log("ajax request");
else
Yii::log("regular request");
//$plan=Plan::model()->findByPk((int) $_GET['plan_id']);
//Yii::log(serializ($plan));
// echo $plan->price;
echo "10";
Yii::app()->end();
}
It is not updating the price. Its not calling the action at all. I looked at the suggestions found in Yiiframework and here and tried those and still no luck.
when I add this to the view
<?php
echo CHtml::ajaxLink(
"Get Price",
Yii::app()->createUrl('mbr/plan/ajaxgetprice'),
array( // ajaxOptions
'type' => 'GET',
'update' => '#price'),
array( //htmlOptions
'href' => Yii::app()->createUrl('mbr/plan/ajaxgetprice')
)
);
?>
I get the response when I click on the link, but it renders a separate page with value "10". I have URLFormat = Path.
What am I doing wrong? Any pointers?
You can also try this as shown
<?php echo CHtml::dropDownList('categories','',
$category,
array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('yourController/GetId'),'update' =>'#data'))
);?>
yourController action
public function actionGetId(){
echo 10;
}
And the div
<div id="data">0.00</div>
I'm not really sure how to do this the Yii way but the following javascript should be useful.
$("#yourdropdownidhere").change(function(){
$.ajax({
url: 'your url here', //(dynamically generated by product item)
type: "get",
success: ajaxSuccessHandler
});
});
function ajaxSuccessHandler(obj) {
$('#price').html(obj);
}
I also suggest sending a JSON object as the response for AJAX requests, so it will have an actual structure. A great blog post on this to check out would be Fully ajax website with Yii
I had the same problem and solved it on the controller that renders the view. If you are using renderPartial assure that the processOutput() option is set to TRUE, otherwise Yii will not attach any Javascript.
If you use render instead of renderPartial it also works.

Random Image as link associated with image

I'm looking for a script that will call a random image linked to its corresponding site on pageload. Anyone know a javascript or php way to do this?
<?php
$random = array(
array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);
$current = rand(0, count($random) - 1);
print "<img src=\"" . $random[$current]['image'] . "\" alt=\"\" />\n";
?>
Quick and easy. Might not be the best way of doing it - I'd personally hook it into a database instead of a static array - but it'll have you up and running in seconds.