Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
scLastOrderDetails
[[!FormIt?
&store=`1`
&hooks=`spam,redirect`
&submitVar=`checkout`
&redirectTo=`[[*id:scFirstChild]]`
]]
[[!scLastOrderDetails]]
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<input type="hidden" name="firstname" value="[[!+fi.firstname]]" />
<input type="hidden" name="lastname" value="[[!+fi.lastname]]" />
<input type="hidden" name="address1" value="[[!+fi.address1]]" />
<input type="hidden" name="address2" value="[[!+fi.address2]]" />
<input type="hidden" name="address3" value="[[!+fi.address3]]" />
<input type="hidden" name="zip" value="[[!+fi.zip]]" />
<input type="hidden" name="city" value="[[!+fi.city]]" />
<input type="hidden" name="state" value="[[!+fi.state]]" />
<input type="hidden" name="country" value="[[!+fi.country]]" />
<input type="hidden" name="email" value="[[!+fi.email]]" />
<input type="hidden" name="phone" value="[[!+fi.phone]]" />
<input type="hidden" name="delivery_firstname" value="[[!+fi.delivery_firstname]]" />
<input type="hidden" name="delivery_lastname" value="[[!+fi.delivery_lastname]]" />
<input type="hidden" name="delivery_address1" value="[[!+fi.delivery_address1]]" />
<input type="hidden" name="delivery_address2" value="[[!+fi.delivery_address2]]" />
<input type="hidden" name="delivery_address3" value="[[!+fi.delivery_address3]]" />
<input type="hidden" name="delivery_zip" value="[[!+fi.delivery_zip]]" />
<input type="hidden" name="delivery_city" value="[[!+fi.delivery_city]]" />
<input type="hidden" name="delivery_state" value="[[!+fi.delivery_state]]" />
<input type="hidden" name="delivery_country" value="[[!+fi.delivery_country]]" />
<input type="hidden" name="delivery_phone" value="[[!+fi.delivery_phone]]" />
<input type="hidden" name="delivery_email" value="[[!+fi.delivery_email]]" />
...
<?php
/**
* [[!scLastOrderDetails]]
* Retrieve Last Order Details
* Place this snippet on the CART before checkout and set your formit call to &store=`1`
*/
$user = $modx->getUser();
if($user && $user->isAuthenticated($modx->resource->get('context_key')) {
$id = $user->get('id');
$profile = $user->getOne('Profile');
$extended = $profile->get('extended');
$userdetails = array(
'firstname' => $extended['firstname'],
'lastname' => $extended['lastname'],
'address1' => $profile->get('address'),
'zip' => $profile->get('zip'),
'city' => $profile->get('city'),
'state' => $profile->get('state'),
'country' => $profile->get('country'),
'email' => $profile->get('email'),
'phone' => $profile->get('phone'),
);
$o = $modx->newQuery('simpleCartOrder');
$o->where(array('user_id'=>$id));
$o->sortby('id','DESC');
$o->limit(1);
$orders = $modx->getCollection('simpleCartOrder',$o);
if(!empty($orders)){
foreach($orders as $order){
$billing = $modx->getObject('simpleCartOrderAddress', array('order_id'=>$order->get('id'), 'type'=>'order'));
if(!empty($billing)){
$bill = $billing->toArray();
$userdetails['firstname'] = $bill['firstname'];
$userdetails['lastname'] = $bill['lastname'];
$userdetails['address1'] = $bill['address1'];
$userdetails['address2'] = $bill['address2'];
$userdetails['address3'] = $bill['address3'];
$userdetails['zip'] = $bill['zip'];
$userdetails['city'] = $bill['city'];
$userdetails['state'] = $bill['state'];
$userdetails['country'] = $bill['country'];
$userdetails['phone'] = $bill['phone'];
}
$delivery = $modx->getObject('simpleCartOrderAddress', array('order_id'=>$order->get('id'), 'type'=>'delivery'));
if(!empty($delivery)){
$del = $delivery->toArray();
$userdetails['delivery_firstname'] = $del['firstname'];
$userdetails['delivery_lastname'] = $del['lastname'];
$userdetails['delivery_address1'] = $del['address1'];
$userdetails['delivery_address2'] = $del['address2'];
$userdetails['delivery_address3'] = $del['address3'];
$userdetails['delivery_zip'] = $del['zip'];
$userdetails['delivery_city'] = $del['city'];
$userdetails['delivery_state'] = $del['state'];
$userdetails['delivery_country'] = $del['country'];
$userdetails['delivery_phone'] = $del['phone'];
}
}
}
$modx->setPlaceholders($userdetails,'fi.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.