SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1 , 2 , 3 , 4
Topic Change fields in an Address 8419 Views

Re: Change fields in an Address

8 November 2013 at 9:55am

Hi Sebastian,

Thank you for the quick reply and for the clear instructions. I hope my next post will be about reporting success :)

best
Szabesz

Re: Change fields in an Address

8 November 2013 at 2:52pm Last edited: 9 November 2013 11:06am

Hi Sebastian,

I have just tested overwriting process() with extendedProcess() but I think it is not what I need, because it is called when we complete the order, right after pressing the "Buy now" button.

What I need to change is the display of the address on the "order overview page", the one we can see right _before_ pressing the "Buy now" button.

Looking through the code I could not find an easy way to make the custom field available in the template (other than hacking "extractAddressDataFrom()").

It is in SilvercartCheckoutFormStep5.php where data is gathered from the session data to be displayed by <% control AddressData %> in SilvercartCheckoutFormStep5.ss. And the process() or extendedProcess() gets called only afterwards. By that time it is "too late" :)

Any ideas?
Thanx in advance
Szabesz

Re: Change fields in an Address

8 November 2013 at 3:48pm

Hi Szabesz,

ok, that's a problem :D

Erm, perhaps I can help you using a little trick...
I did not really try this and it is a little hacky, but...

Decorate SilvercartAddress and add a method loadAdditionalCheckoutData (or sth. other that makes sense for you).

The decorator should look something like that:

class MyCustomAddress extends DataObjectDecorator {

public function loadAdditionalCheckoutData($for = 'Invoice') {
if (Controller::curr() instanceof SilvercartCheckoutStep_Controller) {
$checkoutData = Controller::curr()->getCombinedStepData();
if (array_key_exists($for . '_State', $checkoutData)) {
$this->owner->State = $checkoutData[$for . '_State'];
}
}
}

}

Now, call this method out of your SilvercartCheckoutFormStep5.ss template every time before including SilvercartAddressDetailReadOnly.ss.

The template controls should look sth. like this:

<% control AddressData %>
<% control SilvercartInvoiceAddress %>
{$loadAdditionalCheckoutData}
<% include SilvercartAddressDetailReadOnly %>
<% end_control %>
<% end_control %>
...
<% control AddressData %>
<% control SilvercartShippingAddress %>
{$loadAdditionalCheckoutData(Shipping)}
<% include SilvercartAddressDetailReadOnly %>
<% end_control %>
<% end_control %>

Inside of your SilvercartAddressDetailReadOnly.ss, you should now be able to call the session stored state value by calling {$State}.

Best Regards
Sebastian

Re: Change fields in an Address

8 November 2013 at 4:30pm Last edited: 9 November 2013 11:07am

Hi,

Tested and works fine :) Thank you very much! It might be hacky a bit, but does the trick and easy to implement.

One more thing though, and as far as I can tell this is the last place where my custom State field is missing: the email templates.

The rendering of these templates is ordered by SilvercartOrder.php, e.g.:

public function getShippingAddressTable() {
return $this->SilvercartShippingAddress()->renderWith('SilvercartMailAddressData');
}

Can we use a similar method that can be called in SilvercartMailAddressData.ss (which renders the address of an email template)?

Best Regard,
Szabesz

Re: Change fields in an Address

8 November 2013 at 4:34pm Last edited: 8 November 2013 4:42pm

Well, I have to correct myself a bit: State is not missing from the emails, but if I just use $State in the template, I get the default value of the Enum (that is the type I use for states), and not the real value stored in the database.

Re: Change fields in an Address

8 November 2013 at 4:40pm

Well, I'd expect this behavior to be a temporal issue.

Is it possible that the email is sent before the value of State is written to database?

Best Regards
Sebastian

Re: Change fields in an Address

8 November 2013 at 4:47pm

Well, right now I'm testing it with an already registered user, whose State field is already in the database and displayed correctly anywhere else. So it does not seem to be temporal issue you have described. But I might be wrong.

bets
Szabesz

Re: Change fields in an Address

8 November 2013 at 4:55pm

A registered customers editable address is not exactly the object that will be used for the order.

In fact, when finishing the checkout, there will be added a copy of the chosen address to process the order.

Every order has its own address objects. This is needed to prevent that a customer can change the shipping or invoice address of an already finished order from the past.

The orders addresses are written by default in SilvercartCheckoutFormStepProcessOrder::process(). I think you've overwritten that by decorator, right?
$order->sendConfirmationMail(); should be called after adding the State value to the addresses.

Could you have a look at this to exclude that it's a temporal issue?

Best Regards
Sebastian