Wednesday, November 26, 2014

MySQL query for Baisc Product Infomration in Magento

Product List:

SELECT
  core_website.name AS siteName
, core_website.code AS siteCode
, core_store_group.name AS storeName
, core_store.code AS storeCode
, catalog_product_entity.entity_id
, catalog_product_entity.entity_type_id
, catalog_product_entity.attribute_set_id
, catalog_product_entity.type_id
, catalog_product_entity.sku
, catalog_product_entity.updated_at
, prodName.value AS prodName
, prodPrice.value AS prodPrice
, prodWeight.value AS prodWeight
, cataloginventory_stock_status.qty
FROM core_website
INNER JOIN core_store_group ON core_website.website_id = core_store_group.website_id
INNER JOIN core_store ON core_website.website_id = core_store.website_id
INNER JOIN catalog_product_website ON core_website.website_id = catalog_product_website.website_id
INNER JOIN catalog_product_entity ON catalog_product_website.product_id = catalog_product_entity.entity_id
INNER JOIN catalog_product_entity_varchar AS prodName ON catalog_product_entity.entity_id = prodName.entity_id
INNER JOIN catalog_product_entity_decimal AS prodPrice ON catalog_product_entity.entity_id = prodPrice.entity_id
INNER JOIN catalog_product_entity_decimal AS prodWeight ON catalog_product_entity.entity_id = prodWeight.entity_id
INNER JOIN cataloginventory_stock_status ON core_website.website_id = cataloginventory_stock_status.website_id AND catalog_product_entity.entity_id = cataloginventory_stock_status.product_id
WHERE
1 = 1
AND core_website.website_id = 1 # US Site
AND core_store_group.group_id = 1 # US Store
AND core_store.store_id = 1 # English

AND catalog_product_entity.entity_type_id = 4 # Product
AND catalog_product_entity.type_id = 'simple' # Configurable product has no "weight"

### go to eav_attribute table for other attributes
AND prodName.attribute_id = 71 # Product Name
AND prodName.store_id = 0 # admin store
AND prodPrice.attribute_id = 75 # Product Price
AND prodPrice.store_id = 0 # admin store
AND prodWeight.attribute_id = 80 # Product Weight
AND prodWeight.store_id = 0 # admin store

AND cataloginventory_stock_status.stock_id = 1 # Default Stock (Warehouse ?)

ORDER BY catalog_product_entity.sku

With extra attributes:

SELECT
  core_website.name AS siteName
#, core_website.code AS siteCode
#, core_store_group.name AS storeName
#, core_store.code AS storeCode
, catalog_product_entity.entity_id
#, catalog_product_entity.entity_type_id
#, catalog_product_entity.attribute_set_id
#, catalog_product_entity.type_id
, SUBSTR(catalog_product_entity.sku, 1, 2) AS itemNum2Char
, SUBSTR(catalog_product_entity.sku, 1, 3) AS itemNum3Char
, catalog_product_entity.sku
, catalog_product_entity.updated_at
, prodSizeOptionValue.value AS prodSize
, prodColorOptionValue.value AS prodColor
, prodName.value AS prodName
, prodURLKey.value AS prodURLKey
, prodPrice.value AS prodPrice
, prodWeight.value AS prodWeight
, cataloginventory_stock_status.qty
FROM core_website
INNER JOIN core_store_group ON core_website.website_id = core_store_group.website_id
INNER JOIN core_store ON core_website.website_id = core_store.website_id
INNER JOIN catalog_product_website ON core_website.website_id = catalog_product_website.website_id
INNER JOIN catalog_product_entity ON catalog_product_website.product_id = catalog_product_entity.entity_id
# Product Size
INNER JOIN catalog_product_entity_int AS prodSize ON catalog_product_entity.entity_id = prodSize.entity_id
INNER JOIN eav_attribute_option_value AS prodSizeOptionValue ON prodSize.value = prodSizeOptionValue.option_id
# Product Color
INNER JOIN catalog_product_entity_int AS prodColor ON catalog_product_entity.entity_id = prodColor.entity_id
INNER JOIN eav_attribute_option_value AS prodColorOptionValue ON prodColor.value = prodColorOptionValue.option_id
# Product Name
INNER JOIN catalog_product_entity_varchar AS prodName ON catalog_product_entity.entity_id = prodName.entity_id
# Product URL Key
INNER JOIN catalog_product_entity_varchar AS prodURLKey ON catalog_product_entity.entity_id = prodURLKey.entity_id
# Product Price
INNER JOIN catalog_product_entity_decimal AS prodPrice ON catalog_product_entity.entity_id = prodPrice.entity_id
# Product Weight
INNER JOIN catalog_product_entity_decimal AS prodWeight ON catalog_product_entity.entity_id = prodWeight.entity_id
# Product Quantity
INNER JOIN cataloginventory_stock_status ON core_website.website_id = cataloginventory_stock_status.website_id AND catalog_product_entity.entity_id = cataloginventory_stock_status.product_id
WHERE
1 = 1
AND core_website.website_id = 1 # US Site
AND core_store_group.group_id = 1 # US Store
AND core_store.store_id = 1 # English

