add code on specific category id opencart 2.3.0.2 - opencart2.3

I want to add a image with a link on a specific category id but can't seem to work out how to do it in category.tpl file, below is what I have but nothing is showing on the category
<?php if($category_id=="1697") { ?>
<img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" />
<?php } ?>
I am using seo urls but thought as it's the category id, it would show or is there something I need to add into the catalog.php controller file?
Update: Just managed to solve it with the following code
In catalog/controller/product/catalog.php, added the following in
$data['category_id'] = $category_id;
In catalog/view/theme/default/product/catalog.tpl, I got the following
<?php if ($category_id == '1697') { ?>
<img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" />
<?php } ?>

First in the default OC in folder catalog/view/theme/default/product file catalog.tpl does not exist and catalog.php in the corresponding controller folder also does not exist.
Maybe you want to retrieve in catalog/view/theme/default/product/category.tpl?
So if you want to retrieve category_id in catalog/view/theme/default/product/category.tpl you should:
in catalog/controller/product/category.php
find:
$category_info = $this->model_catalog_category->getCategory($category_id);
belowe add:
$data['category_id'] = $category_info['category_id'];
Now you can in catalog/view/theme/default/product/category.tpl use your code:
<?php if ($category_id == '1697') { ?>
<img alt="Seagate Barracuda SSD's" class="img-responsive" src="image/catalog/Seagate-Barracuda-SSDs.jpg" />
<?php } ?>

Related

Magento - Disable customer of Changing / Reset email

