Friday, 9 August 2013

Magento Observer to add order grid column - ambiguous issue

Magento Observer to add order grid column - ambiguous issue

I'm trying to add new column in sales order grid from custom table using
observer. Everything works fine until I try to filter grid using column
created_at.
Problem is because I have same column name (created_at) in custom table
and in sales_flat_order_grid table.
I'm getting this error
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at'
in where clause is ambiguous
If I edit this line 'index' => 'created_at' to 'index' =>
'main_table.created_at', in
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'main_table.created_at',
'type' => 'datetime',
'width' => '100px',
));
everything work fine, but I don't want to change core files or to copy
them to local folder and edit, I think that there is some simple solution
that I need to add to my observer.
Here is my Observer.php
class Testinggrid_ExtendOrderGrid_Model_Observer{
public function salesOrderGridCollectionLoadBefore($observer)
{
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->joinLeft(array('custab' => 'my_custom_table'),
'main_table.entity_id =
custab.order_id',array('custab.field_to_show_in_grid'));
}
}
Here is my module layout
<layout>
<sales_order_grid_update_handle>
<reference name="sales_order.grid">
<action method="addColumnAfter">
<columnId>field_to_show_in_grid</columnId>
<arguments>
<header>Column header</header>
<index>field_to_show_in_grid</index>
<filter_index>field_to_show_in_grid</filter_index>
<type>text</type>
</arguments>
<after>shipping_name</after>
</action>
</reference>
</sales_order_grid_update_handle>
<adminhtml_sales_order_grid>
<!-- apply layout handle defined above -->
<update handle="sales_order_grid_update_handle" />
</adminhtml_sales_order_grid>
<adminhtml_sales_order_index>
<!-- apply layout handle defined above -->
<update handle="sales_order_grid_update_handle" />
</adminhtml_sales_order_index>
</layout>

Regex to split a CSV

Regex to split a CSV

I know this (or similar) has been asked many times but having tried out
numerous possibilities I've not been able to find a a regex that works
100%.
I've got a CSV file and I'm trying to split it into an array, but
encountering two problems: quoted commas and empty elements.
The CSV looks like: 123,2.99,AMO024,Title,"Description, more info",,123987564
The regex I've tried to use is:
thisLine.split(/,(?=(?:[^\"]\"[^\"]\")(?![^\"]\"))/)
The only problem is that in my output array the 5th element comes out as
123987564 and not an empty string.

String format of sharedPreferences

String format of sharedPreferences

I am trying to modify the following code:
dictName = sharedPreferences.getString(PREFERENCES_DICT_NAME, null);
if (dictName == null) {
}
My situation is I know dictName is not null and its value is "something".
So I modified the code into:
dictName = sharedPreferences.getString(PREFERENCES_DICT_NAME, null);
if (dictName == "something") {
}
However, I can't get my code work. So I am wondering is it correct for me
to put dictName =="something"?

Thursday, 8 August 2013

How to send mail for multiple models in rails

How to send mail for multiple models in rails

I am new to rails. I am having problem in mail sending to multiple models.
Our project contains parent,teacher and student models.each module having
number of users(student,parent,teacher). And also I am having three check
box.that is student,teacher,parent.when I click student and teacher.the
mail should be sent to all teachers and all students.
If I want send a mail to teacher and also student means ,the problem
behind this, mail was sending only to teacher not student. how to solve
this problem.and I included my coding.
Controller
def send_news_letter
if params[:announcement].present?
@announcement = Announcement.find(params[:announcement].keys).first
end
if params[:students].present? and params[:teachers].present?
@student = Student.pluck(:email)
@teacher = Teacher.pluck(:email)
UserMailer.send_multiple_email(@student,@teacher,@announcement).deliver
redirect_to announcements_url, :notice => "Newsletter Delivered
Successfully" a
end
end
Usermailer.rb
class UserMailer < ActionMailer::Base
default to: Proc.new {Teacher.pluck(:email)},
to: Proc.new {Student.pluck(:email)},
from: "from@example.com"
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.password_reset.subject
#
def password_reset(user)
@user = user
mail :to => user.email, :subject => "Password Reset"
end
def send_multiple_email(user,employee,announcement)
@user = user
@employee = employee
@announcement = announcement
mail :subject => "Deliver"
end
end
Please help me.Thanks in advance.

How to use webkitdriver in Java

How to use webkitdriver in Java

I have download all the files of
webkitdriver(https://code.google.com/p/webkitdriver/) via SVN. I want to
use the webkitdriver in java, aiming to implement a Ajax web crawler which
can interpret Javascript contents.However, since their are so many
directory in Webkitdriver, I don't know what should I do to let them
support me coding in Java. Has anybody used it before. Can you tell me the
steps such as building the system or importing the needed packages. Thank
you very much!

Problem on using the definition of Riemann Integral

Problem on using the definition of Riemann Integral

Consider the function: $f:[a,b]\rightarrow \mathbb{R}$ be a bounded
function on $[a,b]$. Suppose that $f$ is Riemann integrable on $[a,c]$ for
any $c\in (a,b)$. The question is to prove that $f$ is Riemann integrable
on the interval $[a,b]$.
I am completely stuck on this question. I tried to use the tagged
partition notion for Riemann integrals, but I couldn't figure out a way to
start solving it. I appreciate any help!

retrieving session via cross domain ajax

retrieving session via cross domain ajax

Background:
I'm developing a website tracker using javascript. Here's how it works:
1) A user visits any domain the tracker script is on "anydomain.com". The
script makes a successful ajax call in the background to my master domain
"masterdomain.com".
2) When "masterdomain.com" receives a request, the following PSEUDO code
is run. It works by checking for an existing session and if one doesnt
exist it creates a new one.
The first call appears to be fine because I am able to receive a session
ID in a response. However, each successive call to "masterdomain.com"
creates a new session. AKA the server doesn't find the "should be"
existing session.
Sample PSEUDO Code:
if(session exists)
{
// update timestamp for session
}
else
{
// set a new session for visitor
}
// load template
api(array("accepted"=>session_id),callback);
Some Quick Facts:
1) This does not appear to be a same origin issue (as I am able to
communicate with the server fine).
2) I have tried this with cookies/sessions both appear to not be working.
3) I am using codeigniter (sessions are set not to expire on page close).
I have also tried using/not using database sessions).
This problem can also be solved if there is another way to uniquely
identify a user each time a page loads on a server (not using IP).
Any help would be greatly appreciated as I'm about ready to tear the rest
of my hair out of my head!!!! :(