Magento: Disable Layout Page Templates like 3-columns.phtml and so on - php

I want to create entire website based on 2 columns only. So I want to remove all one column and 3 column layouts.
I want to remove these options even from the administration area.
How to do this?

You need to rewrite (whether by using app/code/local or by using a module) Mage_Page_Model_Source_Layout::getOptions() like this:
/**
* Retrieve page layout options
*
* #return array
*/
public function getOptions()
{
// Array of layout codes that are allowed
$allowedLayoutCodes = array('empty', 'two_columns_left', 'two_columns_right');
if ($this->_options === null) {
$this->_options = array();
foreach (Mage::getSingleton('page/config')->getPageLayouts() as $layout) {
// If layoutCode in foreach loop is allowed
if(in_array($layout->getCode(), $allowedLayoutCodes)) {
$this->_options[$layout->getCode()] = $layout->getLabel();
if ($layout->getIsDefault()) {
$this->_defaultValue = $layout->getCode();
}
}
}
}
return $this->_options;
}

For Remove Layout option from administrative area, you have to edit core file. For this pls comment required layouts in app\code\core\Mage\Page\etc\config.xml.
Please Make sure that you have removed all removed layout references from your frontend theme.

Related

Joomla - Update Name in the Users table

I have a Joomla 3 installed in my local machine.
I've edited the default registration page to hide the Name field, wherein instead of using the full name as a field, I've divided it into First Name, Middle Name and Last Name.
Fortunately, the records being saved is successful and I can update them too.
The problem is when the administrator starts managing the list of users, there's no link to proceed. This means the field with the link, which is the Name field (the full one) is blank.
My objective is that upon registration, I can fill that field out with a concatenated first, middle and last name.
How can I do this in Joomla 3?
Thanks.
You would need to develop a custom user plugin to manage this properly. In addition, if you are going to write the plugin you should go ahead incorporate the entire use case into. Below is a quick draft of how your main plugin file would look:
<?php
defined('_JEXEC') or die;
class plgUserCustom extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
}
// Called while Joomla is loading the form for the view
// This is where you would remove or alter fields
// and load your custom xml form definition for the
// first, middle and last names
public function onContentPrepareForm($form, $data)
{
// Confirm valid JForm object or exit
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
// If the active view isn't listed in array exit as plugin not needed
//
// com_users.registration = front end registration form
// com_users.profile = front end edit profile form
// com_users.user = back end administrators form
if (!in_array($form->getName(), array('com_users.registration', 'com_users.profile', 'com_users.user'))) {
return true;
}
// The core JForm object for the view will be loaded
// manipulate the fields any way you like
// In below example, the name field will be removed
// from the users registration, profile and admin user manager view
if (in_array($form->getName(), array('com_users.registration', 'com.users.profile', 'com_users.user'))) {
$form->removeField('name');
// Now add the form xml path for your custom name fields
// In this example the plugin has a forms directory
JForm::addFormPath(dirname(__FILE__) . '/forms');
$form->loadFile("custom", false);
}
return true;
}
// This is where Joomla loads any existing data into the form field
// and where you would take the standard name field and separate
// into first, middle and last name values and attach to data object.
// The data object property names must match the field name in your
// xml form definition file.
public function onContentPrepareData($context, $data) {
// Verify you are in the correct form before manipulating data
if (!in_array($context, array('com_users.profile','com_users.user', 'com_users.registration'))) {
return true;
}
// explode core name field into parts, attach to core data object
// as first, middle and last name and unset name data.
// CAUTION: You should implement check to verify middle name entered
// or not by verifying if parts array length is 2 or 3
$parts = explode(" ", $data->name);
$data->first_name = $parts[0];
$data->middle_name = $parts[1];
$data->last_name = $parts[2];
unset($data->name);
}
return true;
}
// This method fires before Joomla save the user data and is where
// you should combine the first, middle and last names into one name
// and attach to data object and remove references to first, middle and
// last names.
public function onUserBeforeSave($user, $isNew, $data) {
// Manicure data before save, implode first, middle and last name
// into one field and add to data object, unset first, middle and last
// name from data object
$data->name = implode(" ", array($data->first_name, $data->middle_name, $data->last_name));
unset($data->first_name);
unset($data->middle_name);
unset($data->last_name);
return true;
}
public function onUserAfterSave($data, $isNew, $result, $error)
{
return true;
}
public function onUserAfterDelete($user, $succes, $msg)
{
return true;
}
public function onUserLogin($user, $options)
{
return true;
}
public function onUserLogout($credentials, $options) {
return true;
}
}
I added links to writing a plugin to help you in creating and packaging the installation ZIP to install the plugin. I also attached a link for creating xml form definitions.
Good Luck!
http://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla
http://docs.joomla.org/XML_JForm_form_definitions
You can manage/manipulate user data using a User Plugin. This link will show you how to use example.php (which, I believe, is included with the Joomla installation). You're probably most interested in function onUserBeforeSave, and may not even need your module changes if you manipulate their input before Joomla saves it.

