Archive

Archive for the ‘General’ Category

CakePHP ajaxed pagination and sort

May 16th, 2009

Here I will describe how I did an Ajaxed pagination for one of my projects using jQuery and Livequery Plugin. Currently I am working on a huge project which, hopefully, will feed me with some ideas for blog posts and this is one of them :) . So:

1. Loading the javascript libs

Loading the jQuery and Livequery was done by Autoloader helper, but if you don’t use it just include jQuery and Livequery in your layout with following code

<?php
echo $javascript->link('jquery.min');
echo $javascript->link('plugins/jquery.livequery');
?>

Read more…

CakePHP, Development, General, JavaScript, Labs , , ,

Creating Wholesale Solution with Magento Commerce

April 17th, 2009

osCommerce to Magento migrationMy first approach for this post was to explain my first impressions from Magento Commerce, but I decided to explain how I managed to create a Retail/Wholesale solution required for a current project.

The requirement (so far, because it’s an ongoing project):

The client want to have a shop where regular customers to be able to see products with their retail price, while Wholesale partners to see the prices with ? discount. The extra condition: retail and wholesale prices hasn’t mathematical dependency. So, a product could be $100 for retail and $50 for whole sale and another one could be $60 retail and $50 wholesale. And of course retail users should not be able to see wholesale prices at all.

Basically, I will explain what I did step-by-step, but in order to understand what I mean, you should be familiar with the basics of Magento.

1. Creating two magento websites, stores and views
(Magento meaning of website of course) It’s done from from System->Manage Stores. The result is:
Website | Store | View
————————————————
Retail->Retail->Default
Wholesale->Wholesale->Default

Both sites using the same category/product tree

2. Setting the price scope
in System->Configuration->Catalog->Catalog->Price set drop-down to Website. Now you could enter prices per store/website and they could be totally different.

3. Get some plugins
Get following plugins from Magento Connect and install them from admin: System->Magento Connect->Magento Connect Manager:
Netzarbeiter_LoginCatalog – User need to login in order to see the store (it will be used for Wholesale site)
Netzarbeiter_CustomerActivation – User need to be approved from site admins in order to be able to login to the site. (again it will be used for wholesale site)

Both plugins need to be activated for wholesale only. Because they are activated when they are installed, you need to disable them for Default/Retail website and to leave enabled to Wholesale. You should know that distinction between sites in System->Configuration is done from top left corner of the config window.

First plugin is enabled/disabled from: System > Configuration > Catalog > Login only catalog
Second one: System > Configuration > Customer > Customer Activation.

4. Setting separate url for Wholesale
Now wholesales need to have separate urls, so regular users will access http://domain.com/, while wholesale will access http://domain.com/wholesale/. I found this solution in the Magento Forum: Thread.

So, following the instructions I created directory wholesale/ and copied .htaccess and index.php files from the root directory. Modifications in the index.php are the same as in the Forum:
Mage::run(); become Mage::run(’wholesale’);
and
$mageFilename = ‘app/Mage.php’; become $mageFilename = ‘../app/Mage.php’;

5. Change the wholesale paths from the admin
From System->Configuration (select Wholesale website)->General->Web and change the paths by adding wholesale/ (it’s also mentioned in the forum thread).

6. Adding products to both websites
When adding products, you should mark them visible for both sites. This is done from Product page->Websites tab.

That’s it! Now on http://domain.com/ users will see full catalog, they can login without Admin approval and prices will be retail, while on http://domain.com/wholesale only users registered as wholesale and activated from admin will be able to see catalog with wholesale prices.

What’s left…

And this was the easiest part … the rest is to import about 2000 products from the current osCommerce store, and to add another 4000 from the client’s ERP system. After this on regular basis to update prices and quantities from ERP system. :)

Hopefully this will help someone.

Development, General , , ,

New hosting for this blog

February 25th, 2009

Hi guys,

if someone tell you that it’s easy to start writing in your blog after looong break – it’s a lie :)

Just wanted to say that this blog was moved to a new host. It was long time planned, but I’ve always delayed. The reason for movement according to the hosting provider was, that it exceeds the limit of the CPU time. For me a blog with less than 100 posts should not be such BIG problem…

Here is the stats of CPU usage from my account.

2009-02-18:      27.45
2009-02-19:      26.60
2009-02-20:      24.21
2009-02-21:      20.22
2009-02-22:      23.40
2009-02-23:      28.73

For me is really strange, and because the current host is really my server where I have control over all resources I will check what caused this load.

