Developing a plugin

  • Posts: 4
  • Thank you received: 0
10 years 7 months ago #149917

Hi I am using Akeeba Subscriptions in conjunction with Hikashop to track how many free purchases (they will be downloads) a user can have per their subscription.
I want to write a plugin which:
-When installed adds a field to the hikashop user table named 'download_count' or something along those lines. Default value is 0.
-When a user has purchased a subscription through Akeeba subs (I believe there is even a way to make this purchase through hikashop, which may make it easier?) add a value to the new field which allows them to have x amount of free downloads.
-When a user uses a free purchase (which will be a downloadable audio file) I want to decrement the number in my custom field. Once it reaches 0 the user cannot make any more free purchases until their new subscription.

Is this a feasible idea? I have done some practice plugin development from a book but this is my first real undertaking in developing an actual plugin, and I know there are probably some standards I need to follow within Hikashop.

I was reading the API and was going to call the function onBeforeDownloadFile(&$filename,&$do,&$file) when a user goes to download a file and say decrement by 1.
From my knowledge, to download a file from Hikashop an email gets sent to a user with a link to download a file, so will this function get called when they click that link?

NOTE: The reason I am using Hikashop for this is because the website will also have pages which are 'Subscriber Only' pages and I couldn't think of a better way to integrate that + allowing users to have x amount of free downloads. I can think of ways to do it separately but the only way I could think of joining them together was the creation of a plugin.

Any help would be appreciated as I want to be armed with as much knowledge before I undertake this, as I know it's going to be a tricky task. If anyone has a better idea also I'd love to hear it!

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 7 months ago #149957

Hi,

Everything is possible, it require just more or less development ;)

It seems to be a feasible idea, the trigger is called even if the customer click on the email link.
To buy a subscription, you can use the Akeebasub plugin in order to buy through HikaShop and add the subscription in Akeeba subscription component.
www.hikashop.com/support/support/documen...a-subscriptions.html

In the plugin add a onAfterOrderConfrim() function to check if the subscription has been paid and is valid, if yes, add "credit" to the customer in the download_count column via a MySQL request.

Then in the function onBeforeDownloadFile() get the user id, and decrement in the table via a MySQL request too.

Regarding the 'Subscriber Only' pages you can set a user group after purchase in the subscription product edition page.
By this way the customer will be moved to another Joomla Group and will be able to see the content of the restricted area.
You will have to add another functionality in the plugin to remove the group when the subscription is not more valid.

Hope this will help you.

The following user(s) said Thank You: alex01

Please Log in or Create an account to join the conversation.

  • Posts: 4
  • Thank you received: 0
10 years 7 months ago #150051

Thank you so much for your explanation and assistance Xavier. I will be working on that today and try to get it working!

Please Log in or Create an account to join the conversation.

  • Posts: 4
  • Thank you received: 0
10 years 7 months ago #150057

I've been having a look around and would I have to use the onAfterOrderUpdate function rather than the onAfterOrderConfirm, as I'd want to make sure a user has paid before giving them any credit.

Also when checking, how would I go about determining whether the order purchased has the Akeeba Subscription in it? I'm trying to figure out how to say
- if the order has been paid for AND there is an Akeeba Subscription within the order, add credits to the database.

Last edit: 10 years 7 months ago by alex01. Reason: Ased another question

Please Log in or Create an account to join the conversation.

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
10 years 7 months ago #150113

You'll have to load the products data from the order with a SQL query and check whether the products have a product_subscription_id set in them or not.

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum