Author Topic: Working on custom extension  (Read 5869 times)

Offline vitalmyth

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Working on custom extension
« on: September 11, 2013, 08:42:07 PM »
First, thank you to the AbanteCart team, because I love this cart and I think it is very well made. I am trying to build a very simple custom extension for my business. I am new to web development, but I have done this same extension project for other, simpler carts, and I am trying to figure out how to do the same thing for AbanteCart.

I have several questions, but I will ask them one at a time. First let me introduce the project.

The idea is very simple:
- When customer confirms an order, extension will send order data to a third-party API. Nothing is visible on storefront, but data is sent at checkout/success
- API will return 2 responses. Now I need to store the responses somewhere with order_id, so that I can select them by order_id later. For example, in a new table called "vitalmyth_notes", which has 3 columns: order_id (same as orders table), vitalmyth_response_1, vitalmyth_response_2.
- On admin backend, the page at sales/orders/order #X now shows 2 new things in "Order Summary" section. These new things are vitalmyth_response_1 and vitalmyth_response_2.
- vitalmyth_response_2 will change after first creation. When the order is first confirmed, it will be "Wait," and then after 1-5 days, "Done." So on admin/orders/order #X, I need something like this (very simplified):

$current_response_2 = select vitalmyth_response_2 from table vitalmyth_notes where order_id = id_of_order_X;
if ($current_response_2 == 'Wait') {
$postfields = select * from table_orders where order_id = id_of_order_X;
$response = curl_exec($postfields);
$this->db->execute(update table vitalmyth_notes set vitalmyth_response_2=$response where order_id = id_of_order_X);
echo $vitalmyth_response_2;
} else { echo $vitalmyth_response_2; }

I hope that makes sense although it is not actual code.

My first question is...my extension will be dependent upon ANY credit card gateway, not just 1 in particular. So if ANY credit card gateway is installed, my extension will work, but will not work for other types of orders (cod, bank transfer, etc). Can I set dependencies so that at least 1 credit card gateway is required, but it can be any gateway?

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1782
  • Karma: +247/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Working on custom extension
« Reply #1 on: September 12, 2013, 05:16:08 AM »
Yes. You can set dependencies inside file config.xml of your extension.
for ex:
Code: [Select]
<dependencies>
       <item prior_version="0.9" version="1.0.1">your_payment_gateway_extension_text_id</item>
       <item prior_version="0.9" version="1.0.1" required="true">your_payment_gateway_extension_text_id</item>
</dependencies>
and then go to your's extension edit page in admin and you will see that dependants there.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline vitalmyth

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Working on custom extension
« Reply #2 on: September 12, 2013, 08:31:14 PM »
edit: oops, post made no sense after i changed some things. fixed now.

Thank you. What if I have required="true" for multiple extensions? This means (your_payment_gateway_extension && another_payment_gateway_extension && another2_payment_gateway_extension) ALL are required, right?

what if I need (your_payment_gateway_extension || another_payment_gateway_extension || another2_payment_gateway_extension), ANY required?

maybe I need to check for this in my own code, like:

(sorry, I cannot put in code tags below, getting error "You cannot post external links" when using [ code ] tags)

$vital_myth_compatible_extensions = array('paymentgateway1' => 'authorizeaim', 'paymentgateway2' => 'paypal_pro', 'paymentgateway3' => 'secure_checkout');
$enabled_extensions = array( ...all of the extensions enabled right now... );
foreach ($enabled_extenstions as $extension) {
if (in_array($extension, $vitalmyth_compatible_gateways)) {
$compatible = true; }
} if ($compatible) { ---my code stuff--- } else { error('No credit card payment gateway enabled'); }
« Last Edit: September 12, 2013, 08:33:02 PM by vitalmyth »

Offline vitalmyth

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Working on custom extension
« Reply #3 on: September 13, 2013, 01:27:48 AM »
New question. I am new to hooks so I am not sure how to use them. Assume I make my extension dependent on default_authorizeaim_net. I want to add note "Hello" to admin order page after the default_authorizeaim_net notes. They look like:

Quote
Authorization Code: 000000
AVS Response: P
Transaction ID: 0
Card Code Response: 252C77980EAA158C200EAC622BAF5F10
Cardholder Authentication Verification Response:

So I want to do this:
Quote
Authorization Code: 000000
AVS Response: P
Transaction ID: 0
Card Code Response: 252C77980EAA158C200EAC622BAF5F10
Cardholder Authentication Verification Response:
Hello

Will this work?

Quote
class Vitalmyth extends Extension {
public function afterDefaultAuthorizeNetAimsend() {
$this->model_checkout_order->update($this->session->data['order_id'], 1, 'Hello', FALSE);
}
}

 

Powered by SMFPacks Social Login Mod