AND catalog_product_entity.entity_type_id = 4 # Product
AND catalog_product_entity.type_id = 'simple' # Configurable product has no "weight"

### go to eav_attribute table for other attributes
AND prodSize.attribute_id = 133 # Walker Size
AND prodColor.attribute_id = 134 # Walker Color

AND prodName.attribute_id = 71 # Product Name
AND prodName.store_id = 0 # admin store

AND prodURLKey.attribute_id = 97 # Product URL KEY
AND prodURLKey.store_id = 0 # admin store

AND prodPrice.attribute_id = 75 # Product Price
AND prodPrice.store_id = 0 # admin store

AND prodWeight.attribute_id = 80 # Product Weight
AND prodWeight.store_id = 0 # admin store

AND cataloginventory_stock_status.stock_id = 1 # Default Stock (Warehouse ?)

ORDER BY catalog_product_entity.sku

jQuery UI tab active color background

        $j('#productExtraInfoDiv').tabs({
          create: function(event, ui) {
            $j('.ui-widget-header').css('background', '#9b9b9b url("")');
            $j('.ui-widget-header').css('border', '0px');
            $j('.ui-widget-content').css('background', '#ffffff url("")');

            $j('.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited').css('color', '#000');
            $j('.ui-state-default').css('background', '#9b9b9b');
            $j('.ui-state-default').css('border', '0px');
            $j('.ui-state-default').css('padding-bottom', '0px');

            $j('.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited').css('color', '#ffffff');
            $j('.ui-state-active').css('background', '#9b9b9b');
            $j('.ui-state-active').css('border', '0px');
            $j('.ui-state-active').css('padding-bottom', '0px');
          },
          activate: function(event, ui) {
            $j('.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited').css('color', '#000');
            $j('.ui-state-default').css('background', '#9b9b9b');
            $j('.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited').css('color', '#ffffff');
            $j('.ui-state-active').css('background', '#9b9b9b');
          },
        });

Tuesday, November 25, 2014

Magento Get Add to Cart URL of any Product

Method 1:

$_productId = 166;
$_product = Mage::getModel('catalog/product')->load($_productId);
$_url = Mage::helper('checkout/cart')->getAddUrl($_product);
echo $_url;

Method 2:
echo $this->getSubmitUrl($_product);

Sunday, November 23, 2014

Tar Extract a Single File(s) From a Large Tarball

Q. I've couple of large tarballs such as www.tar and images.tar. Is it possible to extract a single file or a list of files from a large tarball such as images.tar instead of extracting the entire tarball? How do I extract specific files under Linux / UNIX operating systems?

A. GNU tar can be used to extract a single or more files from a tarball. To extract specific archive members, give their exact member names as arguments, as printed by -t option.

Extracting Specific Files

Extract a file called etc/default/sysstat from config.tar.gz tarball:
$ tar -ztvf config.tar.gz
$ tar -zxvf config.tar.gz etc/default/sysstat
$ tar -xvf {tarball.tar} {path/to/file}

Some people prefers following syntax:
tar --extract --file={tarball.tar} {file}
Extract a directory called css from cbz.tar:
$ tar --extract --file=cbz.tar css

Wildcard based extracting

You can also extract those files that match a specific globbing pattern (wildcards). For example, to extract from cbz.tar all files that begin with pic, no matter their directory prefix, you could type:
$ tar -xf cbz.tar --wildcards --no-anchored 'pic*'
To extract all php files, enter:
$ tar -xf cbz.tar --wildcards --no-anchored '*.php'
Where,
  • -x: instructs tar to extract files.
  • -f: specifies filename / tarball name.
  • -v: Verbose (show progress while extracting files).
  • -j : filter archive through bzip2, use to decompress .bz2 files.
  • -z: filter archive through gzip, use to decompress .gz files.
  • --wildcards: instructs tar to treat command line arguments as globbing patterns.
  • --no-anchored: informs it that the patterns apply to member names after any / delimiter.

http://www.cyberciti.biz/faq/linux-unix-extracting-specific-files/

Saturday, November 22, 2014

Surprisingly Undervalued Books

