Load the Page title in hikashop to a form?

  • Posts: 165
  • Thank you received: 3
11 years 4 months ago #120300

-- url of the page with the problem -- : 67.43.0.200/~adenenc/index.php/mattresse...west-price-guarantee
-- HikaShop version -- : 2.2.0
-- Joomla version -- : 3.1.5
-- PHP version -- : x.x.x

I want to load the $product_name variable into my form on the page as the default value in the "Price Match Item:" I have tried for a few hours and have not seemed to be able to get it to work. Here is what I have tried below with no success how do i get this to work?
I want the product_name variable for each product to load in this field on every page.

thanks,

Josh

<?php
$db = JFactory::getDbo();
$db->setQuery("SELECT `product_name` FROM `#__hikashop_product` WHERE `product_name`='value' LIMIT 1");
return $db->loadResult();
?>

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

  • Posts: 26166
  • Thank you received: 4029
  • MODERATOR
11 years 4 months ago #120355

Hi,

I don't understand your SQL request.
You want to retrieve the product name but I don't understand for which product.

In your request, you made a search for a specific product_name, so you will retrieve the value "value" if you have a product with this name.

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: 165
  • Thank you received: 3
10 years 11 months ago #139733

Hi I am still trying to figure this out. I just put this on hold for a while. Basically what I am trying to do is this:

I want to load the product_name which on this page is "SLEEP-PEDIC - HOTEL FIRM" as the default value for the form field called "price matched item". I attached an image to show you what I am talking about.

I want to do this on all my hikashop product pages. I want the product name to be loaded as the default value in the form for each page. By the way the form field called "price matched item" is a rsformpro field, which is where I want the product name.

I cannot figure out how to do this.

Thanks,

Josh

Attachments:
Last edit: 10 years 11 months ago by jschroeder.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139831

Hi,

You can get the product name with the code below on that page:
<?php echo $this->element->product_name; ?>

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139833

Hi, Unfortunately that will not work because rsform will not get that information off the page but just inserting that into the default value for the field you have to actually load the information from the database first into rsform in order for it to work. If you use the below code as the default value in the form it gives you a syntax error for using $this on a page.


Previously when i had a virtuemart I a code similar to this. I tried modifying it for hikashop but it does not work. I do not fully understand how to do it..
<?php function hikashop_getCID('product_id') {
$id = $_GET["product_id"];
$db = & JFactory::getDBO();
$query = 'SELECT product_name FROM #__hikashop_product ' . ' WHERE product_id = ' . (int) $id;
$db->setQuery($query);
$product_name = $db->loadResult();
echo $product_name;
}
?>

Last edit: 10 years 11 months ago by jschroeder.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139838

That's why jerome was asking for more information. Without knowing that you want that info in rsform, we can't give a correct answer.
Try like that:
$id =hikashop_getCID('product_id');
$db = & JFactory::getDBO();
$query = 'SELECT product_name FROM #__hikashop_product WHERE product_id = ' . (int) $id;
$db->setQuery($query);
$product_name = $db->loadResult();
echo $product_name;

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139844

HI i tried this as the code in the default value and i get the following error
Fatal error: Call to undefined function hikashop_getCID() in administrator/components/com_rsform/helpers/rsform.php(568) : eval()'d code on line 2

Last edit: 10 years 11 months ago by jschroeder.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139849

Yes, you need to load the hikashop library before with that code:

if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139856

Thanks for the quick answer I attached a picture for you. It is still not working. Now it is doing something really weird. It is loading the variable into the page but not in the default form field. Even though I have this code in the form in the default value field it is throwing the product name at the top of my page above the header.

I inserted the code like this in the default field.
<?php
if(!defined('DS'))
define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
$id =hikashop_getCID('product_id');
$db = & JFactory::getDBO();
$query = 'SELECT product_name FROM #__hikashop_product WHERE product_id = ' . (int) $id;
$db->setQuery($query);
$product_name = $db->loadResult();
echo $product_name;
?>
Also, I have my web developer toolkit and it is throwing the browser into quirks mode.

Josh

Attachments:
Last edit: 10 years 11 months ago by jschroeder.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139863

I would recommend you to contact rsform because I don't know how it works for custom code. If you show them the code I gave, they should be able to tell you where to add it and if it needs a modification to display at the correct place in your rsform.

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139975

Hi Nicolas I talked to the developer over at rsform and he said to try this below. I tried it but it does not work. Although I am not exactly sure what he means by "the_name_of_the_id_parameter_from_the_URL". I do not have any parameters. I turned off sef so i could see the actual url and tired every parameter I can think of and it does not work any ideas?


The script should be similar to :

//<code>
$productId = JRequest::getVar('the_name_of_the_id_parameter_from_the_URL');
$db = JFactory::getDbo();

if ($productId) {
// Grab the value from the database.
$db->setQuery("SELECT `product_name` FROM `#__hikashop_products` WHERE `product_id`='".$productId."'");
return $db->loadResult();
}
//</code>

You will only need to replace 'the_name_of_the_id_parameter_from_the_URL' with the actual parameter from the URL that holds the hikashop product id.

Last edit: 10 years 11 months ago by jschroeder.

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139977

Hi, I take it back it does work he had "hikashop_products" instead of 'hikashop_product'. i changed "the_name_of_the_id_parameter_from_the_URL" to "cid" and the same problem i had before Is occuring it is loading the variable at the top of the page instead of in the actual form field.


//<code>
$productId = JRequest::getVar('cid');
$db = JFactory::getDbo();

if ($productId) {
// Grab the value from the database.
$db->setQuery("SELECT `product_name` FROM `#__hikashop_product` WHERE `product_id`='".$productId."'");
$product_name = $db->loadResult();
echo $product_name;
}
//</code>

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

  • Posts: 165
  • Thank you received: 3
10 years 11 months ago #139979

Nicolas it finally works here is the code below I just had a syntax error before:

Here is the code i used
//<code>
$productId = JRequest::getVar('cid');
$db = JFactory::getDbo();

if ($productId) {
// Grab the value from the database.
$db->setQuery("SELECT `product_name` FROM `#__hikashop_product` WHERE `product_id`='".$productId."'");
return $db->loadResult();
}
//</code>

The following user(s) said Thank You: nicolas

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

Time to create page: 0.078 seconds
Powered by Kunena Forum