July 30, 2012
No Comments
Wondering why your Magento admin menu is not showing up after upgrading your live Magento store?
If all attempts to get to a particular admin page with the exception of the dashboard proved abortive, this could be because there is a conflict between the Magento function that merges all Javascript files and the Apache URL rewrite. This could be fixed by turning off this Magento function, and your can run the script below to do this.
UPDATE <code>[your_magento_database_name]</code>.<code>core_config_data</code> SET <code>value</code> = '0' WHERE <code>core_config_data</code>.<code>path</code> =<code>dev/js/merge_files</code>;
Thinking of being able to set different Magento Categories to display its sub-categories which can be controllable in the Magento admin i.e.
from
to this;
You might be interested in using or viewing the zipped file here;subcat
In a situation where you want Magento to display out of stock product options of a configurable products, overriding getAllowProducts() function in Mage_Catalog_Block_Product_View_Type_Configurable is where you should be looking, change
if ($product->isSaleable())
{
$products[] = $product;
}
to
$products[] = $product;
Bingo!!!
February 27, 2012
2 Comments
Magento’s Zend extension for creating pdfs could take massive amount of time to customize, I would say customizing the code to make it do what you want is not the best the way to go when an entire layout changes is to be made to probably for invoice, packing slip etc. I found an extension that you could add to Magento to make things a lot easier by creating pdf’s from html called TCPDF. There exist other extension that could do the same thing e.g. DOMPDF, when I tried incorporating DOMPDF with Magento, it broke my browser and won’t generate anything. Dompdf could actually still work with Magento but I didnt have the time to probe into what could be wrong.
So I settled into using TCPDF which worked beautifully with Magento in minutes. You can incorporate it easily into Magento by following the steps below;
1. Download TCPDF from http://sourceforge.net/projects/tcpdf/files/
2. Change the name of the file root directory after extraction to TCPDF
3. Inside this directory, there is a tcpdf.php file, change the name to TCPDF
4. Open the file and change the class name from tcpdf to TCPDF_TCPDF, am very sure those that are really familiar with Magento will know why.
5. Copy the files into your Magento “lib” folder in the root Magento installation directory.
6. And you have successfully incorporated TCPDF with Magento, from anywhere in Magento, you can call this class by $tcpdf = new TCPDF_TCPDF(), you can find the constructor parameters for this class in the example files in the TCPDF directory.
I hope this helps someone.
February 3, 2010
No Comments
If you encounter the error :
Invalid bind-variable name xxxxxx
When trying to use named bound parameters with Zend Framework, then you are probably using the Mysqli adapter. Unfortunately this doesn’t actually support named parameters, but the Exception message isn’t really clear on that, despite being thrown in this block of code:
} else if ($val[0] == ':') {
if ($this->_adapter->supportsParameters('named') === false) {
/**
* @see Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception("Invalid bind-variable name '$val'");
}
}
The Exception should really say:
You are trying to use named parameters with an adapter that doesn’t support them
The solution is easy, just switch your adapter from Mysqli to Pdo_Mysql
February 2, 2010
No Comments
If you use Zend_Db_Statements directly as well as using the Zend_Db_Table family of classes for Active Record et al then you might find the following little tip useful.
By default, if you run a query using something like
public function query($sql, $params=false) {
if(empty($params)) {
$stmt = $this->getAdapter()->query($sql);
}else {
$stmt = $this->getAdapter()->query($sql, $params);
}
return $stmt;
}
then every time you call your query method, you will be preparing the statement again.
Of course that’s not really a good idea if you are repeating the same query multiple times simply changing the parameters to be passed in.
In that kind of scenario you can do something like this:
$stmt = $db->query($sql, $params);
$result1 = $stmt->fetch();
$stmt->execute($params2);
$result2 = $stmt->fetch();
Heres an example of a chunk of code that is working out a category path from an ecommerce system for a particular category id.
$stmt = $db->query("select c.parent_id, cd.categories_name from categories c join categories_description cd using(categories_id)
where categories_id = ?", array($categories_id));
while(false!==($r=$stmt->fetch())){
$categoryString[]=$r['categories_name'];
if($r['parent_id']==0){
break;
}
//Note this bit - we are just re executing the statement with some new parameters.
$stmt->execute(array($r['parent_id']));
}
This tip alone can add a lot of speed if you are doing repetitive statements
February 1, 2010
No Comments
Currently working on a big Zend Framework project so I though I would have a breather and do a little blog post targeted at anyone looking for a UK based Zend Framework developer.
I’ve built a few Zend Framework based systems and have found it a fun system to work with, especially on the more recent versions of the library. There have been a few hurdles along the way and I have definitely improved my object oriented PHP development skills a lot since I first had a go at the Zend Framework quick start way back when.
I chose to learn Zend Framework primarily because Magento is based on it, and Magento is the ecommerce platform that I have chosen to specialise in. Since then though I have found that Zend Framework has a definite place for me, especially when coding more heavy duty data processing applications.
For simple web sites I would tend more towards using Symfony or my own lightweight MVC framework for very simple sites. For me Zend Framework really shines when you need to do something a little different that doesn’t easily fit into the mold specified by the Symfony code creation tools.
So to conclude, if you are looking for a PHP web developer who specialises in Zend Framework and particularly if you would prefer a UK based Zend Framework specialist then get in touch with us today.
January 27, 2010
No Comments
With some trepidation I decided that I really had to implement pagination into a Zend Framework project I am working on. Zend Framework is great, but some of the sections can be a little tricky to get your head around at first attempt.
However, less than an hour after first looking at it, I have now got my system spitting out results in a nicely paginated ten at a time. The documentation on the Zend Framework reference is a little sparse but suffice to say that if you are using Zend_Db then actually its pretty easy.
The only bit that is a little tricky is getting the actual page controls to display, as you are left to code your own (though they do supply some code).
One major irritation with the Zend Framework reference guide is that I seem to be unable to copy and paste the code examples, it ends up looking like this:
<!--
2.
See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
3.
-->
4.
5.
<?php if ($this->pageCount): ?>
6.
<div class="paginationControl">
7.
<!-- Previous page link -->
8.
<?php if (isset($this->previous)): ?>
9.
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
10.
< Previous
11.
</a> |
12.
note the line numbers, great.
this tutorial was really useful though:
Here is some code snippets:
Controller
public function viewAction(){
$this->view->input = $input = $this->_request->getPost('search');
$paginator = $this->_model->tableSearchAllPaginator($input);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator = $paginator;
}
Model
public function tableSearchAllPaginator($input, $fields_to_select=null){
$table = $this->getTable();
$select = $table->select();
$fields = $table->info(Zend_Db_Table_Abstract::COLS);
if(!empty($input)) {
foreach($fields as $field) {
$select->orWhere("$field like ?", "%$input%");
}
}
if(!empty($fields_to_select)) {
$select->columns($fields_to_select);
}
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
return $paginator;
}
View Script
echo $this->partial('_viewtable_page.phtml', array('paginator'=>$this->paginator, 'controller'=>'products'));
View Table Page Partial
if (count($this->paginator)) {
echo '<h4>Found ' . count($this->paginator) . ' Results</h4>';
echo '<table class="grid">';
foreach($this->paginator as $k=>$row) {
//EC_Debug::dump($k);
$row = $row->toArray();
//EC_Debug::diedump($row);
if($k == 0) {
echo '<tr>';
foreach($row as $f=>$v) {
echo "<th>$f</th>";
}
echo '</tr>';
}
echo '<tr>';
foreach($row as $f=>$v) {
$extra = '';
if($f=='id') {
$extra = '<a href="' . $this->url(array('controller'=>$this->controller, 'action'=>'edit', 'id'=>$v), null, true) . '"><img src="' . $this->baseUrl() . '/style/icons/application_edit.png" border="0" alt="edit"></a>';
$extra .= ' <a href="' . $this->url(array('controller'=>$this->controller, 'action'=>'delete', 'id'=>$v), null, true) . '"><img src="' . $this->baseUrl() . '/style/icons/cancel.png" border="0" alt="delete"></a>';
}
echo "<td>$extra $v</td>";
}
echo '</tr>';
}
echo '</table>';
echo $this->paginationControl($this->paginator, 'Sliding', '_paginator.php');
}else{
echo 'no results...';
}
Pagination Controls Partial
<?php if ($this->pageCount): ?>
<div class="pagination">
<?php if (isset($this->previous)): ?>
<a href="<?= $this->url(array('page' => $this->previous)); ?>">« PREV</a> -
<?php endif; ?>
<?php
/* Page links */
foreach ($this->pagesInRange as $page): ?>
<a href="<?= $this->url(array('page' => $page)); ?>" <?php if($page == $this->current): ?>id="selected"><?php endif; ?><?= $page; ?></a>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
- <a href="<?= $this->url(array('page' => $this->next)); ?>">Next ></a>
<?php endif; ?>
</div>
<?php endif; ?>
August 26, 2009
10 Comments
If you are getting a weird “cant’ save customer” message in your local Magento development environment when trying to save a new account, but the bug is not on your live store, this might be the solution..
If like me you not only develop Magento sites but also use Zend Framework for other projects (which Magento is based upon) then you might find that there are some clashes between your version of Zend Framework and the Magento version.
For Magento development, you need to be sure that your Magento install is using its own version of Zend Framework and not your own separate copy. To do this you have a choice of either changing your php include path to remove your separate Zend Framework folder or alternatively edit the top of app/Mage.php and make this edit edit on line 31.
//Mage::register('original_include_path', get_include_path());
Mage::register('original_include_path', '');
If you develop using Zend Framework you will know that it is sometimes tricky to see exactly whats going on in terms of SQL queries. After trying a few different ideas including subclassing the database classes or other complex systems, the easiest I have found is this:
1. Edit your app.ini config file and add a line:
db_profiling_enabled = false
Then in your development section in your ini file, set the same value to true
2. Add the following lines to your bootstrap.php after the database adapter setup.
// DATABASE ADAPTER - Setup the database adapter
// Zend_Db implements a factory interface that allows developers to pass in an
// adapter name and some parameters that will create an appropriate database
// adapter object. In this instance, we will be using the values found in the
// "database" section of the configuration obj.
$dbAdapter = Zend_Db::factory($configuration->database);
//$dbAdapter = new EC_Db_Mysqli($configuration->database->params);
if($configuration->db_profiling_enabled){
// create a new profiler
$profiler = new Zend_Db_Profiler_Firebug('EdmondsCommerce DB Queries Debug');
// enable profiling (this is only recommended in development mode, disable this in production mode)
$profiler->setEnabled(true);
// add the profiler to the database object
$dbAdapter->setProfiler($profiler);
}
Note you may need to move this chunk above the database adapter section:
// CONFIGURATION - Setup the configuration object
// The Zend_Config_Ini component will parse the ini file, and resolve all of
// the values for the given section. Here we will be using the section name
// that corresponds to the APP's Environment
$configuration = new Zend_Config_Ini(
APPLICATION_PATH . '/config/app.ini',
APPLICATION_ENVIRONMENT
);
This is based on a modified quickstart layout for a project. If you have decided to use an alternative layout, you should be able to tell where the relevant code should be.
You will need to have the Firebug firefox extension to view this output. If you also install the FirePHP extension for firebug then there are even more cool things that you can do.