how do I call my addon script?

I tried to call my addon by using [url]http://mycscarthost/index.php?dispatch=integration.getallproducts[/url], but I get a 404 page not found. Might it be because it cannot find my addon page, or because I don’t have a template file? How do I achieve what I want? I really don’t want a template file, I just want to return a list of product_code & md5 hash of the concatenated product fields. This allows a remote host to simply get a list of product code and md5’s to compare against for product updates. So all I need returned from this page is an array object.



I’ve created the following directory & files



cscart

—addons

------integration

------addon.xml

------func.php

------init.php



inside the func.php I have the following:



if ( !defined('AREA') ) { die('Access denied'); }

if ($mode == 'getallproducts') {
fn_get_all_products();
}

function fn_get_all_products() {
$product_ids = db_get_fields("SELECT product_id FROM ?:products");
foreach ($product_ids as $product_id) {
$product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', true, true, true, true);
$product_code=$product['product_code'];
$product_list[] = array('product_code' => $product_code, 'product_md5' => fn_get_product_md5($product));
return $product_list;
}
}
function fn_get_product_md5($product) {
//this function will concatenate product data and generate an md5
//for now we will just return a number for testing
return 1;
}

?>

Hi Scott, there’s still alot missing, you need to assign the variable to a template using something like:



$view->assign(‘integration’, $integration);



Then the view assign needs to be placed before the last closing brace of the function as shown below:



```php


if ( !defined('AREA') ) { die('Access denied'); }

if ($mode == 'getallproducts') {
fn_get_all_products();
}

function fn_get_all_products() {
$product_ids = db_get_fields("SELECT product_id FROM ?:products");
foreach ($product_ids as $product_id) {
$product = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', true, true, true, true);
$product_code=$product['product_code'];
$product_list[] = array('product_code' => $product_code, 'product_md5' => fn_get_product_md5($product));
return $product_list;

$view->assign('integration', $integration);

}

}

function fn_get_product_md5($product) {
//this function will concatenate product data and generate an md5
//for now we will just return a number for testing
return 1;
}

?>

```



You still need templates to the assign the variable(s) to which is exactly why you are getting a 404, because no template exists. See example highlighted in red below:



index.php?dispatch=[color=red]integration[/color].view is looking for the integration addon which should be located at

[ROOT]/addons/integration/



index.php?dispatch=integration.[color=red]view[/color] is looking for the template which would be located at …/skins/[SKIN_NAME]/addons/integration/controllers/customer/view.tpl



The references above are off the top of my head and most likely need adjustments to work correctly and there is still more that needs to be done but this should get you more on track, if you need help let me know, Thanks - Sno

Sno,



Thanks for the information, I suspected there was a template involved. So in order to return a simple list of product id’s and MD5’s I would need to have an entire template to do that. What would be the simplest template to use to return a simple list like that?



I’m starting to think I may create triggers in the ERP system (Dynamics GP 10) to push out products via the vb.net hub to be received by the php web service one-by-one, which will call the products.php controller (which I have working). I think it would be more efficient to push out product changes as they happen vs. comparing checksums or modified dates.

[quote name=‘scottemick’]Sno,



Thanks for the information, I suspected there was a template involved. So in order to return a simple list of product id’s and MD5’s I would need to have an entire template to do that. What would be the simplest template to use to return a simple list like that?[/QUOTE]



Their may be another way but I don’t know it, the best thing to do is pay for 1 month support period from cs-cart and start pegging them with questions, they are very good and will be able to help you out with more in depth knowledge of what needs to be done.


[quote name=‘scottemick’]

I’m starting to think I may create triggers in the ERP system (Dynamics GP 10) to push out products via the vb.net hub to be received by the php web service one-by-one, which will call the products.php controller (which I have working). I think it would be more efficient to push out product changes as they happen vs. comparing checksums or modified dates.[/QUOTE]



I don’t know the proper code off the top of my head but in the view.tpl you would be something similar to:



{foreach from=$itegration item="itegrate" key="key"}

{$itegrate.product_id}


{/foreach}



  • Sno

Thanks…I’ll probably get that support too…



Scott

Use a controller… I.e.

addons//controllers/admin/.php



Invoke it by dispatch=.get



Have code similar to:


if( $mode == 'get' )
echo get_my_results();
exit;




Your “receiver” can simply read the response as the output from curl. You can encapsulate it in some type of protocol format if you want. One of the cleanest is to simply use the php function serialize() and then use unserialize() on the receiving end.

I have a page in



/cscart/addons/web_service_integration/controllers/admin/web_service_integration.php



but the link admin.php?dispatch=web_service_integration.add&product_ID=333 just gives me a 404 error.



I can do admin.php?dispatch=product.add or product.delete etc with no problems.

My add in is installed through admin, and it is catching the hooks it is registered for.



my addon controller page web_service_integration.php has the following code on it


if ( !defined('AREA') ) { die('Access denied'); }

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($mode == 'add') {
echo $_REQUEST['product_id']."\n";
}
}


?>
Scott




[quote name=‘tbirnseth’]Use a controller… I.e.

addons//controllers/admin/.php



Invoke it by dispatch=.get



Have code similar to:


if( $mode == 'get' )
echo get_my_results();
exit;
Your “receiver” can simply read the response as the output from curl. You can encapsulate it in some type of protocol format if you want. One of the cleanest is to simply use the php function serialize() and then use unserialize() on the receiving end.[/quote]

If you are using your own controller (as above) then you need to redirect() when you’re done (or exit). You can’t just fall out with no indication of the ‘mode’ being caught (or ignored).