Hello!!
Which will be the correct way, in the cs-car framework, of displaying a few product variables, let’s say for example product Name, Description and image to be called from an external page, this without showing no columns or top or bottom divs, for example, I would like to create a modal popup that calls that info only, not the entire product page.
Any ideas
Create a controller called my_changes.product_popup.
You would make your ajax request like:
http://your_domain.com?dispatch=my_changes.product_popup.1234
In this file you would check that the $mode == ‘product_popup’ and that $action is not empty.
Then you would look up the $action (product_code) to get the product ID. Then do a $product_data = fn_get_product_data($product_id, empty($_SESSION[‘auth’]) ? array() : $_SESSION[‘auth’]);
Now you have the product data and let’s say you want to display the product_code, quantity on hand and product name in a simple table.
You’d then do something like:
```php
if( $product_data) {
echo '
Product Code | Quantity On-hand | Product Name |
---|---|---|
'.$product_data['product_code'].' | '.$product_data['amount'].' | '$product_data['product']'. |
} else {
echo "
}
exit;
```
Hey thanks!!!
dos the table must be outputed throught a tpl file in views or it doesn’t. I am just getting error page not found at:
[url]http://www.mydomain.com/index.php?dispatch=my_changes.product_popup&product_id=30294[/url]
after i followed some of your posting i found this:
[QUOTE]As distributed, cs-cart provides an empty addon called my_changes. It is located in the addons/my_changes directory. If you tried to do anything with it as a controller it will fail because there are no modes associated with it.[/QUOTE]
this goes against what you indicated prior… please can you clarify this for me?
You need to create the addons/my_changes/controllers/customer/my_changes.php file and handle the $mode within it.
Also, for portability reasons I wouldn’t use a product_id as the argument, I’d use a product_code and then lookup the product_id. The product_id is DB dependent and if you ever clear your products on an import, that product_id will no longer be valid.
Thanks again… I am now successfully collecting the data only that bellow the data i get error 404 page not found… see the code i am using in my_changes.php bellow:
```php
if ( !defined(‘AREA’) ) { die(‘Access denied’); }
$_REQUEST[‘product_id’] = empty($_REQUEST[‘product_id’]) ? 0 : $_REQUEST[‘product_id’];
$product_code = ($auth[‘area’] == ‘A’ && !empty($_REQUEST[‘action’]) && $_REQUEST[‘action’] == ‘product_code’) ? true : false;
if ($mode == ‘product_popup’) {
$_REQUEST[‘product_id’] = empty($_REQUEST[‘product_id’]) ? 0 : $_REQUEST[‘product_id’];
$product_data = fn_get_product_data($_REQUEST[‘product_id’], $auth, CART_LANGUAGE, ‘’, true, true, true, true, ($auth[‘area’] == ‘A’ && !empty($_REQUEST[‘action’]) && $_REQUEST[‘action’] == ‘preview’));
if($product_data) {
echo '
Product Code | Quantity On-hand | Product Name |
---|---|---|
'.$product_data['product_code'].' | '.$product_data['amount'].' | '.$product_data['product'].'. |
} else {
echo "
}
}
return CONTROLLER_STATUS_OK;
exit;
?> ```
thanks for your help…
It’s working just fine. Question, what if i want to output the info through a tpl file, where should i put this one for the my_changes folder???
skns/
You will need to do a
Registry::get(‘view’)->assign(‘product_data’, $product_data);
in the controller to get the variable available to the template.
THANKS MAN… Thanks millions
hi…
I have been trying passing the information and showing the info in a product_popup.tpl template in the path you specified. It’s not working i get a blank page. Would i need to define the path or CS-Carts get it by default. this is the controller php:
```php
if ( !defined('AREA') ) { die('Access denied'); }
if ($mode == 'product_popup') {
$_REQUEST['product_id'] = empty($_REQUEST['product_id']) ? 0 : $_REQUEST['product_id'];
$product_data = fn_get_product_data($_REQUEST['product_id'], $auth, CART_LANGUAGE, '', true, true, true, true, ($auth['area'] == 'C' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'product_popup'));
if($product_data) {
Registry::get('view')->assign('product_data', $product_data);
} else {
echo "
}
}
exit;
return CONTROLLER_STATUS_OK;
?> ```
You have an exit in your code. The return should also be of type array(). I.e…
return array(CONTROLLER_STATUS_OK)l
this is fine, now, it is displaying all parts of the template, Top, left, central,right and bottom content, i would like to make it display only the content in the [product_popup.tpl] template
Then suggest you not do it as a template and do it as an ajax type request as was first provided.
I have another inconvenient…
i am displaying the image of the product in the ajax request. Now, for those products that have options with different SKU’s the image path is not a variable…
I am having troubles location this variable… i’ll appreciate your advice…
Not sure how images are related to option combinations…
Main Product image was not uploaded… I uploaded and it is fine now… Thanks again