Silverstripe forbid editing of page but allow to create subpages

I have a NewsholderPage and NewsPage. NewsPages are subpages of NewsholderPage.
I need users of a certain group to be able to create NewsPages, but not to be able to edit the NewsholderPage.
If I put the following code into the NewsholderPage...
public function canEdit($member = null){
if(permission::check('SUPERUSER')){
return true;
}
return false;
}
... then a not-admin cannot edit the NewsholderPage but also gets a "forbidden" message, when he is trying to create a NewsPage as child of the NewsholderPage.
What is the best way to allow the creation of subpages, while not allowing to edit the parent page?
You'll want to override the canAddChildren method on NewsholderPage to return something other than the default (which is simply $this->canEdit()). To get the default behaviour back, you can use something like:
public function canAddChildren($member = null) {
// Call SiteTree::canEdit rather than NewsholderPage::canEdit
return parent::canEdit($member);
}

How do I change the order of files on my server?

How do you change the order of files in the file system? I am using Fetch.
The reason I ask is because I have a menu bar that automatically lists the pages in my website by what is in the "pages" folder. The way I see it on fetch, they are in alphabetical order "blog.ctp, games.ctp, home.ctp, news.ctp". So I would expect the menu bar to list the pages as "BLOG GAMES HOME NEWS", but instead it lists them as "GAMES NEWS BLOG HOME". Ultimately I want the order to be "HOME GAMES BLOG NEWS". How do I change the order of the files?
Here is my code in case it is helpful. But my code is not the problem...I just need to know how to change the file order in the folder "Pages".
if ($handle=opendir('../View/Pages/'))
{
while (false !== ($entry = readdir($handle)))
{
if(strpos($entry,".ctp")!==False)
echo "<div class='menubarItem'>".$this->Html->link(substr($entry,0,-4),
array('controller'=>'pages','action'=>'display',substr($entry,0,-4)),
array('escape' => false)).'</div>';
}
}
Add a priority flag to your file names at the beginning or end. I.e. GAMES_1, HOME_2 ...etc... Sort the array of file names using PHP sort() and replace the last two character from file name using substr($filename, -2).
The CakePHP Folder utility has the option to sort the result;
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::find
App::uses('Folder', 'Utility');
App::uses('Folder', 'Utility');
$myFolder = new Folder('/path/to/directory');
$files = $myFolder->find('*.ctp', true);
foreach ($files as $filename) {
// your code here
}
However, If you do not want to show the pages alphabetically, either prefix the file names with a number and create a special route or don't use the filename for sorting but manually specify the order.
In the end, the only reason for dynamically creating the menu based on the View files is to automatically have the menu generated for you. However, chances are that these changes won't occur often and based on your comment (prefered order) you do have a specific order in mind.
The best solution is to just manually specify the sort order. This will also improve performance as the server will not have to do a directory-scan for each request
For example:
/**
* MenuItems
*
* preferable pass this as a viewVar to the View
*
* file => title
*/
$menuItems = array(
'home' => 'HOME',
'blog' => 'BLOG',
....
);
foreach($menuItems as $file => $title) {
// your code here
}
moving this to a Model
Retrieving the file list inside your View is not the location where this should be done. It's best to read the files beforehand and pass them to the View via a viewvar. Because reading the files is actually 'retrieving data', you may want to create a Model for this that is not connected to a database table.
example
app/Model/Menuoption.php
App::uses('Folder', 'Utility');
class Menuoption extends AppModel {
// this model does not use a database table
public $useTable = false;
public function getOptions()
{
// NOTE: or use the 'manually' created menuItems here
$myFolder = new Folder('/path/to/directory');
return $myFolder->find('*.ctp', true);
}
}
Inside your controller; for example in the beforeRender() callback, or inside a regular action;
public function beforeRender()
{
$this->set('files', ClassRegistry::init('Menuoption')->getOptions());
}
inside your view, you can now access the results via the $files variable;
foreach ($files as $filename) {
// your code here
}

