Tag: PHP

Magento Professional customer’s password hashing

So you want to import customer accounts but you’ve to generate the password hash? here you’ve the algorithm used by Magento Professional (which is different from Magento Community, but you can easily find that one in the net):

$passhash = hash("sha256", $salt . $password) . ":$salt";

By the way, for the community it’s

$passhash = md5($salt . $password) . ":$salt";

Create a custom order attribute in Magento

I’ve run into a few posts about this thing but none of them was working out of the box so I took all the info and glued them together so…

if you’ve to create a custom attribute for a Magento order but you don’t have a module (and its installer script) simply create a php file in the project’s root with this code:

require_once(‘app/Mage.php’);
Mage::app()->setCurrentStore(Mage::getModel(‘core/store’)->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = newMage_Sales_Model_Mysql4_Setup;
$attribute = array(
‘type’ => ‘text’,
‘backend_type’ => ‘text’,
‘frontend_input’ => ‘text’,
‘is_user_defined’ => true,
‘label’ => ‘Your attribute label’,
‘visible’ => true,
‘required’ => false,
‘user_defined’ => false,
‘searchable’ => false,
‘filterable’ => false,
‘comparable’ => false,
‘default’ => ”
);
$installer->addAttribute(‘order’, ‘your_attribute_code’, $attribute);
$installer->endSetup();

This attribute is a “text” and it’s made not to be visible but just to use it as a container for some data you may need in your custom development, more info may come in comments if you need.

P4A 3.8.4 is out!

Another maintenance release for our beloved project, here you’ve the changelog:

- “meta viewport” tag was added to mask’s HTML for a better mobile rendering
- P4A::getMetaViewport() and setMetaViewport() methods were added
- p4a_center_elements() javascript funcion now removes marginLeft/paddingLeft
from the first visible column of the first P4A_Frame widget
- a bug with P4A_Frame and multiple CSS classes was solved
- P4A_Table’s arrow symbols were because the past ones weren’t shown on mobile
devices
- an ob_clean() call was added to P4A_Thumbnail_Generator::outputThumbnail()
method
- Zend Framework was updated to 1.11.10
- P4A_Table’s image cols do not throw exception anymore if the image
does not exist
- P4A_Field_loadSelectByArray helper now supports a second parameter to specify
the array’s primary key field name

Download P4A 3.8.4

P4A 3.8.3 is out!

A few improvements on different areas, here you’ve the changelog:

- P4A_DB_Navigator now supports query defined sources
- a bug with P4A_Data_Source::saveUploads() was solved
- a bug with P4A_Table’s image cols (without GD installed) was solved
- P4A_DB_Navigator now triggers a beforeclick event
- all p4a_load_js calls were migrated to require.js
- a bug with P4A_DB_Source::deleteRow() called when in newRow state was solved
- p4a_ajax_enable javascript function was added
- a bug with P4A_GD constant default definition was solved
- P4A_Mask::restart() method was added
- Zend Framework was updated to 1.11.7
- translations were updated
- P4A_DB_Source::load() method now checks for duplicate calls and throws an error

Download P4A 3.8.3

P4A 3.8.2 is out!

This is a minor release but it contains really a lot of great upgrades and fixes, here you’ve the changelog:

- Zend Framework was updated to 1.11.6
- CKEditor was updated to 3.6.0
- jQuery UI was updated to 1.8.11
- requirejs was added
- P4A_Dir_Source automatically sorts files
- P4A_Dir_Source::setPageLimit() calling was disabled
- P4A_Dir_Source’s page limit is now set to 0 (disabled)
- autocomplete values are now sorted and unique
- P4A_Field::getSource() method was added
- p4a_load_js now uses requirejs
- P4A_Field and P4A_Data_Fields now support the “datetime” type
- P4A_Field and P4A_Data_Fields now support the “time” type
- P4A_Object::dropImplement() now turns the action to lowercase
- deprecated method P4A_Object::dropMethod() was removed
- a javascript bug with P4A_DB_Navigator’s drag&drop functionalities was solved
- P4A_DB_Navigator now correctly supports source with non-default DSN

Download P4A 3.8.2

Some tests for P4A 4.0

In the last few weeks I’ve been thinking a lot about the future of P4A, there would be a lot of small things to do but I wanted to think about something big enough for a major release jump.

Some time ago we discussed about the rendering layer, at the moment we generate all the HTML and we use our custom CSS + some jQuery/jQuery UI goodness to enhance everithing a little bit. Point is that jQuery UI is growing too slowly and we need something bigger and more RIA oriented, like Dojo, ExtJS or Qooxdoo. We discussed about which one would be better and at the moment I’d go with Dojo, it has a great FLOSS license, it’s supported by a lot of major players, it’s highly modular and it has my preferred way of including modules. At last I cannot avoid talking about the new wonderful “Claro” graphical theme, simply amazing.

So I started coding some of P4A’s widgets just to test something out and everything was pretty easy, I’d choose to use the declarative syntax because it was the fastest way to have everything running but now I’m running into a few major problems.

First of all I faced a performance issue, maybe it’s due to dojo’s declarative syntax I chose and I should definetively do a comparison test with the programmatic syntax (also if I do not like generating javascript too much). Another problem is due to the fact that most P4A developers tend to use the easiest P4A’s AJAX stack, which actually redraws all the mask (the body tag) without a full page refresh. To do the dojo has to redraw all the widgets in the mask and so the performance issue is not only visible during the first page loading but on every page redrawing. The user would see the page flicker (if we decide to hide the DOM while dojo is rendering) or the unstyled elements for a sec and than the styled widgets. This is not the best way to go…

But here we’ve the most critical issue, every time the page is redesigned (not using a full page refresh) we’ve a noticable memory leak, dojo keeps allocating memory and this is very very bad. That’s not a dojo problem, I mean, I replease the DOM nodes and recall the dojo parser, but the previously built dojo objects are not removed from memory. Actually I hoped that dojo would have recognized that an element was already parsed but this is not happening. Thus we would have to destroy all dojo objects before redrawing them but this operation will make the page flickering longer.

Conclusions? Hard to tell at the moment. I think I want to try a different way doing a quick test using only dojo’s CSS instead of the whole javascripts also because in a P4A application all the events have to be managen by the server and not by the client. I’ll try to do this kind of test ASAP and let you know some more considerations about this topic.

P4A 3.8.1 is out!

A bugfix release for the 3.8.x serie, if you’re using P4A be sure to update to the new release, here you’ve the changelog:

- jQuery was updated to 1.4.4
- a bug with multiple p4a_load_js calls (with the same url and within the
same loading cycle) was solved
- a bug with MSSQL and query limits was fixed (thanks to Diego Fattori)
- CKEditor was updated to 3.5
- P4A_DB_Source::getRowPosition() now returns 1 if the query throws an error
- P4A_DB_Source::addHaving(), setHaving() and getHaving() methods were added
- Zend Framework was updated to 1.11.2
- a bug with P4A::restart() method was fixed (thanks to Daniel Carrero)
- a bug with P4A_Data_Source::saveUploads() and custom file paths was solved
- a new technique to unload CKEditor was implemented

Download P4A 3.8.1

- UPDATE: due to a SourceForge downtime P4A 3.8.1 tarballs can’t be downloaded at the moment, I’ll update this post when everything will be up again, in the meanwhile you can check out the P4A SVN (tags/3.8.1).

- UPDATE 2: SF should have fixed the problem, P4A 3.8.1 packages are available right now.

Open Source VMware PHP API experiment

I think this post is not useful anymore, now that VMware release their first PHP API for vCloud, anyway I’ve this little code I wrote as an experiment a few months ago that maybe could be used by someone having an old vCloud (the code you’ll see is wrote to work with VMware’s vCloud 2.5) or maybe who needs a simpler implementation.

I only wrote a few methods:

  • login to the VMware server
  • get info about all VMs
  • get info about a single VM
  • create a new VM setting the RAM amount, CPUs number, disk capacity
  • a useful methods that waits till a task (like a VM creation) is completed

The code you’ll download uses the old nusoap library and directly sends the raw XML to the server ’cause no other SOAP libraries/implementations were working at that time and for the time the experiment lived (I never used vCloud systems and I worked on this project less than a couple of days so…).

Here you have a set of sample calls to the library:

require “vim25.php”;
$vim25 = new vim25(“ip-address-of-the-vcloud-server”, “username”, “password”);

$service_content = $vim25->retrieveServiceContent();
$all_vm_info = $vim25->getAllVMInfo($service_content["rootFolder"], VIM25_SUB_INFO_ALL);
$vm_info = $vim25->getVMInfo(“vm-16″, VIM25_SUB_INFO_GUEST);

$debug = $vim25->createVM(
“vm name”,
“group-id”,
“guest-id”,
“resgroup-id”,
“host-id”,
2, // num CPU
512, // RAM
10485760 // disk capacity in kB (10GB)
);

print_r($debug);

If you want to give a try to the code:

  • download the library code
  • rename to vim25.php
  • download and install nusoap in the “nusoap” folder (at the same level of the vim25.php file)
  • use the code above to script the vim25 class
  • extend it and use it :-)

