I am setting up an e-commerce site using OpenCart and I want to offer subscriptions. Specifically 3/6/12 months subscriptions. I am NOT interested in recurring billing (I am
This functionality is way outside what Opencart is built for, but if you have some familiarity with PHP/CodeIgniter then you should be able to do most/all of the mods. SQL will be good to know as well, but if you don't already it is fast to learn.
I would say your mods come in 2 parts each with it's own level of difficulty.
I am setting up an e-commerce site using OpenCart and I want to offer subscriptions. Specifically 3/6/12 months subscriptions. I am NOT interested in recurring billing (I am aware that there are modules for PayPal and Authorize.net). I want users to pay once in advance. Does this translate to 3 pseudo-products from a configuration point of view? I guess this is feasible, so far, just with product configuration. 3 products, each with one price.
Here comes the tricky part. For every month the users have paid they have access to order a product, only once a month, within their "billing cycle". So, if a user pays for a 3 month subscription on 23/5:
he can get one product in the period 23/5-22/6, one in 23/6-22/7, and one in 23/7-22/8
I think what I would do for this is add a product for each subscription length, and each product with issue them the appropriate account credit, and have this credit the perfect amount to buy one product per month for the subscription length.
To do this I recommend adding a function to add the funds into the customer_transaction field in the database in the file catalog>model>checkout>order.php (or any model you choose) then call it and add data in catalog>controller>checkout>success.php.
I think it would be smart to verify that the customer has purchased the appropriate subscription product and to verify that there has not been a credit for that purchase already.
To ensure they get only 1 product per month you will need to write a script to the beginning of catalog>controller>checkout>checkout.php to redirect them to an error message if they try to get products too often.
A user should not be able to order more than one products per month, and he should not also be able to get any products after 22/8, unless he renews his subscription. Moreover, it would be awesome if I could have a cron job, checking if a user has utilized his subscription for the current month, and send a "Hey, get your product for this month" kind of reminder email.
I don't even know where to start on this one, but if you are willing to pay you could post for help and probably add this function for a good price.
This is my first OpenCart project, I have gone through the documentation and Googled a lot, I have played with a local installation, and I am trying to figure out if what I am asking is feasible without modifying the core code, I would like to avoid that. However, if there is no other way, I understand that OpenCart is an MVC(+L(anguage)) framework, but I haven't found any solid documentation on how to customize its functionality, only bit ans pieces for specific requirements.
Again, this is way outside of what Opencart is built to do and will take several modifications. As for documentation on how to Opencart scripting works and how to customize it, I haven't found any either. It's been quite a struggle for me to learn what I have over the last 2 months, but if your questions are short you can usually get people to help you along the way when you need it.
If I may, I would like to write down, what I have in mind, please, advise if this sounds OK:
I would like to add one more entity (object/model) for storing the subscription, the user to which it belongs, start and end date and
whether it has been utilized. Basically, a subscription is a normal order and I would like it to be stored like one, I just need to persist a few more fields.
I would add these as attributes, you can do this in the administration on the back end of the website catalog>attributes, catalog>attribute groups, and catalog>products in the attributes tab.
As I said, I need to run two checks: Has the user utilized his subscription for the current month? For this I was thinking about having a flag "isUsed" field, which can be reset with a cron job, everytime a user reaches his billing date. (in our example 23/6, 23/7). Alternatively I could add 3 entries, one for each billing cycle and update them accordingly. Has the subscription expired? I could check against the expiry date of the subscription.
I don't know how to do this cron job but if you can figure that out you could search the database for the attribute name(s) and values then apply your cron job if the values are within your range.
Hope this helps you with your expectations!
UPDATE
To insert data into the database you could replicate something like the addTransaction () function in the admin/model/sale/customer.php
public function addTransaction($customer_id, $description = '', $amount = '', $order_id = 0) {
$customer_info = $this->getCustomer($customer_id);
if ($customer_info) {
$this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction
SET customer_id = '" . (int)$customer_id . "',
order_id = '" . (int)$order_id . "',
description = '" . $this->db->escape($description) . "',
amount = '" . (float)$amount . "',
date_added = NOW()");
}
And this in admin/controller/sale/customer.php
$this->load->model('sale/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
$this->model_sale_customer->addTransaction($this->request->get['customer_id'],
$this->request->post['description'], $this->request->post['amount']);
$this->data['success'] = $this->language->get('text_success');
} else {
$this->data['success'] = '';
}