Welcome, Guest
Username: Password: Remember me
Use this Category for your support questions about Virtuemart Template - FashionMart (SKU# FLEX-00008)

TOPIC: [SOLVED] How to Add To Cart From Category View?

[SOLVED] How to Add To Cart From Category View? 11 years 8 months ago #65

Hi!
I need to get 'Add To Cart From Category View' working for a client on FashionMart Vm2 theme. Same way we have in some Vm2 modules.
Would you please release instructions on how to make this works straight, including future updates? (yeap, as I've bought the 1 year update and support ;)
Here's the topic on VirtueMart forum, with default.php and addToCartCategory.php : forum.virtuemart.net/index.php?topic=90961.90
Last Edit: 11 years 6 months ago by Support.
The topic has been locked.

How to Add To Cart From Category View? 11 years 8 months ago #91

The PHP file you need to make edits is this:

yourdomain.com/templates/<yourjoomlatemplate>/html/com_virtuemart/category/default.php

Where ever you want to add "add to cart" button, The PHP lines you need to enter are these:
<?php // Add To Cart Button
				if (!VmConfig::get('use_as_catalog', 0) and !empty($product->prices)) {?>
				<div class="FlexibleWebaddtocart-area">
 
					<form method="post" class="product js-recalculate" action="index.php" >
					<?php // Product custom_fields
					if (!empty($product->customfieldsCart)) {  ?>
					<div class="FlexibleWeb-product-fields">
						<?php foreach ($product->customfieldsCart as $field)
						{ ?>
 
                        	<div style="text-align:left;" class="product-field product-field-type-<?php echo $field->field_type ?>">
							<span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title) ?></b></span>
								<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
 
                            <span class="product-field-display"><?php echo $field->display ?></span>
 
							<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
							</div> 
							<?php
						}
						?>
					</div>
					<?php }
					 /* Product custom Childs
					  * to display a simple link use $field->virtuemart_product_id as link to child product_id
					  * custom_value is relation value to child
					  */
 
					if (!empty($product->customsChilds)) {  ?>
						<div class="product-fields">
							<?php foreach ($product->customsChilds as $field) {  ?>
								<div style="display:inline-block;float:right; padding:3px;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
								<span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title) ?></b></span>
								<span class="product-field-desc"><?php echo JText::_($field->field->custom_value) ?></span>
								<span class="product-field-display"><?php echo $field->display ?></span>
 
								</div> 
								<?php
							} ?>
						</div>
					<?php } ?>
 
				<div class="Flexibleaddtocart-bar">
 
						<?php // Display the quantity box ?>
						<!-- <label for="quantity<?php echo $product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
 
						<input type="hidden" class="quantity-input" name="quantity[]" value="1" />
 
 
						<?php // Display the quantity box END ?>
 
						<?php // Add the button
						$button_lbl = JText::_('COM_VIRTUEMART_CART_ADD_TO');
						$button_cls = 'addtocart-button'; //$button_cls = 'addtocart_button';
						$button_name = 'addtocart'; //$button_cls = 'addtocart_button';
 
 
						// Display the add to cart button
						$stockhandle = VmConfig::get('stockhandle','none');
						if(($stockhandle=='disableit' or $stockhandle=='disableadd') and ($product->product_in_stock - $product->product_ordered)<1){
							$button_lbl = JText::_('COM_VIRTUEMART_CART_NOTIFY');
							$button_cls = 'notify-button';
							$button_name = 'notifycustomer';
						}
						vmdebug('$stockhandle '.$stockhandle.' and stock '.$product->product_in_stock.' ordered '.$product->product_ordered);
						?>
						<span class="addtocart-button">
							<?php if ($button_cls == "notify-button") { ?>
                            <span class="outofstock"><?php echo JText::_('COM_VIRTUEMART_CART_PRODUCT_OUT_OF_STOCK'); ?></span>
 
                            <?php } else {?>
                            <input type="submit" name="<?php echo $button_name ?>"  class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
 
 
 
 
                            <?php } ?>
						</span>
 
					<div class="clear"></div>
				</div>
 
					<?php // Display the add to cart button END ?>
					<input type="hidden" class="pname" value="<?php echo $product->product_name ?>" />
					<input type="hidden" name="option" value="com_virtuemart" />
					<input type="hidden" name="view" value="cart" />
 
					<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
					<?php /** @todo Handle the manufacturer view */ ?>
					<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
					<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
					</form>
 
 
			</div>
				<?php }  // Add To Cart Button END ?>
The topic has been locked.

How to Add To Cart From Category View? 11 years 8 months ago #143

Thank you for answering.
Excuse my ignorance, but isn't the above code allready present in Fashionmart theme's original category/default.php file, from lines 363 to 459?
If so how to enable the addtocard button please?
The topic has been locked.

How to Add To Cart From Category View? 11 years 8 months ago #144

In FashionMart, there are 2 different layouts in Category Browse page.
1- GRID Layout (THUMB layout)
2- LIST layout.

In the list layout, there is already "add to cart" button (this is why you are seeing same exact codes in 363-459th line), but since you have asked, i though you want to add it to GRID layout as well. The PHP codes above should be copy/pasted in
templates/<yourjoomlatemplate>/html/com_virtuemart/category/default.php
to 623th line. Right after these lines:
<div class="FlexibleThumbBrowseV1ProductDetailsButton">
	<?php // Product Details Button
		echo JHTML::link($product->link, JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'product-details'));
	?>
</div>

Flexible Support Team
Last Edit: 11 years 8 months ago by Support.
The topic has been locked.

How to Add To Cart From Category View? 11 years 8 months ago #153

Got it, and it works well.
Thank you

note: will be usefull for the pages with many accessories , so that clients may add a bunch of them in a row.
Hopefuly, will use a category display (aka Default) for those product accessories pages, and another (aka Flexv2) for main products. The later without 'AddToCart' button.
The topic has been locked.
Time to create page: 0.132 seconds

MaterialMart

for Virtuemart 3

Google's Material Design has finally arrived to Virtuemart

Virtumart Template - MaterialMart Virtumart Template - CleanMart Virtumart Template - CleanMart Virtumart Template - CleanMart

Fully responsive!

Buy Now   |   Live Demo