News:

Looking for documentation? Take a look on our wiki

Main Menu

Add to Cart in category view

Started by driver_wedge, January 24, 2017, 17:10:54 PM

Previous topic - Next topic

driver_wedge

Hi all..

I want to add a generic 'VIEW PRODUCT'  button to all products in category view instead of the usual ADD TO CART button. The main reason being is that my template does not accommodate child variants very well, so I get 'Choose a variant' displaying when viewing products with variants on the category page. I'm also keen to learn a little more about this stuff in the process....fingers crossed!

Having had a read through various threads, I came to the conclusion that this feature would be controlled by the 'addtocartbar.php' file in the /templates/mytemplate/html/com_virtuemart/sublayouts directory. Hopefully this is correct...and if so, can anyone point me to the relevant areas of code below that will enable me to achieve this? Will I need to also edit other files too?

defined('_JEXEC') or die('Restricted access');
$product = $viewData['product'];

if(isset($viewData['rowHeights'])){
$rowHeights = $viewData['rowHeights'];
} else {
$rowHeights['customfields'] = TRUE;
}

$init = 1;
if(isset($viewData['init'])){
$init = $viewData['init'];
}

if(!empty($product->min_order_level) and $init<$product->min_order_level){
$init = $product->min_order_level;
}

$step=1;
if (!empty($product->step_order_level)){
$step=$product->step_order_level;
if(!empty($init)){
if($init<$step){
$init = $step;
} else {
$init = ceil($init/$step) * $step;

}
}
if(empty($product->min_order_level) and !isset($viewData['init'])){
$init = $step;
}
}

$maxOrder= '';
if (!empty($product->max_order_level)){
$maxOrder = ' max="'.$product->max_order_level.'" ';
}

$addtoCartButton = '';
if(!VmConfig::get('use_as_catalog', 0)){
if(!$product->addToCartButton and $product->addToCartButton!==''){
$addtoCartButton = shopFunctionsF::getAddToCartButton ($product->orderable);
} else {
$addtoCartButton = $product->addToCartButton;
}

}
$position = 'addtocart';
//if (!empty($product->customfieldsSorted[$position]) or !empty($addtoCartButton)) {


if (!VmConfig::get('use_as_catalog', 0)  ) { ?>

<div class="addtocart-bar">
<?php
// Display the quantity box
$stockhandle VmConfig::get ('stockhandle''none');
if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($product->product_in_stock $product->product_ordered) < 1) { ?>

<a href="<?php echo JRoute::('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' $product->virtuemart_product_id); ?>" class="notify"><?php echo vmText::('COM_VIRTUEMART_CART_NOTIFY'?></a><?php
} else {
$tmpPrice = (float) $product->prices['costPrice'];
if (!( VmConfig::get('askprice'true) and empty($tmpPrice) ) ) { ?>

<?php if ($product->orderable) { ?>
<!-- <label for="quantity<?php echo $product->virtuemart_product_id?>" class="quantity_box"><?php echo vmText::('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">

<input type="number" class="quantity-input js-recalculate" name="quantity[]" data-errStr="<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>" value="<?php echo $init?>" min="<?php echo $init?>" step="<?php echo $step?>" <?php echo $maxOrder?> /></span><?php }

if(!empty($addtoCartButton)){
?>
<span class="addtocart-button"><?php echo $addtoCartButton ?></span><?php
?>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>"/>
<noscript><input type="hidden" name="task" value="add"/></noscript> <?php
}
?>

</div><?php
?>



Hope you can help.

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

driver_wedge

Sorry...!  :-[

Joomla version - 3.6.5
VM Version - 3.0.18
PHP Version - 5.6.29
Template - uses VM styling and overrides
Using SEF - No

Basically, I just want to know what string(s) make the add to cart button display on the front end when on a category page. This will give me something to work off.

Thanks!

GJC Web Design

cat pages use the sublayout product.php to display each product block

it uses the add to cart sublayouts to display the add to cart etc

you would normally build your own version of the add to cart sublayout .. call it something else -- and load that one in your product.php
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation