Product Variants aren't assigned a Category

  • Posts: 76
  • Thank you received: 2
9 years 7 months ago #196064

-- url of the page with the problem -- : www.claycellar.co.uk
-- HikaShop version -- : 2.3.0
-- Joomla version -- : 2.5.14

Hi there,

My client wants to apply a mass action to update the price of all the products in a given category.

To do this we add a filter by category column and an "update the values" action using "operation" to increase the price by 10%. A screen shot of this is attached.

We then discover that this doesn't update the price of the variants, because the variants haven't been assigned a category. Indeed there appears to be no place to assign a category to a variant. Presumably variants are assigned to a product which is in turn assigned to a category. But this makes filtering all products and variant under a single category hard right?

Though you can do it in the back end table of products, so presumably it's possible? Can you explain how?

Best wishes,

Jonathan

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
9 years 7 months ago #196134

Hi,

Thanks for the report, to handle the variants when filtering on categories in the mass actions please edit the file "plugins/hikashop/massaction_product/massaction_product.php" and replace the function:

onProcessProductMassFiltercategoryColumn()

By:
	function onProcessProductMassFiltercategoryColumn(&$elements,&$query,$filter,$num){
		if(empty($filter['type']) || $filter['type']=='all') return;
		if(!isset($this->massaction))$this->massaction = hikashop_get('class.massaction');
		$db = JFactory::getDBO();
		if(count($elements)){
			foreach($elements as $k => $element){
				if(!empty($element->categories)){
					if(!is_array($element->categories)) $element->categories = array($element->categories);
					JArrayHelper::toInteger($element->categories);
					$db->setQuery('SELECT * FROM '.hikashop_table('category').' WHERE category_id IN('.implode(',',$element->categories).')');
					$categories = $db->loadObjectList();
					$del = true;
					foreach($categories as $category){
						$in = $this->massaction->checkInElement($category, $filter);
						if($in) $del = false;
					}
					if($del) unset($elements[$k]);
				}
			}
		}else{
			if(!empty($filter['value']) || (empty($filter['value']) && in_array($filter['operator'],array('IS NULL','IS NOT NULL')))){
				$query->leftjoin['product_category'] = hikashop_table('product_category').' AS hk_product_category ON hk_product_category.product_id = hk_product.product_id';
				$query->leftjoin['category'] = hikashop_table('category').' AS hk_category ON hk_category.category_id = hk_product_category.category_id';
				$query->where[] = $this->massaction->getRequest($filter,'hk_category');

				$tQuery = '';
				if(!empty($query->select)) $tQuery .= ' SELECT '.$query->select;
				if(!empty($query->from)) $tQuery .= ' FROM '.$query->from;
				if(!empty($query->join)) $tQuery .= ' JOIN '.implode(' JOIN ',$query->join);
				if(!empty($query->leftjoin)) $tQuery .= ' LEFT JOIN '.implode(' LEFT JOIN ',$query->leftjoin);
				if(!empty($query->where)) $tQuery .= ' WHERE ('.implode(') AND (',$query->where).')';
				if(!empty($query->ordering)) $tQuery .= ' ORDER BY '.implode(',',$query->ordering);
				if(!empty($query->direction) && is_string($query->direction)) $tQuery .= ' '.$query->direction;
				if(!empty($query->group) && is_string($query->group)) $tQuery .= ' GROUP BY '.$query->group;

				$db->setQuery($tQuery);
				$mainProducts = $db->loadObjectList();
				$ids = array();
				foreach($mainProducts as $mainProduct){
					$ids[] = $mainProduct->product_id;
				}

				$query->join = array();
				$query->leftjoin = array();
				$query->where = array('product_id IN ('.implode(',',$ids).') OR product_parent_id IN ('.implode(',',$ids).')');
			}
		 }
	}

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

  • Posts: 7
  • Thank you received: 0
9 years 5 months ago #203958

Hello
I make the change but the order is not correct

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

  • Posts: 13201
  • Thank you received: 2322
9 years 5 months ago #204069

Hi,

This feature has been integrated in HikaShop, and will be available in the next release.
So you will be able to add ordering in the settings of your mass action directly.

If it is currently not working as expected, that's potentially because you don't selected a correct value as ordering field.

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

  • Posts: 7
  • Thank you received: 0
8 years 10 months ago #225237

I install last version

The order is correct but i display also the variant of the product no actif

Are there a possibility to filter to no display this variant without modify the variant product (no actif)

Thank

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

  • Posts: 7
  • Thank you received: 0
8 years 10 months ago #225260

Sorry,

change the massaction, put test on product_published first and it works correctly

I see that a problem with price with taxe

For the variant the price_value_with_taxe is the same like price_value see attach

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
8 years 10 months ago #225283

Hi,

Sorry but with the given csv file I can't really see the difference of the prices.
In the product edition page, under the variant tabs, are the prices correct ? Is that error only related on the exported csv file from the mass actions ?

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

  • Posts: 7
  • Thank you received: 0
8 years 10 months ago #225299

The price is correct in the variant product tab
Michel

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

  • Posts: 13201
  • Thank you received: 2322
8 years 10 months ago #225302

Hi,

There is indeed an issue, we just corrected it on our end and the fix will be in the next release.
For now you can edit the file "administrator/components/com_hikashop/classes/massaction.php" and in the function "_displayResults()" replace the code:

								if(!isset($productClass->products[$row->price_product_id]))
									$rows[$k]->price_value_with_tax = $rows[$k]->price_value;
								else
									$rows[$k]->price_value_with_tax = $currencyHelper->getTaxedPrice($row->price_value,$zone_id,$productClass->products[$row->price_product_id]->product_tax_id);
By:
								if(isset($productClass->all_products[$row->price_product_id]) && $productClass->all_products[$row->price_product_id]->product_type == 'main')
									$rows[$k]->price_value_with_tax = $currencyHelper->getTaxedPrice($row->price_value,$zone_id,$productClass->all_products[$row->price_product_id]->product_tax_id);
								elseif(isset($productClass->all_products[$productClass->all_products[$row->price_product_id]->product_parent_id]->product_tax_id))
									$rows[$k]->price_value_with_tax = $currencyHelper->getTaxedPrice($row->price_value,$zone_id,$productClass->all_products[$productClass->all_products[$row->price_product_id]->product_parent_id]->product_tax_id);
								else
									$rows[$k]->price_value_with_tax = $rows[$k]->price_value;

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

Time to create page: 0.088 seconds
Powered by Kunena Forum