Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addRecurring missing required variables #7808

Closed
gRoberts84 opened this issue Jan 8, 2020 · 5 comments
Closed

addRecurring missing required variables #7808

gRoberts84 opened this issue Jan 8, 2020 · 5 comments
Labels
3.0.x.x Affects the 3.0.x.x maintenance version

Comments

@gRoberts84
Copy link

What version of OpenCart are you reporting this for?
3.0.3.2

Describe the bug
Errors below are thrown when confirming an order with recurring products:

<b>Notice</b>: Undefined index: product_id in <b>/redacted/public/store/catalog/model/checkout/recurring.php</b> on line <b>4</b><b>Notice</b>: Undefined index: quantity in <b>/redacted/public/store/catalog/model/checkout/recurring.php</b> on line <b>4</b>

To Reproduce
Steps to reproduce the behavior:

  1. Create a recurring profile.
  2. Attach to product.
  3. Configure payment gateway with recurring support (i.e. PayPal Express)
  4. Create order and confirm to payment gateway.
  5. Check order_recurring table if product_id and product_quantity have been populated.

Expected behavior
Expected the product id and quantity to be provided to addRecurring to allow it to be associated with the recurring order.

Screenshots / Screen recordings
image

Server / Test environment (please complete the following information):

  • Local development
  • OSX 10.15.2 (19C57)
  • PHP 7.1.25
  • Nginx 1.15.7
  • Chrome

Additional context
Looking at all uses of addRecurring, it appears only the recurring profile is passed, which does not include the quantity or product id. This is confirmed by carrying out a number of tests using different payment gateways with the same issue.

The SagePay Server payment gateway fails to redirect to SagePay due to the errors being included in the JSON response.

@gRoberts84
Copy link
Author

Also noticed that the addRecurring is expecting other data, i.e. product name, however it's simply using the recurring profile name?!

@straightlight
Copy link
Contributor

straightlight commented Jan 9, 2020

In system/library/cart/cart.php file, find:

'recurring_id' => $cart['recurring_id'],

add right below:

'product_id' => $recurring_query->row['product_id'],

See if that solves the issue. Also found on the master branch.

@gRoberts84
Copy link
Author

In system/library/cart/cart.php file, find:

'recurring_id' => $cart['recurring_id'],

add right below:

'product_id' => $recurring_query->row['product_id'],

See if that solves the issue. Also found on the master branch.

Whilst I have resolved the issue by creating a modification, it is still unfortunately a bug.

<!-- Fix Recurring Order Bug -->
    <file path="catalog/controller/extension/payment/pp_express.php">
        <operation>
            <search><![CDATA[
            $recurring_id = $this->model_checkout_recurring->addRecurring($order_id, $recurring_description, $item['recurring']);
            ]]></search>
            <add position="replace"><![CDATA[
            $recurring_id = $this->model_checkout_recurring->addRecurring($order_id, $recurring_description, $item);
            ]]></add>
        </operation>
    </file>
    <file path="catalog/model/extension/payment/sagepay_server.php">
        <operation>
            <search><![CDATA[
            $recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item['recurring']);
            ]]></search>
            <add position="replace"><![CDATA[
            $recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item);
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
            $recurring_order = $this->getRecurringOrder($recurring['order_recurring_id']);
            ]]></search>
            <add position="replace"><![CDATA[
            $recurring_order = $this->getRecurringOrder($recurring['order_recurring_id']);
            if (empty($recurring_order)) {
                continue;
            }
            ]]></add>
        </operation>
    </file>
    <file path="catalog/controller/extension/payment/worldpay.php">
        <operation>
            <search><![CDATA[
            $order_recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item['recurring']);
            ]]></search>
            <add position="replace"><![CDATA[
            $order_recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item);
            ]]></add>
        </operation>
    </file>
    <file path="catalog/model/extension/payment/sagepay_direct.php">
        <operation>
            <search><![CDATA[
            $order_recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item['recurring']);
            ]]></search>
            <add position="replace"><![CDATA[
            $order_recurring_id = $this->model_checkout_recurring->addRecurring($this->session->data['order_id'], $recurring_description, $item);
            ]]></add>
        </operation>
    </file>
    <file path="catalog/model/checkout/recurring.php">
        <operation>
            <search><![CDATA[
            $this->db->query("INSERT INTO `" . DB_PREFIX . "order_recurring` SET `order_id` = '" . (int)$order_id . "', `date_added` = NOW(), `status` = 6, `product_id` = '" . (int)$data['product_id'] . "', `product_name` = '" . $this->db->escape($data['name']) . "', `product_quantity` = '" . $this->db->escape($data['quantity']) . "', `recurring_id` = '" . (int)$data['recurring_id'] . "', `recurring_name` = '" . $this->db->escape($data['name']) . "', `recurring_description` = '" . $this->db->escape($description) . "', `recurring_frequency` = '" . $this->db->escape($data['frequency']) . "', `recurring_cycle` = '" . (int)$data['cycle'] . "', `recurring_duration` = '" . (int)$data['duration'] . "', `recurring_price` = '" . (float)$data['price'] . "', `trial` = '" . (int)$data['trial'] . "', `trial_frequency` = '" . $this->db->escape($data['trial_frequency']) . "', `trial_cycle` = '" . (int)$data['trial_cycle'] . "', `trial_duration` = '" . (int)$data['trial_duration'] . "', `trial_price` = '" . (float)$data['trial_price'] . "', `reference` = ''");
            ]]></search>
            <add position="replace"><![CDATA[
            $this->db->query("INSERT INTO `" . DB_PREFIX . "order_recurring` SET `order_id` = '" . (int)$order_id . "', `date_added` = NOW(), `status` = 6, `product_id` = '" . (int)$data['product_id'] . "', `product_name` = '" . $this->db->escape($data['name']) . "', `product_quantity` = '" . $this->db->escape($data['quantity']) . "', `recurring_id` = '" . (int)$data['recurring']['recurring_id'] . "', `recurring_name` = '" . $this->db->escape($data['recurring']['name']) . "', `recurring_description` = '" . $this->db->escape($description) . "', `recurring_frequency` = '" . $this->db->escape($data['recurring']['frequency']) . "', `recurring_cycle` = '" . (int)$data['recurring']['cycle'] . "', `recurring_duration` = '" . (int)$data['recurring']['duration'] . "', `recurring_price` = '" . (float)$data['recurring']['price'] . "', `trial` = '" . (int)$data['recurring']['trial'] . "', `trial_frequency` = '" . $this->db->escape($data['recurring']['trial_frequency']) . "', `trial_cycle` = '" . (int)$data['recurring']['trial_cycle'] . "', `trial_duration` = '" . (int)$data['recurring']['trial_duration'] . "', `trial_price` = '" . (float)$data['recurring']['trial_price'] . "', `reference` = ''");
            ]]></add>
        </operation>
    </file>
    <!-- /Fix Recurring Order Bug -->

As you can see from my fix above, it is only passing the recurring profile to the addRecurring which is expecting more information, i.e. quantity, product id, product name, which are not present in the recurring profile when pulled from the database.

@straightlight
Copy link
Contributor

This solution has now been added on the pre-release version.

@faca5
Copy link

faca5 commented Sep 30, 2020

Thank you very much!

@WebkulOpencart WebkulOpencart added the 3.0.x.x Affects the 3.0.x.x maintenance version label Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0.x.x Affects the 3.0.x.x maintenance version
Projects
None yet
Development

No branches or pull requests

4 participants