404NotFound_ Posted July 4 Share Posted July 4 Bonjour tout le monde, je suis sur un projet de récupération de données sur propriétés personnalisées du module Cartsguru, mon soucis est le suivant : Lorsque j'ajoute un enfant et ses données, et que j'enregistre dans "Informations personnel" les infos sont stocker dans ma base de donnée correctement et s'affiche et se mettent bien à jour coté Prestashop. Le soucis est que lors de cette première manipulation, les données enfants ne remonte pas, par contre si je rappuie une seconde fois sur "enregistrer" là les données sont correctement envoyées à Carts guru. Je ne comprends pas? (cf log) : 2024-07-04 10:05:47 - Executing SQL: SELECT firstname, dob FROM ps_childrens WHERE id_customer = 6971 2024-07-04 10:05:47 - SQL Result: Array ( [0] => Array ( [firstname] => Pedro [dob] => 2021-12-13 ) ) 2024-07-04 10:05:47 - Children data for customer 6971: Array ( [0] => Array ( [firstname] => Pedro [dob] => 2021-12-13 ) ) 2024-07-04 10:05:47 - Contact data: Array ( [accountId] => [email protected] [civility] => mister [lastname] => Dev [firstname] => Dylantest [email] => [email protected] [homePhoneNumber] => [mobilePhoneNumber] => [countryCode] => [country] => [birthDate] => [language] => fr [storeLanguage] => fr [browserLanguage] => fr [buyerAcceptsMarketing] => false [custom] => Array ( [language] => fr [customerGroup] => Client [child1] => Pedro [bod1] => 2021-12-13 ) ) 2024-07-04 10:07:44 - Executing SQL: SELECT firstname, dob FROM ps_childrens WHERE id_customer = 6971 2024-07-04 10:07:44 - SQL Result: Array ( [0] => Array ( [firstname] => Pedro [dob] => 2021-12-13 ) [1] => Array ( [firstname] => Messi [dob] => 2022-10-10 ) ) 2024-07-04 10:07:44 - Children data for customer 6971: Array ( [0] => Array ( [firstname] => Pedro [dob] => 2021-12-13 ) [1] => Array ( [firstname] => Messi [dob] => 2022-10-10 ) ) 2024-07-04 10:07:44 - Contact data: Array ( [accountId] => [email protected] [civility] => mister [lastname] => Dev [firstname] => Dylantest [email] => [email protected] [homePhoneNumber] => [mobilePhoneNumber] => [countryCode] => [country] => [birthDate] => [language] => fr [storeLanguage] => fr [browserLanguage] => fr [buyerAcceptsMarketing] => false [custom] => Array ( [language] => fr [customerGroup] => Client [child1] => Pedro [bod1] => 2021-12-13 [child2] => Messi [bod2] => 2022-10-10 ) ) Voici la partie de code qui gère la récupération des données (contact.php) : $childrenData = $this->getChildrenData($customer->id); $childrenFirstnames = []; $childrenBirthdates = []; $custom = [ 'language' => isset($customer->browserLanguage) ? $customer->browserLanguage : '', 'customerGroup' => isset($customer->customerGroupName) ? $customer->customerGroupName : '', ]; // Ajouter les informations des enfants au tableau $custom for ($i = 0; $i < min(count($childrenData), 5); $i++) { $childIndex = $i + 1; $custom["child$childIndex"] = $childrenData[$i]['firstname']; $custom["bod$childIndex"] = $childrenData[$i]['dob']; } $params = [ 'accountId' => $accountId ?? '', 'civility' => $civility ?? '', 'lastname' => $lastname ?? '', 'firstname' => $firstname ?? '', 'email' => $email ?? '', 'homePhoneNumber' => $homePhoneNumber ?? '', 'mobilePhoneNumber' => $mobilePhoneNumber ?? '', 'countryCode' => $countryCode ?? '', 'country' => $country ?? '', 'birthDate' => $birthDate ?? '', 'language' => $storeLanguage ?? '', 'storeLanguage' => $storeLanguage ?? '', 'browserLanguage' => $browserLanguage ?? '', 'buyerAcceptsMarketing' => $buyerAcceptsMarketing ? 'true' : 'false', 'custom' => $custom, ]; $this->logData('Contact data: ' . print_r($params, true)); if ($this->helper->isRawEnabled()) { $raw = $this->getRaw($customer, $addresses); if (isset($raw)) { $params['raw'] = $raw; } } return $params; } private function getChildrenData(int $customerId): array { // Ajouter un délai de 4 secondes avant d'exécuter la requête SQL sleep(4); $sql = 'SELECT firstname, dob FROM ' . _DB_PREFIX_ . 'childrens WHERE id_customer = ' . (int) $customerId; $this->logData('Executing SQL: ' . $sql); $dbInstance = Db::getInstance(); $childrenData = $dbInstance->executeS($sql); // Log the SQL error if there's any if (!$childrenData) { $this->logData('SQL Error: ' . $dbInstance->getMsgError()); } $this->logData('SQL Result: ' . print_r($childrenData, true)); $this->logData('Children data for customer ' . $customerId . ': ' . print_r($childrenData, true)); return $childrenData; } private function logData($message) { $logFile = _PS_ROOT_DIR_ . '/log/cartsguru_contact.log'; $timestamp = date('Y-m-d H:i:s'); $fullMessage = $timestamp . ' - ' . $message . "\n"; file_put_contents($logFile, $fullMessage, FILE_APPEND); } Merci à vous pour vos réponses! Bonne journée. Link to comment Share on other sites More sharing options...
Mediacom87 Posted July 5 Share Posted July 5 Bonjour, regardez cela directement avec les développeurs du module cartguru. Link to comment Share on other sites More sharing options...
404NotFound_ Posted July 10 Author Share Posted July 10 Bonjour, J'ai envoyer un mail au support technique j'attends, j'ai essayer d'ajouter un sleep au début de la fonction mais rien n'y fait... Problème de synchro l'envoie des données en DB et la récupération depuis la DB pour Cartsguru se fait au même moment j'ai l'impression. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now