For security reasons I need to disable the possibility in form the user to change his email. Once set it can't be change. How can I do this?
I have found :
http://www.magentocommerce.com/boards/viewthread/8622/
Maybe usefull for someone ...
Make the following changes:
In template/customer/account/dashboard/info.phtml
<div class="inner-head">
<h5><?php echo $this->__('Contact Information') ?></h5>
Edit
</div>
<p>
<?php echo $this->htmlEscape($this->getCustomer()->getFirstname()) ?>
<?php echo $this->htmlEscape($this->getCustomer()->getLastname()) ?><br />
<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?><br />
<?php echo $this->__('Change Password') ?>
</p>
and Replace with:
<div class="inner-head">
<h5><?php echo $this->__('Contact Information') ?></h5><br />
</div>
<p>
<?php echo $this->htmlEscape($this->getCustomer()->getFirstname()) ?>
<?php echo $this->htmlEscape($this->getCustomer()->getLastname()) ?><br />
<?php echo $this->__('Change Password') ?>
</p>
Extracted and adapted from the magento community forums.
The problem was that we had an extension that override the user model/controller/view, example: social login, and because we decided not to use it we Disable it in the advanced settings.
Because it was disable, the list of users was not showing in the back-end, but I could create a new customer, yet in the New customer view the Addresses were not showing either.
So, we activated all the extensions again and suddenly the customers list appears. So like this we found out which extension was breaking and fixed it.
In file :
app\code\core\Mage\Customer\controllers\AccountController.php
/**
* Change customer password action
*/
public function editPostAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/*/edit');
}
if ($this->getRequest()->isPost()) {
$customer = Mage::getModel('customer/customer')
->setId($this->_getSession()->getCustomerId())
->setWebsiteId($this->_getSession()->getCustomer()->getWebsiteId());
$fields = Mage::getConfig()->getFieldset('customer_account');
$data = $this->_filterPostData($this->getRequest()->getPost());
//=========
// ADD THAT // customer cannot change his email // Le customer ne peut pas modifier son email
if(isset($data['email'])){
$data['email'] = $this->_getSession()->getCustomer()->getData('email');
}
//========END
foreach ($fields as $code=>$node) {
if ($node->is('update') && isset($data[$code])) {
$customer->setData($code, $data[$code]);
}
}
$errors = $customer->validate();
if (!is_array($errors)) {
$errors = array();
}

how to check session in zend layout

layout.phtml:
<?php echo $this->doctype() ?>
<html>
<head>
<?php echo $this->headTitle()."\n"; ?>
<?php echo $this->headLink() ."\n"; ?>
<?php echo $this->headScript(); ?>
</head>
<body>
<div id="wrap">
<div class="header">
<div class="logo"><img src="../../images/logo.gif" alt="" title="" border="0" /></div>
<div id="menu">
<ul>
<li class="selected">home</li>
<li>about us</li>
<li>books</li>
<li>specials books</li>
<li>my accout</li>
<li>register</li>
<li>prices</li>
<li>contact</li>
<li>adddbook </li>
</ul>
</div>
</div>
<div class="center_content">
<div class="left_content">
<?php echo $this->layout()->content ?>
I am new to zend framework here i am facing problem with displaying navigations. in pure php i can serve my navigation by checking sessions. like this:
<?php
if($_SESSION['usertype']=='admin')
{
echo "<li>adddbook </li>";
}
?>
My question is how can i implement this in zend framework. Thanks
You can do this in a myriad of ways like the Zend_Auth, but the closes to the $_SESSION method is using Zend_Session.
First you need to start Zend_Session before any output is sent to the browser, just like a normal php session. I do it in my index.php right after setting all my paths and autoloaders.
Zend_Session::start();
Next step is creating a namespace for the userinformation and adding the relevant information to it, preferably when you authenticate the user.
$userInfo = new Zend_Session_Namespace('userInfo');
$userInfo->userType = 'admin';
This is the equivalent to setting a $_SESSION['userInfo']['userType'] = 'admin';
Last, get the information in your layout:
<?php
$userInfo = new Zend_Session_Namespace('userInfo');
if($userInfo->userType=='admin')
{
echo "<li>addbook </li>";
}
?>
Read this link for more information http://framework.zend.com/manual/en/zend.session.html
If you want to check an user role, you could use the class Zend_Auth provided by the framework. You can check the credential of a user and then affect it a role.
To retrieve this role you can check the identity of the user with the Zend_Auth instance :
$identity = Zend_Auth::getInstance()->getIdentity();
if (strcmp($identity->role, "admin") == 0) {
echo '<li>adddbook </li>';
}

view render in zend not working properly as expected

My zend layout and scripts are detecting fine. but when in init function of my IndexController I write $this->view->render("header.phtml") It does not show anything one the screen, whereas when I write echo ($this->view->render("header.phtml"); it displays my header.phtml file. Here is my IndexController
class IndexController extends Zend_Controller_Action
{
public function init()
{
$layout = $this->_helper->layout();
//$this->view = $this->getResource('View');
echo ($this->view->render("header.phtml"));
//echo"<pre>";
//var_dump($this->view);
//var_dump(APPICATION_PATH);
}
public function indexAction()
{
// action body
echo "In default index con";
}
}
Also when Igive my url to/mypath/index It does not display the simple line "I'm in index controller" which I'm just echoing. In my bootstrap here is my Zend_Layout settings.
Zend_Loader::loadClass('Zend_View');
$this->view = new Zend_View();
$this->view->setEncoding('UTF-8');
$this->view->setScriptPath($this->root .'/application/default/views/scripts');
$viewRenderer=new Zend_Controller_Action_Helper_ViewRenderer();
// Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
// $view->setScriptPath($this->root.'/'.$theme.'/views/scripts/');
//$view->setScriptPath($this->root.'/application/default/views/scripts/');
$this->view->addScriptPath($this->root.'/application/admin/views/scripts');
$this->view->addScriptPath($this->root.'/application/business/views/scripts');
// $this->view->setHelperPath($this->root .'/application/default/views/helpers');
$this->layout = Zend_Layout::startMvc(
array(
'layoutPath' => $this->root . '/application/default/views/'.$crt_theme.'/layouts',
'layout' => 'layout'
)
);
$this->registry->set("theme", $crt_theme);
variable $crt_theme is set to 'default'.
Rob' answer is correct although you may need some more information as you appear to be working hard at making this complicated. ZF when used as an MVC has a place to put layouts and defaults for using them.
If you are using the Zend_Tool command line interface start with the commmand: zf enable layout and the tool will add the default directory and a default layout.phtml to your project.
in the application.ini it will add the line:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
and at that path it will add the file layout.phtml
If you need to change the name of the default layout add this line with the name of your script without the .phtml
resources.layout.layout = master
There are as many ways as you can think of to use this file, but here is an example of how I use it.
I like to set my project defaults in my application.ini file so if I need to change anything it's easy.
View Settings
;*************
resources.view[]=
resources.view.charset = "UTF-8"
resources.view.encoding = "UTF-8"
resources.view.doctype = "HTML5"
resources.view.language = "en"
resources.view.contentType = "text/html; charset=UTF-8"
then in my bootstrap I setup the view I want use, I do it here so that if I have multiple layouts (i usually do) it's easy to change css or js files in one place.
protected function _initView() {
//Initialize view
$view = new Zend_View();
$view->addHelperPath('/../library/Application/View/Helper');
$view->doctype(Zend_Registry::get('config')->resources->view->doctype);
$view->headTitle('Our Home');
$view->headMeta()->appendHttpEquiv('Content-Type', Zend_Registry::get(
'config')->resources->view->contentType);
$view->headLink()->setStylesheet('/css/normalize.css');
$view->headLink()->appendStylesheet('/css/blueprint/src/liquid.css');
$view->headLink()->appendStylesheet('/css/blueprint/src/typography.css');
$view->headLink()->appendStylesheet(
'/javascript/mediaelement/build/mediaelementplayer.css');
$view->headLink()->appendStylesheet('/css/main.css');
$view->headLink()->appendStylesheet('/css/nav.css');
$view->headLink()->appendStylesheet('/css/table.css');
//add javascript files
$view->headScript()->setFile('/javascript/mediaelement/build/jquery.js');
$view->headScript()->appendFile('/javascript/modernizr.js');
//add it to the view renderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer');
$viewRenderer->setView($view);
//Return it, so that it can be stored by the bootstrap
return $view;
}
Notice all of those headLink(), headScript() and docType() entries, these are where the data is set for placeholders, that will be used in the layout.
Now the layout, the actual content from your other action based scripts will typically be rendered by the placeholder $this->layout()->content
<?php
echo $this->doctype() . "\n";//placeholder
?>
<html>
<head>
<title></title>
<?php echo $this->headMeta() . "\n" ?><!-- displays all meta data passed -->
<?php echo $this->headLink() . "\n" ?><!-- displays all links passed -->
<?php echo $this->headscript(). "\n"?><!-- displays all scripts passed -->
</head>
<body>
<section class="container">
<header class="block">
<hgroup id="header" class ="column span-24">
<h1>Our Home</h1>
</hgroup>
<nav>
<div id="nav" class="column span-24">
<?php echo $this->layout()->nav ?> <!-- Custom Placeholder -->
</div>
</nav>
</header>
<section class="block">
<div id="main" class="column span-18 border">
<div id="flash">
<?php
//flash messenger display location
if (count($this->messages) > 0) {
printf("<h3 id='flash'>%s</h3>", $this->messages[0]);
}
?>
</div>
<?php echo $this->layout()->content; ?><!-- Default placeholder, where views are rendered -->
</div>
<aside id="sidebar" class="column span-4 last">
<?php echo $this->layout()->search ?><!-- Custom placeholder -->
<div id="subNav">
<?php echo $this->layout()->subNav ?> <!-- Custom placeholder -->
</div>
<div id="adminMenu">
<h4>Administration Links</h4>
<?php echo $this->layout()->adminMenu ?> <!-- Custom placeholder -->
</div>
</aside>
</section>
<footer class="block">
<div id="footer" class="column span-24">
<p>Created with Zend Framework. &COPY; </p>
</div>
</footer>
</section>
<?php echo $this->inlineScript() ?><!-- placeholder -->
</body>
</html>
Hope this helps!
[Edit]
One more thing, this always seems to be the next question. "How do I change my layout from the default in my controller/action?"
to change the layout from your controller you would typically do it with a preDispatch() method and just pass the name of your new layout to the layout helper.
$this->_helper->layout->setLayout('myOtherLayout');
doing just this will change the layout for every action in the controller. To be more selective you can use a conditional, like:
if ($this->getRequest()->getActionName() == 'player') {
$this->_helper->layout->setLayout('player');//reset layout
//add 2 new headscripts
$this->view->headScript()->appendFile(
'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'
);
$this->view->headScript()->appendFile(
'/javascript/mediaplayer/jwplayer.js'
);
}
render() is working as intended; it returns a string that you should then echo.
It is very unusual to be rendering directly in a controller however. At a minimum, you should be rendering your header and footer from views/scripts/index/index.phtml, though using Zend_Layout would be even better. If you are using Zend_Application, then you can start using Zend_Layout simply by adding:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
to your application/config/application.ini file. You then need to create a application/layouts/scripts/layout.phtml file which could look something like this:
<?php
$this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$this->headTitle()->setSeparator(' - ');
$this->headTitle('My website');
?>
<!DOCTYPE html>
<html>
<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<!-- Other <head> elements and view helpers here -->
</head>
<body>
<div id="content">
<?php echo $this->layout()->content; ?>
</div>
</body>
</html>

Zend Framework - Flashmessenger - Only one character

I have a little problem with FlashMessenger. When I want to retrieve the messages in my layout, it writes the first letter of the message... example "test" displays "t".
I tried a solution posted in this question, but nothing changed for me.
I use php 5.3.6
Here is my code:
In my method :
$message = 'test';
$this->_helper->FlashMessenger($message);
Call in the Layout
<div id="message_box">
<?php echo $this->flashMessages(); ?>
</div>
Can someone help me?
Try this:
In controller:
$this->_helper->FlashMessenger->addMessage("Your message", 'actions');
// you can redirect to another controller ...
$this->view->messages = $this->_helper->FlashMessenger->getMessages('actions');
In phtml file:
<!-- some html code -->
<div id="message_box">
<?php echo $this->messages[0]; ?>
</div>

how do i add a dynamiclally generating dropdown to the layout.phtml in zend framework

i want to add a dropdown menu to my layout .
i have a list of hotels . i want to change the hotel from a dropdown , i need to keep that drop down in my layout.phtml .
problem is hotel list is dynamic.
can i do this , is this possible in zend ,
here is my layout,phtml
i need to add a dropdown to <div class="floatright wid35 textaligncenter padtop5">
<html>
<head>
<?php echo $this->docType(); ?>
<?php echo $this->headTitle(); ?>
<?php echo $this->headScript(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headStyle(); ?>
</head>
<body>
<?php echo $this->render('admin/header.phtml'); ?>
<div id="contentColumns" class="columns">
<div id="columnRight" class="column-right"></div>
<div id="columnLeft" class="column-right">
<div class="link-guide">
<div id="breadcrumbs" class="floatleft wid60">
<?php echo $this->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render(); ?>
</div>
<div class="floatright wid35 textaligncenter padtop5">
</div>
</div>
<div class="padding-box">
<?php echo $this->layout()->content; ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php echo $this->render('admin/footer.phtml'); ?>
</body>
</html>
No. Layout files represent the static structure of a page like header and footer and everything you wrap around your dynamic content.
So this is not recommended. However you could solve that implementing the _init method of your main controller and extend any controller with that main controller:
class MainController extends Zend_Action_Controller{
function init(){
$this->view->foo = "Show everywhere!";
}
}
class IndexController extends MainController{
public function indexAction(){
$this->view->bar = "Show only on index/index";
}
}
Or you can use a plugin which would be the more elegant way
class MyPlugin extends Zend_Controller_Plugin_Abstract{
public function preDispatch(Zend_Controller_Request_Abstract $request){
$view = Zend_Controller_Action_HelperBroker::
getStaticHelper('viewRenderer')->view;
$view->foo = "bar";
}
}
and in your bootstrap process register that plugin
Zend_Controller_Front::getInstance()->registerPlugin(new MyPlugin);
You can create preDispatch function in your base controller class.
Then you get hotel list and send it to view:
$this->view->hotels = $hotels;
And in your layout you can parse it as you wish.
I see two issues here:
Using your hotel list in a dropdown suggests that you will have a form My_Form_Hotels extending Zend_Form which accepts the hotel list as a constructor parameter.
Where should you populate the hotel list, instantiate the form, and communicate all this to the view/layout for rendering?
Sounds like a front controller plugin would do the job. Since the layout resource functions as a plugin that runs late in postDispatch(), you need to run yours before that. dispatchLoopStartup() should be fine.
Something like this in library/My/Plugin/HotelForm.php:
class My_Plugin_HotelForm extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$hotelModel = new My_Model_Hotel();
$hotels = $hotelModel->getAllHotels();
$form = new My_Form_Hotels($hotels);
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = $viewRenderer->getView();
$view->hotelForm = $form;
}
}
Then in your layout, simply dump the form using $this->hotelForm.
To enable your plugin, add to application/configs/application.ini:
autoloaderNamespaces[] = 'My_"
resources.frontcontroller.plugins[] = "My_Plugin_HotelForm"