I saw ‘Moneyball’ recently. It’s about a baseball coach who takes on a failing team and turns them into a huge success. His method? Acquire players who seem terrible, but are actually good. In other words, find undervalued baseball players.
This got me thinking about books. I’ve read some great books recently which I wouldn’t have heard of by reading ‘best of’ lists or going through an A-Z of the classics. In almost all cases, I heard of them through bloggers or forums. Yet I consider these to be some of the most important books I’ve read so far.
These books don’t look like they’ll be worth much on the surface, and turn out to be really great. They’re undervalued.
I’m not necessarily talking about obscure books/authors here. I’m talking about the ratio of how good the book is to how good you expect it to be. These are the outliers, the ones that most people don’t talk about very much or haven’t heard of, and yet turn out to be profoundly brilliant.
One interesting pattern these books display – with the caveat that this is a very small sample size – is that they’re generally in a particular niche. ‘Impro’, for example, is disguised as a drama book but turns out to be a book about education philosophy, creativity, the theory of narrative and the role of status in human interaction; ‘The Inner Game of Tennis’ looks like a tennis instruction manual and turns out to be a book about Zen, the ‘two selves’, and other things.
I’d love to find more of these. So if you know of any, please email me, Facebook me, tweet me, whatever.
The list so far:
1. ‘Impro’ by Keith Johnstone. Learning certain sets of concepts – like Newtonian mechanics, calculus, comparative advantage – changes the way you see the world. ‘Impro’ gave me at least a piece of the set of concepts for understanding human interaction at a conscious, theoretical level. Yet it’s a totally unpretentious book about improvisational drama.
This is probably the book I’d recommend the most from this list to the average person.
2. ‘The Inner Game of Tennis’ by Timothy Gallwey. This is supposed to be a book about getting better at tennis, but only one chapter is devoted to the actual mechanics of tennis. Instead, it’s a great instruction manual on emotion, stress, Zen Buddhism, and achievement. Frankly, it blew my mind.
You can get a taste it it in this brilliant video with Alan Kay, but it’s only a fraction of the kind of thing you’ll find in this book.
3. ‘The Philosophical Investigations’ by Ludwig Wittgenstein. This is probably the book with the most ‘classic’ status of the bunch. I find that it’s thoroughly undervalued by philosophers, though, who see it as an arcane and eccentric work of little value. And ordinary people don’t bother reading it, probably for good reason: it’s a difficult thing to read. However, spending the time to understand it is hugely rewarding.
Ironically for a book ignored by most philosophers, it contains the answers to a lot of their questions, and the method for answering all of them.
4. ‘Raise High The Roofbeams, Carpenter / Seymour: An Introduction’ by J.D. Salinger. I was tempted to put ‘Franny and Zooey’ here too, but I think it has enough devotion that it’s disqualified. This collection of two stories by Salinger, however, is much less well known. Yet I’d put this in my fiction top 5. I must have read Seymour: An Introduction about 20 times.
I’ve recommended this to a few people and only one other person has liked it as much as I do. Most people didn’t get it. I’m not sure what conclusion to draw from that.
5. ‘Shakespeare’s Sonnets’ by Stephen Booth. If you don’t get poetry, read Stephen Booth. Maybe you’ve read some poems and really like them, but you can’t articulate exactly why beyond just gesturing. Booth gives a definition of why poems are good that is, I think, objective enough that you could develop a computer-generated index of the goodness of a poem out of it. Not everyone will agree with it, but I’ve found it works really well. Wikipedia has a good list of some of his stuff online here.
6. ‘Principles‘ (pdf) by Ray Dalio. Dalio’s a hedge fund manager – the most successful one in the world. His firm, Bridgewater, is known for being radically transparent: every meeting is recorded and recordings are available to anyone (so I could access the recordings of a meeting between two managers discussing my feedback, for example).
This is good reading if you’re in business and want to understand what makes a good company culture, and how to solve problems. It’s also good reading in general, because Dalio has a relentlessly rational, critical take on things and it’s good for people to see that kind of mind at work. He talks a lot about how to achieve things as well, which is always useful. His advice here is better than any self-help book.
7. ‘Drawing on the Right Side of the Brain’ by Betty Edwards. Again, this blew my mind. I sucked at drawing as a teenager, and this book taught me how to do it. She specializes in teaching people to draw competently over short periods of time using what I can only describe as extremely clever hacks.
In the process, the book also taught me that (a) with hard work and the right methods, you can learn most things, and your barriers are probably mental; (b) ‘bad’ drawers don’t look at the thing itself and draw its shape, they translate reality into abstract concepts first and then draw what that concept visually looks like, and a great way to prove this (and hack the process) is to copy a drawing upside down; (c) seeing things as they really are is harder than you think.
8. Ray Carney: not naming a particular book here. Like the other books here, his writings seem to be just about films, but if you read them deeply enough they turn out to be a recipe for more than that – in this case, how to be a good, empathetic human being. He got me into John Cassavetes, which alone makes him worth the read. His writings on film are amazing. You can find a bunch of them via Wikipedia.
I actually don’t expect most people to like the books on this list – that’s just a sober prediction. To me, though, that’s a good sign. If everything I liked was what everybody would like, then I’d have something to worry about.