Yii CListView Pagination customising

is there a way to customise the Yii CListView Pagination object to show
previous 1 of n pages next
rather then
previous 1,2,3 next ?
thanks
You cannot do this by simply passing parameters to the CLinkPager in order to modify its output. So, there is no more elegant method.
But you can very easily override the Pager class by extending CLinkPager and just change the createPageButtons()-Method in the following way:
Yii::import('web.widgets.pagers.CLinkPager');
class YourLinkPager extends CLinkPager{
/**
* Creates the page buttons.
* #return array a list of page buttons (in HTML code).
*/
protected function createPageButtons()
{
if(($pageCount=$this->getPageCount())<=1)
return array();
list($beginPage,$endPage)=$this->getPageRange();
$currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
$buttons=array();
// first page
$buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,$currentPage<=0,false);
// prev page
if(($page=$currentPage-1)<0)
$page=0;
$buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);
/*
* !!! change has been made here !!!
*/
$buttons[]='<li>Page '.$this->getCurrentPage(false).' of '.$this->getPageCount().'</li>';
// next page
if(($page=$currentPage+1)>=$pageCount-1)
$page=$pageCount-1;
$buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);
// last page
$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);
return $buttons;
}
}
http://www.yiiframework.com/forum/index.php/topic/5776-customise-the-clinkpager/

Magento - Blank white screen search results. Many things broken

