views:

28

answers:

0

I tried to edit paypal module of PrestaShop, but I think I tangled in a philosophical problem on the code. :(

As I understand when customer redirected to the paypal website, there is no appropriate order inserted in the orders table yet. As soon as customer come back from paypal site, at the end of modules/paypal/validation.php file, validateOrder() function will be called and order will inserted into orders table.

It's completely recognizable till now, but after this my brain slightly farts! There's a serious problem when I see customer will return to order-confirmation.php and it checks the order_id before it inserted into DB! Let me to explain; On the top of order-confirmation.php there's a check about order:

$id_order = Order::getOrderByCartId(intval($id_cart));
...
if (!$id_order OR !$id_module OR !$secure_key OR empty($secure_key))
    Tools::redirect('history.php'.(Tools::isSubmit('slowvalidation') ? '?slowvalidation' : ''));
...
$smarty->assign(array(
    'HOOK_ORDER_CONFIRMATION' => Hook::orderConfirmation(intval($id_order)),
    'HOOK_PAYMENT_RETURN' => Hook::paymentReturn(intval($id_order), intval($id_module))));

It tries to get id_order associated to the cart (id_cart), but as I explained there's no associated order yet, so Order::getOrderByCartId returns false. In the next line customer will be redirected to the history.php and Hook::orderConfirmation will not never called and no order placed!

I can't believe if you say it's a bug, but I can't understand where I'm wrong. Any help will be appreciated :)