Post by supak111 » Thu Jan 11, 2024 6:54 am

Just want to be able to add any product_id to checkout in a simple link so something like this
example.com/index.php?route=checkout/checkout/?product_id=10

Can this be added easy to OC 3?

while ago someone help me add coupons straight to cart and it wasn't much code at all so now I can add coupons to cart like this:

example.com/?coupon=10off

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by johnp » Thu Jan 11, 2024 8:05 am

It may be best to use an extension. Search for "Email Cart" in the OC marketplace and you find extensions like these:

https://www.opencart.com/index.php?rout ... n_id=16030

https://www.opencart.com/index.php?rout ... n_id=21677

Opencart 1.5.6.5/OC Bootstrap Pro/VQMOD lover, user and geek.
Affordable Service £££ - Opencart Installs, Fixing, Development and Upgrades
Plus Ecommerce, Marketing, Mailing List Management and More
FREE Guidance and Advice at https://www.ecommerce-help.co.uk


User avatar
Active Member

Posts

Joined
Fri Mar 25, 2011 10:25 am
Location - Surrey, UK

Post by supak111 » Thu Jan 11, 2024 9:22 am

I have a save cart extension which puts your current cart into a URL and saves it to DB but I would have to do each product manually.
More importantly it has a weird URL.

I really need the URL to look something like this:
example.com/?add_product_id=90 OR example.com/index.php?route=checkout/checkout/?add_product_id=

I want to be able to add something like this to the end of any URL on the site: ?add_product_id=20

I found free extension that does EXACTLY what I asked for over at:
https://webocreation.com/auto-addition- ... kout-page/

However it doesn't seem to work. Can anyone take a look and see what the issue maybe?
Extension is only 1 file which goes in: catalog/controller/extension/module/buttonclickcheckout.php

and here is the code:

Code: Select all

<?php
class ControllerExtensionModuleButtonClickCheckout extends Controller
{

    public function add()
    {
        $this->load->language('checkout/cart');

        $json = array();

        if (isset($this->request->get['product_id'])) {
            $product_id = (int) $this->request->get['product_id'];
        } else {
            $product_id = 0;
        }

        $this->load->model('catalog/product');

        $product_info = $this->model_catalog_product->getProduct($product_id);

        if ($product_info) {
            if (isset($this->request->get['quantity']) && ((int) $this->request->get['quantity'] >= $product_info['minimum'])) {
                $quantity = (int) $this->request->get['quantity'];
            } else {
                $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1;
            }

            ////http://opencart.loc/index.php?route=extension/module/buttonclickcheckout/add&product_id=58&options=246_71-247_72
            if (isset($this->request->get['options'])) {
                $soptions = $this->request->get['options'];

                $optionsid = explode('-', $soptions);

                foreach ($optionsid as $optionid) {
                    $optionvalue = explode('_', $optionid);
                    $options[$optionvalue[0]] = $optionvalue[1];
                }
            }

            // $options= array('246'=>71,'247'=>72);

            if (isset($options)) {
                $option = array_filter($options);
            } else {
                $option = array();
            }

            $product_options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);

            foreach ($product_options as $product_option) {
                if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
                    $json['error']['option'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']);
                }
            }

            if (isset($this->request->get['recurring_id'])) {
                $recurring_id = $this->request->get['recurring_id'];
            } else {
                $recurring_id = 0;
            }

            $recurrings = $this->model_catalog_product->getProfiles($product_info['product_id']);

            if ($recurrings) {
                $recurring_ids = array();

                foreach ($recurrings as $recurring) {
                    $recurring_ids[] = $recurring['recurring_id'];
                }

                if (!in_array($recurring_id, $recurring_ids)) {
                    $json['error']['recurring'] = $this->language->get('error_recurring_required');
                }
            }

            if (!$json) {
                $this->cart->add($this->request->get['product_id'], $quantity, $option, $recurring_id);

                $json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), $product_info['name'], $this->url->link('checkout/cart'));

                // Unset all shipping and payment methods
                unset($this->session->data['shipping_method']);
                unset($this->session->data['shipping_methods']);
                unset($this->session->data['payment_method']);
                unset($this->session->data['payment_methods']);
                // Totals
                $this->load->model('setting/extension');

                $totals = array();
                $taxes = $this->cart->getTaxes();
                $total = 0;
                // Because __call can not keep var references so we put them into an array.
                $total_data = array(
                    'totals' => &$totals,
                    'taxes' => &$taxes,
                    'total' => &$total,
                );
                // Display prices
                if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                    $sort_order = array();
                    $results = $this->model_setting_extension->getExtensions('total');
                    foreach ($results as $key => $value) {
                        $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
                    }
                    array_multisort($sort_order, SORT_ASC, $results);
                    foreach ($results as $result) {
                        if ($this->config->get($result['code'] . '_status')) {
                            $this->load->model('total/' . $result['code']);
                            // We have to put the totals in an array so that they pass by reference.
                            $this->{'model_total_' . $result['code']}->getTotal($total_data);
                        }
                    }
                    $sort_order = array();
                    foreach ($totals as $key => $value) {
                        $sort_order[$key] = $value['sort_order'];
                    }
                    array_multisort($sort_order, SORT_ASC, $totals);
                }

                $json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
            } else {
                $json['redirect'] = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']));
            }
        }
        $this->response->redirect($this->url->link('checkout/checkout'));
    }

}

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by paulfeakins » Thu Jan 11, 2024 6:40 pm

supak111 wrote:
Thu Jan 11, 2024 9:22 am
I found free extension that does EXACTLY what I asked for over at:
https://webocreation.com/auto-addition- ... kout-page/

However it doesn't seem to work.
That's the problem with free unfortunately.

If no one fixes this for you for free you might need to pay a developer in Commercial Support.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by supak111 » Thu Jan 11, 2024 10:33 pm

Actually, it does work. Adding item to cart works, and adding quantity works.
Only adding options doesn't seem to work. Do you see any issues in the options code?

I was using the wrong URL structure. URL should look like this:

ADD only item to cart OK: example.com/index.php?route=extension/module/buttonclickcheckout/add&product_id=97
ADD item + quantity OK: example.com/index.php?route=extension/module/buttonclickcheckout/add&product_id=97&quantity=3
BUT options doesn't work: example.com/index.php?route=extension/module/buttonclickcheckout/add&product_id=97&quantity=3&options=24_96

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by DigitCart » Fri Jan 12, 2024 12:29 am

Hi
I have a paid extension that can do that:
Add To Cart By URL link
https://www.opencart.com/index.php?rout ... n_id=36520

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by supak111 » Fri Jan 12, 2024 1:20 pm

Your extension still doesn't allow you to just add this ?add&product_id=90 to any URL on your website and add that item to cart...

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by DigitCart » Fri Jan 12, 2024 6:17 pm

Hi
Try this link please:

Code: Select all

http://digitcart.ir/demo/oc/en/3020/4/index.php?route=extension/module/add_to_cart&product_id=30&option[226]=15&redirect=cart&coupon=2222

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm

Who is online

Users browsing this forum: Bing [Bot], OSWorX, paulfeakins, Semrush [Bot] and 27 guests