populate variants in product object

  • Posts: 12
  • Thank you received: 0
11 years 7 months ago #133275

code taken from your "dev" section:

$prodClass = hikashop_get('class.product');
$prod=$prodClass->get($id);

the resulting object doesn't contain any information about product variants, like it should, according to object reference provided on your website, the class methods are too abstract and there is no method suitable for extracting this data (at least i failed to found one). how can i get product variants (in the way they are displayed on your product object reference page) by product id?

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

  • Posts: 12953
  • Thank you received: 1778
11 years 7 months ago #133290

Hi,
Note that you'll also be able to do it like this :

$this->database = JFactory::getDBO();
$query='SELECT * FROM '.hikashop_table('product').' WHERE product_parent_id ='.$YOURPRODUCTID;
$this->database->setQuery($query);
$variants = $this->database->loadObjectList();

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

  • Posts: 12
  • Thank you received: 0
11 years 6 months ago #135708

Hi,

thanks, however the product doesn't have prices and taxes arrays included, so it returns incorrect prices, is there a way to do it by using hikashop framework?

Link - parduotuve.joomlatvs.lt/joomla/

Regards,
Arminas

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

  • Posts: 12953
  • Thank you received: 1778
11 years 6 months ago #135719

Hi,
the problem is coming from the fact that the price is in the "hikashop_price" table, this kind of code will probably do the job :

$this->database = JFactory::getDBO();
$query='SELECT * FROM '.hikashop_table('product').' AS product LEFT JOIN  '.hikashop_table('price').' AS price ON product.product_id=price.price_product_id WHERE product.product_id = '. $this->element->product_id .' GROUP BY product.product_id ORDER BY price.price_min_quantity ASC';
$this->database->setQuery($query);
$product = $this->database->loadObjectList();

Last edit: 11 years 6 months ago by Mohamed Thelji.

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

  • Posts: 12
  • Thank you received: 0
11 years 6 months ago #135728

ok, better, now i just need the taxes and the price_with_tax in this object, how do i do that?

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

  • Posts: 83995
  • Thank you received: 13605
  • MODERATOR
11 years 6 months ago #135776

You need to do something like that:

$currencyClass = hikashop_get('class.currency');
foreach($product as $k => $v){
 $product[$k]->price_with_tax = $currencyClass->getTaxedPrice($v,hikashop_getZone(),$v->product_tax_id);
 $product[$k]->taxes = $currencyClass->taxRates;
}

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

Time to create page: 0.064 seconds
Powered by Kunena Forum