Customizable way to show products

  • Posts: 95
  • Thank you received: 1
  • Hikashop Business
9 years 8 months ago #216629

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.4
-- PHP version -- : 5.5.12

hi,
i am interested in a customized way of selecting products and proceeding to checkout.
I will have a group of products tagged "1st week".Another group with tag "2nd week" and another with tag "1st and 2nd week"
When a user select a product from "1st week" he must not be able to select a product from the group "1st and 2nd week". Similarly when he selects a product from "1st and 2nd week" he must not be able to select a product from any other group. So i want to "enable" conditional product selection. When a user chooses "this" product then he cannot choose "that" product. Is it possible to do sth like that even with a completely "reworked" view.
And lastly i want whatever product or how many products he selects the order total to be a fixed number.
1 product -> 10$
2products ->10$
..... ->10$

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

  • Posts: 83937
  • Thank you received: 13598
  • MODERATOR
9 years 8 months ago #216690

Hi,

1. I don't see a way to do that with the options available by default in HikaShop. So it will require customizing the "quantity" file of the view "product" via the menu Display>Views to add custom code in order to do that. you'll want to load the products from the current cart, and if there are products in cart preventing you from adding the current product displayed to the cart, remove the display of the add to cart button.

2. In that case, you can set the price of all the products to 0, change the "free" text to something else in order to suits your needs with a translation override:
hikashop.com/download/languages.html#modify
And then, you can use that plugin www.hikashop.com/forum/taxes/873285-fix-tax-import.html#190511 in order to define that $10 amount.

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

  • Posts: 95
  • Thank you received: 1
  • Hikashop Business
9 years 8 months ago #216747

Thank you for your reply Nicolas,
I have managed to write some code that gives the functionality that i want and added the code to quantity.php as you instructed.

global $Itemid;
$database = JFactory::getDBO();
$url_itemid = '';
$app = JFactory::getApplication();
$class = hikashop_get('class.cart');
$cart_type = 'cart';
$cart_id =$app->getUserState( HIKASHOP_COMPONENT.'.'.$cart_type.'_id', 0, 'int' );
$class->get($cart_id,true,$cart_type);
		$full = $class->loadFullCart(true,true,true);
		$rows = $full->products;


$cat= array();
$cart_cat = array();
$found=false;
foreach ($this->categories as $category){  
 array_push($cat, $category->category_id); //categories of the current product
}

var_dump($this->categories);
foreach($rows as $row){
    $query = 'SELECT b.category_id FROM '.hikashop_table('product_category').' AS a LEFT JOIN '.hikashop_table('category').' AS b ON a.category_id = b.category_id WHERE a.product_id = '.(int)$row->product_id.' ORDER BY a.product_category_id ASC';
	$database->setQuery($query);
	$categories = $database->loadObjectList();
	$this->assignRef('categories',$categories);//categories of the products that are already in cart
    foreach ($categories as $category){
        if (in_array($category->category_id, $cat)){  //if there is a product in the cart with same category as the current product 
            $found=true;
            break;
        }
    }
    if ($found){
     break;   
    }
}


if ($found){
 echo 'hide add to cart';
    
}
else{
 echo ' show add to cart';   
}


I have created categories for my products and at version 1 of the code i check the categories of the products at the cart and if the current product has the same category i hide the add to cart button.

I have 2 problems.
First one is that when i add a product to the cart from a product listing and then i press continue shopping(thats what i want the user to able to do) the page does not refresh so my code is not run.

Secondly the var_dump($this->categories); always return null for the first product in product listing but if i enter the product view of the said product it displays my array correctly. It is always null for the first product in product listing. Where is the error in my logic?

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

  • Posts: 83937
  • Thank you received: 13598
  • MODERATOR
9 years 8 months ago #216845

Hi,

1. It probably means that you have the "Use AJAX when possible for add to cart buttons" setting of the HikaShop configuration activated. Turn it off and the page will refresh.

2. $this->categories is not defined on listings. It's only defined on the product page.
For the category of the current listing, its data is available in $this->element

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

Time to create page: 0.059 seconds
Powered by Kunena Forum