Jump to content

A REEEEAL Tough one for PRESTASHOP Pros


alpaca

Recommended Posts

Hey everyone,

This is a really tough one that only the season pro's can help with (but if anyone else can help that would be great)

Scenario:
1. new customer add products to cart, registers and is at checkout.
2. Customer enter "please drop parcel at house number 17" in the additional comments text box.

This additional comment for some reason goes into the ps2_addresses - "other" column. I need this to go into a newly created column in the ps2_orders table called "opccomments". I have created the column, but cannot find where to charge the code to insert this into the new column and what to change to do this.

Any ideas? I am hoping (as everyone does) to have an answer tonight if at all possible.

P.S I have searched and have been working on this all day - so if anyone can make it any easier I would really appreciate it.

Link to comment
Share on other sites

Hi alpaca,
maybe this could help -- but it's really dirty hardcoding ;)

The class responsible to store the address data - including field "other" is "classes/Address.php". There you'll find the definition of the fields, their validation procedures etc. This class descends from class "ObjectModel" in the same directory, which contains methods add() and update(). These write the data into the database.

Now comes the dirty work: Go to class Address and add methods add() and update() there. Let them execute the parent's code to not break the regular functionality. Then obtain the field value of "other" and write your own SQL to save it where you want.
E.g.

class Address extends ObjectModel
{
public function add(...)
{
parent::add(...);
... DO YOUR SQL HERE
}
}



Lemme know if I earned those £20 ;)

Greets, Mork

Link to comment
Share on other sites

  • 2 weeks later...

Hi Mork,

Thank you for the effort. I really do appreciate it. Maybe I can make this easier to understand. Is there anywhere I can just change the query to add this to the ps2_orders table called “opccomments" column instead of the standard ps2_addresses – “other” column.

Does this make sense? I just want to change the code that enters this information into our newly created column instead of the regular area it adds it.

Link to comment
Share on other sites

I don't see any other column in the addresses table in my installation, what I do get is a message in the order messages.

And there is not a line of code that you can change to make it enter the data to another table. PrestaShop uses classes to handle most of the SQL. The base class automatically generates the SQLs based on the table name and the fields defined in the child class.

Link to comment
Share on other sites

Hi WL,

When we enter any info into the "additional information" form upon checking out, we add the text "avatar" and then complete checkout. We then search the SQL DB through PHPAdmin and find the string "avatar" under this table: ps2_addresses and in the "Other" column.

Link to comment
Share on other sites

Hi alpaca,

really, there's no way to achieve your goal by changing a single line of code. (Maybe using hooks would be easier -- but I have no experience with that and can only guess.)

I have assembled a working example how to set a field in the "orders" table with data from a newly registered account. Put the code into the "Address" class (file "classes/Address.php"). The main difficulty is, of which order you want to set the field? Please see comments in code for details.

   /**
    * Do this if a new account is registered
    *
    * Add a similar method update() to capture changes in an existing account.
    *
    * Method must have the same signature as parent's ObjectModel::add()
    */
   public function add($autodate = true, $nullValues = false)
   {
       // Perform whatever Prestashop performs when a new account is registered.
       $orig_result = parent::add($autodate, $nullValues);
       // Quote string without outer quotation marks
       $other = pSQL($this->other);
       // Build SQL statement to add.
       // CAVEAT: 1. You may need to adjust the table name for your installation
       //         2. Field opccomments does not exist in the original Prestashop. So we
       //            use field `gift_message' instead. Adjust this to your needs.
       // You must determine the ID of the order in which you want to put the `other' string.
       // Maybe it's an existing order, like in this example.
       $id_order = 1;
       $q = "UPDATE ps_orders SET gift_message='$other' WHERE id_order=$id_order";
       // Obtain instance of current database connection...
       $dbh = Db::getInstance();
       // ...and execute your statement
       $dbh->Execute($q);
       // Maybe you need to create a new order. Then you have to
       // gather data about the new order and do sth. like this:
       #$id_lang = 3; // ID of language DE in my installation
       #$id_order = NULL; // Do not load an existing order
       #$my_order = new Order($id_order, $id_lang);
       #$my_order->id_carrier = ...; // Set all needed properties
       #$my_order->gift_message = $other;
       #$my_order->add();

       // Return original result of add() method
       return $orig_result;
   }

Link to comment
Share on other sites

let's clarify: there are two "additional information" fields. One is related to the address and the other is related to the order.

The one related to the address is saved in ps_address table, 'other' field.
The one related to the order is saved in ps_message table, 'message' field. It has also an 'id_order' value associated with it.

Both of them you can see in the BO in Orders.

So I think you don't need to change anything, just to understand what is what.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...