Whenever a user searches, I get this error:
2012-06-26 11:05:21.671 [NOTICE] [208.69.120.120:48175-0#hostname] [STDERR] PHP Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::getEntityTablePrefix() in /chroot/home/SITENAME/DOMAIN.COM/html/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php on line 505
And instead of the user's results appearing, they get a blank white page- no error on their end, no UI, just white. This was the first issue I noticed, but on the same day the following issues started coming up:
White Search Results
Sub-category product count for all sub-categories in layered nav is showing 0.
Some customers can not view orders from their front-end UI when logged in.
Our order export script is returning blank fields (1.7mb instead of 4.3).
Our "Made-in-the-usa" and "best sellers" pages are returning more products than they should.
Now, I know these are all incorrect because if I reindex the entire site, for some period while it is processing the index, all of the above works. However, when the index is complete, it all breaks again. The same day this happened we had an error page appear that stated one of the tables had broken and should be repaired. We ran PHPMyAdmin's repair and optimize functions on all tables and it fixed that error- but all of these are still broken.
Any ideas at all? Any ideas of what could be tried to fix this? I cant find this error anywhere- and the guys over at Nexcess haven't been able to find anything for this, either.
Thank you for your time.
As per the comments above, Magento's telling you that it's trying to call the method getEntityTablePrefix on an object whose classes don't have that method defined. Specifically in this method
#File: app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
public function getBackendTable()
{
if ($this->_dataTable === null) {
if ($this->isStatic()) {
$this->_dataTable = $this->getEntityType()->getValueTablePrefix();
} else {
$backendTable = trim($this->_getData('backend_table'));
if (empty($backendTable)) {
$entityTable = array($this->getEntity()->getEntityTablePrefix(), $this->getBackendType());
$backendTable = $this->getResource()->getTable($entityTable);
}
$this->_dataTable = $backendTable;
}
}
return $this->_dataTable;
}
Given this happens from the following class
Mage_Catalog_Model_Resource_Product_Flat
It says to me that you have an extension and/or customization done that assumes you're not using the flat catalog data tables and wasn't coded to work with the flat table.
Dropping in a debugging call like this
if(!is_callable(array($this->getEntity()),'getEntityTablePrefix'))
{
mageDebugBacktrace();
//debug_print_backtrace();
exit;
}
right before the offending call (in a local code pool override, of course), will print out a call-stack that should point the offending code.
The seems that problem is in Mage_CatalogSearch_Model_Resource_Search_Collection::_getSearchEntityIdsSql that is not compatible with using the product flat index.
You can rewrite class Mage_CatalogSearch_Model_Resource_Search_Collection and do two little modifications.
1) Add new function _getSearchEntityIdsSqlUsingFlatIndex to rewrited class. This new function (I hope) does exactly the same thing as original _getSearchEntityIdsSql, but with using the product flat index.
2) Modify function _getSearchEntityIdsSql so that it calls new _getSearchEntityIdsSqlUsingFlatIndex if the catalog product flat index is enabled and built.
See source code:
class VENDOR_MODULE_Model_PATHTOREWRITECLASS extends Mage_CatalogSearch_Model_Resource_Search_Collection {
/**
* Retrieve SQL for search entities using product flat index.
*
* #param $query
* #return Varien_Db_Select
*/
protected function _getSearchEntityIdsSqlUsingFlatIndex($query)
{
/* #var $coreHelper Mage_Core_Model_Resource_Helper_Abstract */
$coreHelper = Mage::getResourceHelper('core');
$likeOptions = array('position' => 'any');
$flatTableName = $this->getTable('catalog/product_flat').'_'.$this->getStoreId();
/** #var Varien_Db_Select $select */
$select = $this->getConnection()
->select()
->from($flatTableName, array('entity_id'));
foreach ($this->_getAttributesCollection() as $attribute) {
/** #var Mage_Catalog_Model_Entity_Attribute $attribute */
if ($this->_isAttributeTextAndSearchable($attribute)) {
$attributeCode = $attribute->getAttributeCode();
$dbFieldName = in_array($attribute->getFrontendInput(), array('select', 'multiselect'))
? $attributeCode.'_value'
: $attributeCode;
if ($this->getConnection()->tableColumnExists($flatTableName, $dbFieldName)) {
$select->where($coreHelper->getCILike($dbFieldName, $this->_searchQuery, $likeOptions));
} else {
Mage::log(__METHOD__.": Attribute '$attributeCode' is missing in flat index.", Zend_Log::NOTICE);
}
}
}
return $select;
}
/**
* Retrieve SQL for search entities
*
* #param unknown_type $query
* #return string
*/
protected function _getSearchEntityIdsSql($query)
{
// HACK - make compatibility with flat index
/** #var Mage_Catalog_Helper_Product_Flat $flatHelper */
$flatHelper = Mage::helper('catalog/product_flat');
if ($this->getStoreId() > 0
&& $flatHelper->isEnabled($this->getStoreId())
&& $flatHelper->isBuilt($this->getStoreId())
) {
return $this->_getSearchEntityIdsSqlUsingFlatIndex($query);
}
// END HACK
return parent::_getSearchEntityIdsSql($query);
}
}

Categories