Skip to content

Commit

Permalink
Check if PS < 8.0.0 for fetching Referrers
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Apr 6, 2022
1 parent 27a4d4b commit ce465df
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions psgdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public function getCustomerDataFromPrestashop(Customer $customer)
$genderName = $gender->name;
unset($gender);

$customerInfo = [
$data['customerInfo'] = [
'id_customer' => $customer->id,
'gender' => $genderName,
'firstname' => $customer->firstname,
Expand All @@ -784,7 +784,7 @@ public function getCustomerDataFromPrestashop(Customer $customer)
];

// get orders
$orders = [];
$data['orders'] = [];
$orderList = Order::getCustomerOrders($customer->id);

if (count($orderList) >= 1) {
Expand All @@ -793,7 +793,7 @@ public function getCustomerDataFromPrestashop(Customer $customer)
$productsOrder = $orderObject->getProducts();
$currency = Currency::getCurrency($order['id_currency']);

array_push($orders, [
$data['orders'][] = [
'id_order' => $order['id_order'],
'reference' => $order['reference'],
'payment' => $order['payment'],
Expand All @@ -803,80 +803,74 @@ public function getCustomerDataFromPrestashop(Customer $customer)
'total_paid_tax_incl' => number_format($order['total_paid_tax_incl'], 2) . ' ' . $currency['iso_code'],
'nb_products' => $order['nb_products'],
'products' => [],
]);
];
foreach ($productsOrder as $product) {
array_push($orders[$index]['products'], [
$data['orders'][$index]['products'][] = [
'id_product' => $product['product_id'],
'id_product_attribute' => $product['product_attribute_id'],
'product_reference' => $product['product_reference'],
'product_name' => $product['product_name'],
'product_quantity' => $product['product_quantity'],
]);
];
}
unset($orderObject);
}
}

// get carts
$carts = [];
$data['carts'] = [];
$cartList = Cart::getCustomerCarts($customer->id, false);

if (count($cartList) >= 1) {
foreach ($cartList as $index => $cart) {
$cartObject = new Cart($cart['id_cart']);
$productsCart = $cartObject->getProducts();

array_push($carts, [
$data['carts'][] = [
'id_cart' => $cart['id_cart'],
'nb_products' => count($productsCart),
'products' => [],
'date_add' => $cart['date_add'],
]);
];
foreach ($productsCart as $product) {
array_push($carts[$index]['products'], [
$data['carts'][$index]['products'][] = [
'id_product' => $product['id_product'],
'id_product_attribute' => $product['id_product_attribute'],
'product_reference' => $product['reference'],
'product_name' => $product['name'],
'product_quantity' => $product['cart_quantity'],
'total_wt' => $product['total_wt'],
]);
];
}
unset($cartObject);
}
}

// get addresses
$addresses = $customer->getAddresses($id_lang);
$data['addresses'] = $customer->getAddresses($id_lang);

// get messages
$messages = [];
$data['messages'] = [];
$messageList = CustomerThread::getCustomerMessages($customer->id);

if (count($messageList) >= 1) {
foreach ($messageList as $index => $message) {
array_push($messages, [
$data['messages'][] = [
'id_customer_thread' => $message['id_customer_thread'],
'message' => $message['message'],
'ip' => (int) $message['ip_address'] == $message['ip_address'] ? long2ip((int) $message['ip_address']) : $message['ip_address'],
'ip' => (int)$message['ip_address'] == $message['ip_address'] ? long2ip((int)$message['ip_address']) : $message['ip_address'],
'date_add' => $message['date_add'],
]);
];
}
}

// get connections
$connections = $customer->getLastConnections();
$data['connections'] = $customer->getLastConnections();

// get referrers
$referrer = Referrer::getReferrers($customer->id);

$data['customerInfo'] = $customerInfo;
$data['orders'] = $orders;
$data['carts'] = $carts;
$data['addresses'] = $addresses;
$data['messages'] = $messages;
$data['connections'] = $connections;
$data['referrer'] = $referrer;
if (version_compare(_PS_VERSION_, '8.0.0', '<')) {
$data['referrer'] = Referrer::getReferrers($customer->id);
}

return $data;
}
Expand Down

0 comments on commit ce465df

Please sign in to comment.