This work is public domain thus do whatever you want with it and enjoy.

P4A 3.8.0 is out!

It took me a couple of month to work on this release, we’ve a pretty long changelog you’ve to be sure to check out because we’ve a lot of important changes that may impact your upgrades.

One of the most important things is that now P4A supports MS SQL, it was quite easy but surely we need a stronger user base to test out every possible scenario. The next big thing is that MySQL connections are now UTF-8 safe, it could hurt your existing applications so please check out the notes in the changelog before upgrating.

- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- P4A_DB’s connection charset is now set to UTF 8
This could lead to possible data corruption, if you’re upgrading from a
previous release and you’re using MySQL or PostgreSQL (Oracle and SQLite
should not be involved in this change) you’ve to be sure to convert the DB
charset to UTF-8 before editing data in your P4A applications.

ALWAYS DO BACKUPS BEFORE ANYTHING ELSE!!!

For MySQL we used this procedure to migrate our DBs:
mysqldump –default-character-set=latin1 DBNAME > dump.sql
open dump.sql and replace this line
/*!40101 SET NAMES latin1 */;
with
/*!40101 SET NAMES utf8 */;
mysql NEWDBNAME < dump.sql
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Support For MS SQL was added, check out the README file
- AJAX STACK REVERTED TO XML (instead of JSON) due to the bugs with jQuery::form
- README file was updated
- CKEditor was updated to 3.4.1
- a new strategy to avoid CKEDITOR loading problems was implemented
- P4A_Data_Fields::getSchemaTableField now correctly handles calculated fields
- a bug with P4A_I18N::format and time fields was fixed
- P4A::__construct() now has a "cache" param, simply pass a Zend_Cache object
to override all Zend_Cache configurations inside P4A
- P4A::getCache() method was added
- P4A_I18N now uses P4A::getCache() to pass an overridden Zend_Cache object to
Zend_Locale_Data
- a bug with "onreturnpress" and IE was fixed
- a bug with multicple CKEditor instances (loaded via AJAX call) and IE
was solved
- CKEditor's forcePasteAsPlainText option was enabled again
- jQuery::form was updated to 2.49
- jQuery was updated to 1.4.3
- file upload percentage and speed is shown while uploading
(if PECL uploadprogress is available, APC not implemented beacuse it does
not work with PHP CGI)
- a bug with autocomplete and HTML tags (in the value) was fixed
- a bug with autocomplete loading was fixed (thank to Lorenzo Valori)
- a bug with CKEDITOR and AJAX was fixed

Download P4A 3.8.0

P4A 3.6.2 available now!

Another 3.6 serie release, let’s take a look at the changelog

- P4A_Field::setSource() now correctly handles null param
- CKEditor was updated to 3.4
- P4A_DB_Source::getRowPosition() now correctly handles multivalue fields
(bug #3057839)
- forcing IE to use his latest rendering engine
- some javascript fixes were applied to make IE ajax system work
- Zend Framework was updated to 1.10.8
- P4A_I18N now correcly handles 3 chars languages (like “fil”)
- translations were updated
- Filipino translation was added (thanks to Elin Eon)

Download P4A 3.6.2