function template_preprocess_amazon_component_cart in Amazon Product Advertisement API 7.2
File
- amazon_component/
amazon_component.preprocess.inc, line 3
Code
function template_preprocess_amazon_component_cart(&$variables) {
/* ----------------------------------------------------------------- */
/* Request Cart Information
/* ----------------------------------------------------------------- */
// IF :: Cart Exists
if ($cart_creds = amazon_store_get_cart_creds()) {
$cartRequest = amazon_store_http_request('CartGet', $cart_creds);
$i = 0;
if (!empty($cartRequest->Cart->CartItems)) {
foreach ($cartRequest->Cart->CartItems->CartItem as $item) {
$i++;
}
}
// IF :: Check Amazon API Request Errors
if (!empty($cartRequest->error) || $cartRequest->Cart->Request->IsValid != 'True') {
amazon_store_report_error('Failed to get cart', $cartRequest->Cart->Request->Errors);
drupal_set_message(t('Failed to get cart.'), 'error');
}
// IF :: Cart Request Is Valid
// Set template variables (cart, subtotal, etc.)
if ($cartRequest->Cart->Request->IsValid == 'True') {
$variables['cart'] = $cartRequest->Cart;
$variables['subtotal'] = (string) $cartRequest->Cart->SubTotal->FormattedPrice;
$variables['cart_total'] = $i;
}
/* User Name & Image
/*--------------------------------- */
if (!empty($variables['user']->uid)) {
$user = user_load($variables['user']->uid);
$variables['username'] = $variables['user']->name;
$variables['userImage'] = theme('user_picture', array(
'account' => $user,
));
}
else {
$variables['userImage'] = "<img class='no-avatar' src='sites/default/files/user/avatar-default.jpg'>";
}
}
}