Mar 26, 2012

Mobile: Html meta data and headers

Sample Mobile Meta and headers

<meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/>
<meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no' name='viewport'/>

Magento: Hack - Nested addAttributeToFilter.

I already waste my one whole working day to look on this problem but still can file the solution. So I decide to modify the the magento core.

Here's the condition I want to do in addAttributeToFilter function.

(condition1) OR ((condition2) and (condition3) ..... )


To solve this Fucking problem I modify this class Mage_Eav_Model_Entity_Collection_Abstract.

public function addAttributeToFilter($attribute, $condition=null, $joinType='inner')
{
....Some Code here
if (is_array($attribute)) {
$sqlArr = array();
foreach ($attribute as $condition) {
$sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType);
}
$conditionSql = '('.join(') OR (', $sqlArr).')';
}else{
... your other code here.
}


Here my modify version.

public function addAttributeToFilter($attribute, $condition=null, $joinType='inner')
{
....Some Code here
if (is_array($attribute)) {
$sqlArr = array();
$myAND = array();
$andSqlArr = array();
/*
* @ win mode to support (x=a) or (y=1 and z=0)
* array(
* array(condition)
* 'and' =>
* array(
* array(condition)
* array(condition)
* ),
* )
*
* Output expected
* cond1 OR (cond2 and cond3)
*/
foreach ($attribute as $key => $condition) {
if ($key === "and"){
$myAND = $condition;
continue;
}
$sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType);
}
foreach ($myAND as $key => $andCond ){
$andSqlArr[] = $this->_getAttributeConditionSql(
$andCond['attribute'],
$andCond,
$joinType);
}
$conditionSql = '('.join(') AND (', $andSqlArr).')';
if ($andSqlArr){
$sqlArr[] = $conditionSql;
}

$conditionSql = '('.join(') OR (', $sqlArr).')';
}
... your other code here.
}


In your product collection.

$collection->addFieldToFilter(
array(
array("attribute"=>"your_attribute1", "in"=>array(1,2,3,)),
"and" => array(
array("attribute"=>"your_attribute2", "eq"=>1,),
array("attribute"=>"your_attribute3", "eq"=>1,),
),
)
);


Happy Coding. :)

Mar 22, 2012

SVN: SSL handshake failed: Secure connection truncated

I experience this error in my fedora 14 with svn version

svn --version
svn, version 1.6.17 (r1128011)
compiled Jun 2 2011, 15:23:50

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.apache.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme



Here my command

$ svn export https://mycode.googlecode.com/svn/trunk/ mycode --username admin@syntax3rror.co.cc


Response

svn: OPTIONS of 'https://mycode.googlecode.com/svn/trunk': SSL handshake failed: Secure connection truncated (https://mycode.googlecode.com)


From Jan's Blog instructed to install libneon27 However before in install I check /usr/lib/libneon.so.27 and exist to my filesystem so I just issue.

sudo ln -s /usr/lib/libneon.so.27 /usr/lib/libneon-gnutls.so.27


Cheers.. :)

Magento: Deleting Product

A simple way to delete product is:
$productId = 1;
Mage::getSingleton('catalog/product')
  ->load($productId)
  ->delete();
If you want to delete product by category
$collection = Mage::getSingleton('catalog/category')
  ->load(YOUR_CATEGORY_ID)
  ->getproductCollection();

// If you want to filter by attribute
$collection->addAttributeToFilter('YOUR_ATTRIBUTE_CODE', 'ATTRIBUTE_VALUE')
foreach($collection as $product){
   $product =Mage::getSingleton('catalog/product')
     ->load($product->getId())
   try {
   // Im not sure what is the use of this part
   Mage::dispatchEvent(
     'catalog_controller_product_delete',
     array('product' => $product));
   
   // Finally we not able to delete the product
   $product->delete();
   }catch (Exception $e) {
     echo "Can't delete product w/ id: $product";
   }
}
Reference: Delete magento Product

Mar 15, 2012

Android: Handling of Content-Disposition header on the android browser.

As part web development, something we need to create one script file to handle all download request from your server but, suddenly I try to work on android browser and get an issue on download name.

Scripname download.php
Download name: download.apk which not correct

To fix the issue:

header("Content-Disposition: attachment; filename=\"fast-and-the-furios.apk\"");
header("Content-Type: application/vnd.android.package-archive");






NOTE:
* Besure to put SPACE between attachment; and filename
* Also be sure to quote the filename with double-quote

Content-Disposition: attachment; filename="fast-and-the-furios.apk"



If you want to upload on android try to read this one multipart form upload on android. PS. I did now test his code yet, check in you own either. :)


Happy reading. :)

Mar 13, 2012

Mar 12, 2012

Mysql: How to recover mysql table.

One time I get real problem about mysql table. It was crashed and I don't have any back up on it.

After I get on an internet connected pc I googled it and this helpfull resources.
how-to-repair-corrupted-mysql-tables-using-myisamchk

My Pick pickup line and emo sentence

Pag namatay ako wag ka pupunta, bka pag nakita kita, tumibok uli puso ko. :)


Wla lang gusto ko lang itago. Most data from monster program (The Morning Rush)

Mar 5, 2012

Mar 4, 2012

AppEngine - Guestbook sample

https://developers.google.com/cloud-sql/docs/developers_guide_java#using_the_java_development_server

GWT - Php support

For PHP developer want to use appengine, try this out.

http://www.webdigi.co.uk/blog/2009/run-php-on-the-google-app-engine/

Mar 2, 2012

GWT - Login Manager

Just a recording refernce yet. Sorry I cant get one yet. :(

http://code.google.com/webtoolkit/tools/gwtdesigner/tutorials/loginmanager.html
http://www.dariusz-borowski.com/wp/?p=20
http://www.vogella.de/articles/GWT/article.html

Mar 1, 2012

GWT - How to build multiple or another page.

As a beginner in playing GWT. I don't know to create another page after I done the Getting Stated on GWT documention.
GWT Getting start

While looking on the to this stuff, I found that there was no mutiple page on GWT instead it use widget to display another view on you page.

Read the Alen Post here GWT Concepts No Multiple Pages

Reference:
Here another reference http://colchambers.blogspot.com/2010/08/creating-multiple-page-gwt-app.html