VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: phil147 on September 25, 2017, 12:24:26 PM

Title: Template over-ride to Disable add to cart for a category
Post by: phil147 on September 25, 2017, 12:24:26 PM
Using VM 3.2.4

I have an over-ride that was put in my product display php file. The over-ride makes add to cart buttton in category view dis-appear and in product detail page it makes add to cart button disabled and grey back-ground. It used for a medicine product category that displays a button to a form thats to be completed first etc...

I have another product category that we're no longer allowed sell online, so I need to remove add to cart option from category view and disable in product detail view and grey the button.

Anyone know how to do this? Have attached product display file (changed to txt format from php)

snippet of code from file below...where it check the category id '218' which is the medicine category

<?php //GJC
   if(in_array('218',$this->product->categories)){
      $product_name = $this->product->product_name;
   ?>
   <script type="text/javascript">

         jQuery(document).ready(function($) {
            $('.addtocart-button').prop('disabled', true);
            $('.addtocart-button').addClass('disabled');
            $('#ff_elem20').val('<?php echo $product_name; ?>');
            $('a.declaration').on('click', function () {
               $('.decform').hide();
               $('.gjc_overlay').show();
               $('.decform').show();
               //$("html, body").css("overflow", "hidden");
            });
            $('.close-content').on('click', function () {

               $('.decform, .gjc_overlay').hide();
               //$("html, body").css("overflow", "visible");
            });
         });

</script>

Title: Re: Template over-ride to Disable add to cart for a category
Post by: GJC Web Design on September 25, 2017, 13:01:11 PM
make the 218 an array of the filtered cats

then use array_intersect
http://php.net/manual/en/function.array-intersect.php

if(count(array_intersect($array2,  $array))) {
   ...
}


Title: Re: Template over-ride to Disable add to cart for a category
Post by: phil147 on September 27, 2017, 00:32:52 AM
not sure i understand...would it be a matter of adding similar code to one file (product display) or would it be more complicated ?
Title: Re: Template over-ride to Disable add to cart for a category
Post by: GJC Web Design on September 27, 2017, 00:58:40 AM
$array2 = array(218,219);

if(count(array_intersect($array2,  $this->product->categories))) {
   ...
}

untested