http://nabeelqu.com/blog/surprisingly-undervalued-books/

程序员和绘画

今天,我打算说一说绘画是如何帮助我更好的编程的故事。
在一年半之前,如果让我绘画,我除了能用5条线和一个圈画出一个人的形状外,画不出更复杂的图案。我既不认为曾经会过,也不认为以后可能会。但我错了。
如果你能画出这个,就能画出一切。
有一天,我在Hacker News上看到一篇有趣的文章,里面介绍了一些能够帮助我们通过自学来提高自己的书籍,这些书的特点是虽是自学,但不会让你感觉到是一种学习任务。涉及到很多方面,而最有价值的就是这本《像艺术家一样思考(Drawing on the Right Side of the Brain)》,因为它里面提到的方法非常简单,正中我的下怀。
当我最终把它拿到手,开始阅读时….奇迹发生了。这本书是我见到的最好的一本“how-to”书籍,它用非常奇特的方法教你绘画。它并不告诉你绘画技巧知识,它也不推荐你去画一些简单的图形、像学生那样练基本功。它一开始就通过一些简单的练习让你相信你可以绘画,增强你的自信。而这正是我最需要的。
这真是一个意外的礼物。
我通读了这本书,完成了里面每个练习,然后停了下。我停下来是因为这本书已经让我实现心愿——想去证实我不是一个在绘画领域毫无希望的人。我不知道拿我的这些新学的本领去干什么,于是我又恢复了以前业余时间所干的事情——开发游戏,写关于编程的博客。停止了绘画,直到3个月前。
你应该明白,当一个人在开发视频游戏时,他很自然的需要去体验和分析大量的其它种视频游戏,尤其是那些个人独立出品的,你的脑子里经常会出现这样的声音:“喔欧,太漂亮的了,真希望我也能画出这样的场景”,但马上又会想:“没有什么能难倒我的,因为我读了那本书,我也会绘画。”于是,经过了几次这样的刺激后,我再也忍不住要拿起铅笔和纸了。
我又开始了素描。起初,我是在工作之余做这些事情,但很快发现,在具备了一些基本技巧后,我能非常迅速的完成简单的素描,于是我开始尝试在每当遇到新的编程问题、思路卡住的时候画画。让我吃惊的是,我的开发效率大幅提高。
每个程序员都应该深知这一点:编程中更重要的是思考,而不是敲代码(如果你不认同这一点,那你应该改行做打字员)。当在研究一个麻烦问题时,你思考,思考,思考,阅读关于你的问题的文章,思考,也许做一些盲目的实验,再思考,终于赢来了“哦”的时刻,然后,剩下的就是敲代码了。
但这里会出现一些小问题,至少对我是这样。我有拖延症,它会出现在我思考的间隔中。因为专注思考是一件很难的事,收邮件、看微博却是很容易的事。这个毛病在程序员中很普遍,我就是一个永远都在同自己的消极怠工做斗争的人,使用了各种精良武器,但很遗憾,都没有解决核心问题,而是让我更分心。绘画是我的武器库里最后一种武器。

于是,现在我会每天拿出一到两个休息时间来绘画——当我感觉累了或需要大脑放松时。画简单的素描,临摹名画,或完全涂鸦。每次最多20分钟,大多时候这些时间是够用的。绘画后我感觉非常好。
2次休息 x 20分钟 = 这幅画和放松的大脑
我不知道为什么绘画能帮助我编程,我想可能有两个主要原因:
  1. 绘画不会中断工作状态。 绘画也是在工作,只是形式不同。也许正好和逻辑思维工作的编程补充。而看微博会很快打断你的工作状态,比大锤敲脑袋更具破坏力。
  2. 绘画跟编程不一样,它使用的是另外一半大脑,绘画时,大脑在整理你之前的思维。这纯属个人观察,没有科学论据,你也不必相信我。但我认为就是这样的。
放松并不是我要绘画的唯一原因,但的确是很重要的原因之一。并且它有助我做其它事情。希望你能喜欢这篇文章!


http://www.vaikan.com/drawing-as-a-programmer/

我的一天是这样度过的

大家好!我是Semih Yağcıoğlu.
我是一个程序员。我生活中土耳其首都安卡拉。我喜欢编程,挑战难题永远是让我兴奋的事情。
我会写一些我感觉有趣的东西。
这是长话短说——来和我喝一杯咖啡,我们可以细聊。
这些年来我养成了一些生活及工作上的习惯。我想这些习惯也许会对你有些启发。

早上

每天大概在6点到6点半间起床。不需要闹钟。我要求是自然醒。7点钟左右吃早餐。锻炼15到30分钟。在出门上班前,我会选出今天要完成的3个最重要的任务。
早晨是安静的。早晨我注意力最容易集中,能完成更多的任务。所以我努力在上班前尽可能的多完成几项事情。

