protected function getAjaxCartData($data, $cart, $status) {
$config = hikashop_config();
$imageSize = (int)$config->get('addtocart_popup_image_size', 50);
$ret = array(
'ret' => (int)$status
);
if(!empty($cart->messages))
$ret['messages'] = $cart->messages;
if(empty($cart->cart_products))
$ret['empty'] = true;
if(!empty($data['type']) && $data['type'] == 'product' && !empty($data['form']) && count($data['form'])) {
$added = array();
foreach($data['form'] as $prod => $qty) {
if($qty)
$added[] = array('product' => $prod, 'quantity' => $qty);
}
if(count($added) == 1) {
$data = array_merge($data,$added[0]);
}
}
if(!isset($data['product']))
return $ret;
$imageHelper = hikashop_get('helper.image');
if(!empty($cart->products)) {
foreach($cart->products as $product) {
if($product->product_id != $data['product'])
continue;
$ret['product_name'] = $product->product_name;
$ret['quantity'] = (int)$product->cart_product_quantity;
if($imageSize > 0) {
$image_path = (isset($product->images[0]->file_path) ? $product->images[0]->file_path : '');
$img = $imageHelper->getThumbnail($image_path, array($imageSize,$imageSize), array('default' => true), true);
if($img->success)
$ret['image'] = $img->url;
}
break;
}
}
if(!isset($ret['product_name'])) {
$productClass = hikashop_get('class.product');
$product = $productClass->getProduct($data['product']);
$ret['product_name'] = $product->product_name;
$ret['quantity'] = 0;
$image_path = ((isset($product->parent) && isset($product->parent->images[0]->file_path)) ? $product->parent->images[0]->file_path : '');
$image_path = (isset($product->images[0]->file_path) ? $product->images[0]->file_path : $image_path);
$img = $imageHelper->getThumbnail($image_path, array($imageSize,$imageSize), array('default' => true), true);
if($img->success)
$ret['image'] = $img->url;
}
if(!empty($cart->messages)) {
foreach($cart->messages as $msg) {
if(empty($msg['product_id']) || (int)$msg['product_id'] != $data['product'])
continue;
$ret['message'] = $msg['msg'];
break;
}
}
return $ret;
}