Anyway, the guys from the hosting company where really kind and supportive, and even proposed to pay me some compensation about this inconvenience, so it was (and still is) pleasure to work with them.

That’s it.

General

Strange issue with captcha field

January 24th, 2009

Captcha caseWell, it’s more an observation than a real problem.

For my current CakePHP project I had to set a captcha field to a user registration form. I decided to be “creative” and I set the captcha image as background of the input field. In fact the graphical representation wasn’t bad at all. Unfortunately when it’s used, the captcha word shows wrong image and of course the result was wrong. To be correct the first attempt was always ok, but the second one (let’s say if the user decided to register again) the captcha was always wrong.

I checked everything especially after the image in Javascript library case and I couldn’t find anything suspicious.

The solution came when I removed the image from the background of the field and call it with an <img> tag. This time everything went just fine. This make me think that it’s a cache problem. I didn’t dig it deeply, because for now it’s working and as you can see it’s looking better.

So, an advise from me – never put your captcha image as background of your field, or call through css. Just use good old <img> tag instead.

Development, General, PHP , , , , ,

Book review: CakePHP Application Development

January 12th, 2009

CakePHP Application Development

In the beginning of December I’ve been asked to write a review of a book called CakePHP Application Development. The interesting thing was that I received a copy of the book exactly on my birthday – 29-th of December (probably consequence, but it was really nice). In this article I will write about what this book covers and my opinion of the content. Hope it will be a good guide for these of you who will decide to buy a copy of it from Amazon.com.

What this book covers

First two chapters start with some theoretical explanations about concepts and patterns which are used in the Framework as well as the process of installation of the framework.

The next chapter explain how to build a really simple application. The readers could use to with the framework way of coding, everything in this chapter is hand crafted, so people could actually see how it’s works.

After this there are 4 chapters which explain in details how the Models, Controllers and Views are working in details.

There is one chapter which explain how to build an scaffolded application with the Bake console script. There is an explanation how to create Models, Controllers and Views.

The next chapters explain how to build a real world example with CakePHP called Quickwall (Questions and Answers), which is different from standard blog creation example. In these chapters the authors upgrade and optimize the app and expand it’s functionality, so at the end it could be used in the real world.

The good things

  • Even though it’s really difficult to write for a framework which still is in development, where some coding conventions could be changed, this book cover almost everything which is currently used in CakePHP1.2
  • The book is build with example driven approach which is really helpful for understanding from the developers
  • Each article is separated in sensible 3 sub-sections: introduction, or theoretical part, Time for action and What Just Happened. This approach is really useful, because first, explained what will be done in the current chapter, the second part display the actual code snippets and the third one explain step by step the code presented in the previous part. For me it’s really good approach of writing a technical book
  • Using non trivial building a blog is also a plus, I personally don’t think that anyone will write a new blog platform, just because for fun. The Quickwall application could be used in real world without any problems.

What I didn’t like

  • It’s opposite of the first thing in the previous list – just because the framework in still in motion the book is jist a little bit outdated. There are few code snippets where I found that for example condition word is in the right part, while at this moment it’s moved to the left. The code in the book was:
    'conditions' => array('ModelName.field_name' => 'LIKE value')

    while it should be

    'conditions' => array('ModelName.field_name LIKE' => 'value')
  • There are some things which are missing although they are well known – the behaviors. The same as the authors explained about the components and helpers, they should take a moment and explain the behaviors as well. In fact this is totally missing in this book.
  • Although the validations are well explained in the book, I miss the list of methods provided from the core.
  • There isn’t any information about the internationalization, which for me as developer working with many people and different languages is essential.

The conclusion

I would recommend this book for PHP developers who are new to the framework and they are willing to understand the core functionality of it. With the good approach of introduction-code-explanation, it will be really easy to learn how to use the CakePHP. This book could build a base, but it cannot create from you an advanced CakePHP developer (well I think it’s not the main purpose of it anyway). The learning is ongoing process and people which are willing to learn could start with this book, but after this, they need to continue reading other materials, as well as start with real development tasks, because the practice is the best teacher invented ever.

Here is a sample chapter from the book kindly provided from Pakt Publishing

Reviews by others:

CakePHP, General , ,

The last post for 2008

December 30th, 2008

Merry Christmas and Happy New Year to all readers of this blog!