工作

我拒绝同时做个事情。同时做多个事情会一个都做不好。我一次只做一件事。
我总是对任务划分优先级。我的座右铭是马克·吐温的一句话,“早上先活吞一只青蛙,那你余下的这一天时间将不会再遇到比这更糟糕的事情了。”
不管是工作还是业余时间,我都奉行收件箱0原则[0]。如果邮件箱里还有没有处理完的邮件,我有三种处理方式:回复,删除,或转给他人处理。最终,它们都会进入归档状态。
不管做什么,我都会尽全力专心一致。为了达到这种状态,我会在工作时关掉或清除所有的干扰因素。只有这样我才能专心的干那些真正重要的事情。
我会把任务分块,我使用番茄时间管理法,它能帮助我专注于当前的任务[2]。做事情的期间我尽量不中断,坚持一口气完成。如果你把任务分成20分钟的任务块,每20分钟不中断,你会惊奇于你的工作效率。它让我保持了工作动力,让我能头脑清醒的干活。这种一次次的小冲锋、一次完成一个任务块的方式,让我感觉工作变成了游戏。
工作中间穿插短时间的休息,这些休息时间里我做我任何想做的事情,和朋友喝咖啡,浏览Quora, Hacker News 或者 Stack Overflow,这些都是我在休息时间最喜欢的活动。

饮食

我不喜欢一个人吃饭。我总是和朋友或同事一起吃。这是一种很好的社交方式。聊些小东西,想法,项目等,这些能让我了解外面发生的事情。这跟你的工作繁忙与否无关,毕竟大家都要吃饭。
我喜欢到外面吃,哪都行。这能让你保持新鲜感,而且有助于清理大脑。

做笔记

我使用一个方形的Moleskine笔记本和一种黑色钢笔做笔记。我养成了bullet journal[3]的习惯。我会尽可能的记下所有有用的信息。没次当我重新翻阅以前的旧笔记时,我都会惊奇于发现一些已经忘记的好东西。
除了用纸质笔记本外,我一直还用手机或电脑本做记录。但是,如果你没有好好的组织这些笔记,它们的混乱会让你很麻烦。所以,我制订了一些规范来管理我这些笔记。手机做笔记非常方便。但有时候你也会遇到使用手机或电脑笔记本做笔记不方便的时候。比如会议中别人会以为你在聊天或发短信。所以我学会了随身带一个纸质笔记本。因为提着电脑走到哪带到哪并不方便,所以带个本子就成了习惯。特别是,我把它放在枕边。你不知道什么时候灵感会突然冒出来。
工具
我使用Evernote来保存所有的想法。能用它的地方我尽量使用它。我把它装在所有设备上。将所有的物理东西都数字化,保持到Evernote里,会最大化的避免信息混乱。
我使用GitHub存储我的所有项目,甚至我的写作。
我喜欢写作,我使用Web应用ZenPen写作,用的是一个有标记语言的编辑器[4]。它很简单,也很漂亮。我使用LaTeX写学术论文,也会用一些其它的看起来很酷的东西写[5]。
我用RSS阅读文章。我偶尔玩Twitter。我从来不去Facebook。
我使用Pomodoro应用,它非常简单,其实就是一个计时器。
晚间
晚饭后我继续工作。睡觉前我会做一会儿身体锻炼,一般不超过15分钟。这能让我保持清醒,有助于工作。
睡前我会回顾一下做的笔记。包括本子上记录的和电脑里记录的。我会清理完收件箱,每个邮件都做出相应的处理。
回顾笔记后我会计划明天的事情。知道下一步该怎么做是解决掉了一个肩头的重担。
无论我如何疲劳,我都会为我自己做一个事情。读一本书,看一个电视节目,或写一些我喜欢的东西。这对我很重要,我会坚持下去。

标注

[1] Inbox zero 是指清理干净你的收件箱,消灭所有纷扰的事情。
[2] Pomodoro 是一种把工作分成25分钟左右的时间段,中间休息5到15分钟的方法。
[3] Bullet journal 如果你喜欢做笔记,这是个很好的东西。
[4] ZenPen 是一个极简主义的Web应用,是我目前发现的最好用的写作工具。它能帮助你专心写作。我使用标记语言,存到本地可以离线写作。
[5] LaTeX 对你的眼睛很好。每次我看一个文档,不论是不是打印出来的,我都能看出它是不是用LaTeX编写的。它就是这么漂亮。
感谢Kevin McKeown启发我写这篇文章,还感谢 Evrim Doğanyiğit, Aykut Aras, 和 Mehmet Kordacı 预览这篇文章的草稿。

http://www.vaikan.com/this-is-how-i-work/

Friday, November 21, 2014

How to delete parent element using jQuery

what about using unwrap()

<div class="parent">
<p class="child">
</p>
</div>

