Database Call from custom html module

  • Posts: 35
  • Thank you received: 2
11 years 10 months ago #85169

Long story short, I am severely editing the product display page. I need to call upon the description (or else a custom field that is a replica of the description) in a custom html module on the same page.

These gives me the following error:
<?php echo $this->row->product_centers_description; ?>

or

<?php echo $this->element->product_description)); ?>

ERROR: Fatal error: Using $this when not in object context in....

However, I can call upon it individually as shown below without errors, though that won't work because I can't make a new custom html for every single product page:

<?php $class = hikashop_get('class.product');
$prod = $class->get(2);
echo $prod->product_centers_description; ?>

Please help,
G

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

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 10 months ago #85266

Hi,

I did not understand your message but the PHP code in modules is not the same than in views.
It is not possible to copy/past code in views directly in a module, the context is completely different.
After that, I don't know where you put your code so it is difficult to help you.

A module could be call in the product page but the module should read the product id directly in the url.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 35
  • Thank you received: 2
11 years 10 months ago #85293

Can you show me, using the bottom code as a rough draft, how to call on "product_centers_description" using the ID directly from the URL? I really appreciate how excellent the customer service is around here. Thank you.

Let me simplify:

I need this code...

<?php $class = hikashop_get('class.product');
$prod = $class->get(1);
echo $prod->product_centers_description; ?>

To pull the "get(id)" from the url or some other way than "$this", because $this gives me errors:

retreatwell.com/index.php?option=com_hik...yout=show&Itemid=274

Last edit: 11 years 10 months ago by dynamicvitality.

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

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 10 months ago #85444

Hi,

You can load the product id using this code:

$product_id = (int)hikashop_getCID('product_id');
if(empty($product_id)) {
	$menus	= $app->getMenu();
	$menu	= $menus->getActive();
	if(empty($menu)){
		global $Itemid;
		if(!empty($Itemid)){
			$menus->setActive($Itemid);
			$menu = $menus->getItem($Itemid);
		}
	}
	if (is_object( $menu )) {
		jimport('joomla.html.parameter');
		$category_params = new HikaParameter( $menu->params );
		$product_id = $category_params->get('product_id');
	}
}

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 35
  • Thank you received: 2
11 years 10 months ago #85491

So combing the two would look something like this:

$product_id = (int)hikashop_getCID('product_id');
if(empty($product_id)) {
	$menus	= $app->getMenu();
	$menu	= $menus->getActive();
	if(empty($menu)){
		global $Itemid;
		if(!empty($Itemid)){
			$menus->setActive($Itemid);
			$menu = $menus->getItem($Itemid);
		}
	}
	if (is_object( $menu )) {
		jimport('joomla.html.parameter');
		$category_params = new HikaParameter( $menu->params );
		$product_id = $category_params->get('product_id');
	}
}

$productClass = hikashop_get('class.product');
$prod = $productClass->get($product_id);
echo $prod->product_centers_description;

Last edit: 11 years 10 months ago by Jerome. Reason: Fixing the code

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

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 10 months ago #85498

Hi,

I have fixed your code.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: dynamicvitality

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

  • Posts: 35
  • Thank you received: 2
11 years 10 months ago #85506

Awesome!

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

Time to create page: 0.067 seconds
Powered by Kunena Forum