This is my last post for this year and I could say I am pretty happy with the results achieved. There are 42 posts and 311 comments on them. Hopefully some of the posts helped someone, which is the main goal of this blog.
So, next year I hope they will be at least 1.5 times more. (at least I am thinking for stable growth) :) .

Ok, the main reason for this post is completed, now it’s time to show you what brought me Santa Claus … a second monitor as well as good Video Card with 2 outputs, so now I am working on dual monitor machine. Here is the picture of my new work place:

Dual screen

Adding second screen on Ubuntu is really piece of cake – I was ready to go after 15 min including the HW mounting :) Hopefully this addition will increase my productivity :)

That’s all folks. See ya next year! Happy New Year to everyone!

General, Tools, Ubuntu , ,

Careful with JavaScript includes

December 11th, 2008

Ok, this is not a code snippet article. It’s just an experience which you probably already met, but it was nightmare to find and it took me 1/2 a day to fix this “stupid” bug.

So what is the case?

Working on a project including some advanced JavaScript and Ajax techniques my coworker Milen noticed that the Session is not behaving as expected. In a simple function like:

function test($id = false){
  if ($id != false) {
    echo $id;
    echo $k = $this->Session->read('some_var');
    $this->Session->write('some_var', $id);
  }
  $this->set('tests', $this->paginate());
 }

The result should be quite easy to be predicted: if you pass for example 5 on the second reload the $k should be with the same value as $id. Unfortunately instead of 5 the $k was ‘images’. Yep, quite strange, isn’t it?

if you put die() at the end of the function, the result is as expected.

What was the problem

In our current project we are using jQuery and some of it’s plugins. So the problems was in the ThickBox plugin. If you remove it from the header everything works.

Digging into unpacked version of the plugin we’ve noticed that the loading picture is not where it should be. there is an variable

var tb_pathToImage = "images/loadingAnimation.gif"

and as you may notice the path is not compatible with Cake convention and obviously it’s not in the http://server/cakeapp/tests/test/images/.

In the example above we were writing id into the session. Yes but calling: http://server/cakeapp/tests/test/images/loadingAnimation.gif mean that $id take value of ‘images’.

It was quite tricky, because if you loading CSS or JavaScript and the file is not there, FireBug or even the html /if there is no correct CSS the styling will fail/ will warn the developer, but image loaded into the JS function is quite difficult to find.

Anyway, the conclusion is “Watch you JavaScript libs and what files they require”.

Ajax, CakePHP, Development, Frameworks, General, JavaScript, Labs, PHP , ,

That’s my face

December 2nd, 2008

last week I found this site [That's my face] and I decided to take a try.

The process of submission is very easy. You need 3 images (front, left side and right side), once submitted you need to specify some key points which will make these images to become 3D object. Once you finish this, your face went on queue and it will be ready after couple of ours and the site will send you notification mail.

Official description of the service:

How it Works : Take a frontal and profile photo of your face, upload it to our servers and within a few hours we’ll generate your facial profile which includes:

Site features:

  • Your face at 20, 40 and 60 years old
  • Your face as an African, Indian, Asian or Caucasian
  • Your face as man or woman
  • Your caricature
  • Identify your facial asymmetries
  • Attractiveness rating
  • Compare yourself to others and find you look-alikes
  • Buy your custom-made FaceStatue!

I really liked the ages simulation. :)

Here is how I will look at 60 years:
That's my face

There is also analysis of your facial features:

  • 61 Shape Features
  • 26 Asymmetric Shape Features
  • 36 Skin Features

There is also “similar faces” comparison:

  • People with similar shape+skin
  • People with similar shape
  • People with similar skin
  • People with similar asymmetries

It’s a really big fun using it! I would recommend you to take a try.

External Sites, General , , , ,

My first Wordpress plugin

November 28th, 2008

Hey,

I am very proud to present you, my first plugin for Wordpress platform – Autocompleter.

The plugin adding autocomplete functionality for the search input field of your blog. The values are the tags and categories existing in the blog and this way you will help your visitors to find easily the proper information in your blog.

My first implementation was with Prototype and Script.aculo.us, but because I like very much jQuery library and I found a wonderful plugin for autocomplete, I build it with jQuery.

You can check the demo in this blog – top right – search box :)

Hope you will like it and you will vote for it :) Thanks

The official page is: wordpress.org/extend/plugins/autocompleter

Ajax, Development, General, JavaScript, Labs , , , ,

A new skin

November 27th, 2008

Well, it was time to change something in this blog and here it is – a brand new skin from iNove.

I hope you will like it.

General , ,