after using - $(".child").unwrap() - it will be;

<p class="child">
</p>

http://stackoverflow.com/questions/6647736/how-to-delete-parent-element-using-jquery

Magento add products to cart programatically

Method 1:

$cart = Mage::getSingleton('checkout/cart');
$productIds = array(1,2,3,4);

foreach ($productIds as $productId) {
  $product = Mage::getModel('catalog/product');
  $product->load($productId);
  $cart->addProduct($product);
  $cart->save();
}

Method 2:

app/code/local/BTS/AddMultipleProducts/controllers/AddController.php;

<?php
class BTS_AddMultipleProducts_AddController extends Mage_Core_Controller_Front_Action {
 
    public function indexAction() {
        $products = explode(',', $this->getRequest()->getParam('products'));
        $cart = Mage::getModel('checkout/cart');
        $cart->init();
        /* @var $pModel Mage_Catalog_Model_Product */
        foreach ($products as $product_id) {
            if ($product_id == '') {
                continue;
            }
            $pModel = Mage::getModel('catalog/product')->load($product_id);
            if ($pModel->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
                try {
                    $cart->addProduct($pModel, array('qty' => '1'));
                }
                catch (Exception $e) {
                    continue;
                }
            }
        }
        $cart->save();
        if ($this->getRequest()->isXmlHttpRequest()) {
            exit('1');
        }
        $this->_redirect('checkout/cart');
    }
 
}
?>

http://www.danneh.org/2011/09/adding-multiple-products-cart-simultaneously-magento-part-2/#ixzz3JkEd6JY6

How To Install Git on a CentOS 7

# yum install git

# git config --global user.name "FirstName LastName"
# git config --global user.email "username@mydomain.com"

# git config --global core.editor vim
# git config --global merge.tool vimdiff
# git config --global color.diff auto
# git config --global color.status auto
# git config --global color.branch auto

# git config --list
# cat ~/.gitconfig

# git help

Magento get product and related products by ID or SKU

Get product by product ID:

$_productId = 166;
$_product = Mage::getModel('catalog/product')->load($_productId);

Get product by product SKU:

$_sku = 'logitechcord';
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku);

Get product ID by product SKU:

$_sku = 'logitechcord';
$_catalog = Mage::getModel('catalog/product');
$_productId = $_catalog->getIdBySku($_sku);

Get related products by product ID:

$_relatedProductsId = $_product->getRelatedProductIds();

$relatedProducts=array();
$i=0;

foreach($_relatedProductsId as $relatedProductId)
{
  $_tmpObj = Mage::getModel('catalog/product')->load($relatedProductId);
  $relatedProducts[$i] = $_tmpObj->getName()
    . ' ' . $_tmpObj->getPrice() . ' ' . $_tmpObj->getWeight() . ' ' . $_tmpObj->getDescription()
    . ' ' . $_tmpObj->getImage()
    . ' ' . $_tmpObj->getSmallImage()
    . ' ' . $_tmpObj->getThumbnail()
    . ' ' . $_tmpObj->getImageUrl()
    ;

  $i++;
}

Magento to change update product image when a link button clicked

$j('.mytest').on('click', function(e){
  e.preventDefault();
  var target = '<img src="asdf.png">';
  ProductMediaManager.swapImage(target);
});

Difference between Mage::getSingleton() and Mage::getModel() in Magento

Hello all of you today I will explain you what is Difference between Mage::getSingleton() and Mage::getModel() in Magento.

Mage::getSingleton()

Mage::getSingleton() will first check the same class instance is exits or not in memory. If the instance is created then it will return the same object from memory. So Mage::getSingleton() faster then Mage::getModel().

$product1 = Mage::getSingleton('catalog/product');
$product2 = Mage::getSingleton('catalog/product');

$product1 and $product2 both will share same memory of OS and return only one instance each time.

Mage::getgetModel()

Mage::getModel() will create a new instance of an object each time even such object exists in configuration.

Example

$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');

$product1 and $product2 both have different instant of same object and also occupy different memory .

Hope you like this.

http://shahkeyul.wordpress.com/2013/07/21/difference-between-magegetsingleton-and-magegetmodel-in-magento/

===

Mage::getModel() will always return a new Object for the given model:
/**
 * Retrieve model object
 *
 * @link    Mage_Core_Model_Config::getModelInstance
 * @param   string $modelClass
 * @param   array|object $arguments
 * @return  Mage_Core_Model_Abstract|false
 */
public static function getModel($modelClass = '', $arguments = array())
{
    return self::getConfig()->getModelInstance($modelClass, $arguments);
}

Mage::getSingleton() will check whether the Object of the given model already exists and return that if it does. If it doesn't exist, it will create a new object of the given model and put in registry that it already exists. Next call will not return a new object but the existing one:
/**
 * Retrieve model object singleton
 *
 * @param   string $modelClass
 * @param   array $arguments
 * @return  Mage_Core_Model_Abstract
 */
public static function getSingleton($modelClass='', array $arguments=array())
{
    $registryKey = '_singleton/'.$modelClass;
    if (!self::registry($registryKey)) {
        self::register($registryKey, self::getModel($modelClass, $arguments));
    }
    return self::registry($registryKey);
}
In your case you always want a completely new Product object/model since every product is unique.

http://stackoverflow.com/questions/18756753/magento-getsingleton-vs-getmodel-issue

Thursday, November 20, 2014

Sharing Shared folders files between Linux, FreeBSD and Windows

FreeBSD Windows Server 2008 Note
NFS Server Client Windows Server 2008 has a built-in NFS client.
NFS Client Server Windows Server 2008 has a built-in NFS server.
SSH Filesystem Server Client SSH Filesystem
SFTP Server Client SyncBack Pro, FileZilla.
SFTP Client Server Core FTP, Bitvise SSH Server WinSSHD, VanDyke Vshell.
SMB/CIFS Server Client
SMB/CIFS Client Server mount_smbfs
RSYNC Server Client
RSYNC Client Server
Samba Server Client
Samba Client Server

Note: The Server Message Block (SMB) Protocol is a network file sharing protocol, and as implemented in Microsoft Windows is known as Microsoft SMB Protocol. The set of message packets that defines a particular version of the protocol is called a dialect. The Common Internet File System (CIFS) Protocol is a dialect of SMB. Both SMB and CIFS are also available on VMS, several versions of Unix, and other operating systems.

Note: SSH Filesystem (簡單好用的 SSH 檔案系統) 工具,讓你只要有 SSH 登入權限,就可以輕易的將遠端資料夾直接掛載到本機,而且連一般使用者也可以使用,甚至於連在 Windows 下都可以自由掛載遠端 Linux 帳號下的任意一個資料夾,真的非常方便。

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365233(v=vs.85).aspx
http://technet.microsoft.com/en-us/library/cc753302(v=ws.10).aspx

Linux Memory Usage 記憶體使用率

free
                      total         used           free     shared     buffers      cached
Mem:       1023916     975816       48100              0      26376     465844
-/+ buffers/cache:      483596      540320
Swap:      2096440    105564    1990876
計算方式
                      total         used           free     shared     buffers      cached
Mem:                a               b                c              d           e               f
-/+ buffers/cache:             g                h
Swap:               i                j                 k
a = 總記憶體大小
b = 配給 buffers 與 cache 的記憶體大小(包含未用的 buffers 與 cache)
c = 剩下的記憶體大小
e = 配給 buffers 但未用的記憶體大小
f = 配給 cache 但未用的記憶體大小
g = buffers 與 cache 被使用掉的記憶體大小,也就是實際被應用程式用走的
h = 那這個就是實際剩下的記憶體大小
a  = b + c
a  = g + h
g = b  – e  –  f
h = c  + e  + f
buffer 與 cache 的區別:
A buffer is something that has yet to be "written" to disk.
A cache is something that has been "read" from the disk and stored for later use.
一般情況下,Linux kernel 會盡可能多地利用 RAM 的空閑空間作為 cache/buffer 以最大幅度地提高系統性能。當系統中運行的應用程序占用的 RAM 增加時,則將 cache/buffer 所占用的空間釋放出來,讓渡給應用程序使用。
Mem: 那一行顯示了實際記憶體的使用率;
Swap: 顯示的是系統 swap 空間的使用率;
-/+ buffers/cache: 則是目前撥給系統緩衝區的實體記憶體數量。
記憶體管理的概觀
當系統開機一段時間後,像是「top」這種傳統的 Unix 工具常常回報少的可憐的可用記憶體數值,在我寫這篇文章的系統中,就算我總共有 512 MB 的記憶體在我的系統裡,但約開機m後三個小時,我只剩下 60 MB 的可用記憶體,那些記憶體到底跑到那裡去了?
用掉最多記憶體的地方是磁碟快取 (disk cache),目前它總共用了超過 290 MB 的記憶 (在 top 裡的「cached」項目中),快取記憶體 (cached memory) 基本上是空閒的,當有新/執行中的程式需要記憶體的話,它會快速的被取回來。
為什麼 Linux 使用這麼多的記憶體來當作磁碟快取 (disk cache) 呢?主要的原因便是:假如 RAM 沒有被使用的話,它便是閒放在那邊浪費著不用。如果把資料放在用 RAM 組成的磁碟上,它的存取速度比直接從硬碟上存取還要快上 1000 倍。假如在快取裡找不到該資料,當然還是得直接從磁碟裡存取,但就如同上面說的,您將可以節省些微的存取時間。
Free中的buffer和cache︰(它們都是佔用內存)︰
  buffer : 作為buffer cache的內存,是塊設備的讀寫緩沖區
  cache: 作為page cache的內存, 文件系統的cache
  如果 cache 的值很大,說明cache住的文件數很多。如果頻繁訪問到的文件都能被cache住,那麼磁盤的讀IO bi會非常小。
/proc/meminfo 解釋參考: http://www.redhat.com/advice/tips/meminfo.html
ref: http://www.wujianrong.com/archives/linux/2.html
ref: http://linux.chinaunix.net/bbs/viewthread.php?tid=887896
對 Memory Usage 的詳細說明及當 Out of Memory 的解決方法參考: http://rimuhosting.com/howto/memory.jsp
Out of Memory
      more /var/log/messages
kernel: Mem-info:
kernel: Zone:DMA freepages:  2916 min:     0 low:     0 high:     0
kernel: Zone:Normal freepages:   758 min:   766 low:  4031 high:  5791
kernel: Zone:HighMem freepages:   125 min:   253 low:   506 high:   759
kernel: Free pages:        3799 (   125 HighMem)
kernel: ( Active: 237940/1195, inactive_laundry: 1, inactive_clean: 0, free: 3799 )
kernel:   aa:0 ac:0 id:0 il:0 ic:0 fr:2916
kernel:   aa:209592 ac:2087 id:1190 il:1 ic:0 fr:758
kernel:   aa:26033 ac:232 id:0 il:0 ic:0 fr:125
kernel: 0*4kB 2*8kB 4*16kB 2*32kB 4*64kB 2*128kB 1*256kB 1*512kB 0*1024kB 1*2048kB 2*4096kB = 11664kB)
kernel: 8*4kB 1*8kB 175*16kB 6*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 3032kB)
kernel: 1*4kB 0*8kB 1*16kB 1*32kB 1*64kB 1*128kB 1*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 500kB)
kernel: Swap cache: add 5156731, delete 5156620, find 19439534/21006374, race 0+19
kernel: 4115 pages of slabcache
kernel: 1566 pages of kernel stacks
kernel: 13 lowmem pagetables, 5378 highmem pagetables
kernel: 32 bounce buffer pages, 32 are on the emergency list
kernel: Free swap:            0kB
kernel: 261760 pages of RAM
kernel: 32384 pages of HIGHMEM
kernel: 5781 reserved pages
kernel: 14591 pages shared
kernel: 116 pages swap cached
kernel: Out of Memory: Killed process 25580 (java).
Quote: http://rimuhosting.com/howto/memory.jsp Resolving: High Java Memory Usage
To determine how much memory you can spare for Java, try this: stop your Java process; run free -m; subtract the 'used' value from the "-/+ cache" row from the total memory allocated to your server and then subtract another 'just in case' margin of about 10% of your total server memory.  The number you come up with is a rough indicator of the largest -Xmx setting you can use on your server.
意思就是配給 -Xmx數值多少m = a – g – a x 10%,應該是這樣子吧!!!@@

http://ssorc.tw/599

幾個 sniffer 監聽網路封包

比較有名的 Wireshark 就不用多說了
不過 wireshark 比較龐大一點
以下幾個比較輕便型的
  1. for windows
  2. 查看每個封包
smartsniff
  1. for windows
  2. 針對 port 80
httpnetworksniffer
  1. 用 perl 搭配 tcpdump
  2. 不過不太容易視別
  1. for windows
  2. 一樣針對 port 80 ,也順便統計數量,是查那個 domain 被大量連線的好工具
websitesniffer
Ngrep + Perl : http://ssorc.tw/?p=1025
#!/usr/bin/perl
#
use strict;
my $limit = shift || 5000;
$|=1;
open (STDIN,"/usr/bin/ngrep -Wsingle -n$limit '(POST|GET)' dst port 80 |");
while (<>) {
 chomp();
 if ($_ =~ /^T /) {
 my $where = $_;
 $where =~ s/ \[AP\] .*|^T //g;
 my $get = $_;
 $get =~ s/.* \[AP\] //g;
 my %get_hash = ();
 my $is_action;
 foreach (split/\.\./,$get) {
 chomp();
 my $name = $_;
 if ($_ =~ /^GET /) {
 $name =~ s/^GET | HTTP\/.*//g;
 $get_hash{'action'} = "$name";
 $is_action = 'GET';
 } elsif ($_ =~ /^POST /) {
 $name =~ s/^POST | HTTP\/.*//g;
 $get_hash{'action'} = "$name";
 $is_action = 'POST';
 } elsif ($_ =~ /Host: /) {
 $name =~ s/Host: //g;
 $get_hash{'host'} = "$name";
 }
 }
 print "\n(--) $where => $is_action http://" . $get_hash{'host'} . "" . $get_hash{'action'};
 }
}

http://ssorc.tw/3427