Author Topic: [Hack] VM1.1.8 - Customise Products in Attribute_Drop  (Read 3400 times)

NikolaiM

  • Beginner
  • *
  • Posts: 6
[Hack] VM1.1.8 - Customise Products in Attribute_Drop
« on: April 09, 2012, 07:09:17 am »
Hey,

Client wanted products to show up that are sold out in the attribute list but have they greyed out saying - "Sold Out"

This code will also work to show the amount available in stock next to each product

See demo: http://www.yoursyours.com/store/detail/11-yours-shop-online/flypage/1082-the-classic-black?sef=hcfp

You need to have it in VM that "Check Stock" and "Show Products that are Out of Stock" and then edit:

/administrator/components/com_virtuemart/classes/ps_product_attribute.php

Find: function list_attribute_drop( $product_id, $cls_suffix ) {

add product_in_stock to the query here:

if( CHECK_STOCK && PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS != "1") {
         $q1 = " AND product_in_stock > 0 ";
      }
      $q = "SELECT product_id,product_name, product_in_stock FROM #__{vm}_product WHERE product_parent_id='$product_id' AND product_publish='Y'" ;
      $db->query($q.$q1);

Find: // Start row for this child

Add:
//Nikolai Show Sold Out Products Disabled
                                $whatstock = $db->f( "product_in_stock" );
                               
                               if ($whatstock == '0') {
                               $disabled = 'disabled="disabled"';
                               $soldout = '- Sold Out';
                               }
                               else
                               {
                               $disabled = '';
                               $soldout = '';
                               //If you want to show the in-stock amount next to each product in the list use this
                               //$soldout = '$whatstock';
                               };
                               
Directly below, remove the code that generates the <option> and replace with:

$html .= "<option " . $disabled . " value=\"" . $db->f( "product_id" ) . "\" $selected>" ;


Find:
while( $db_item->next_record() ) {

Add:
$html .= $soldout;
above:
if( ! $db_sku->is_last_record() )

Done!

mimi86uk

  • Beginner
  • *
  • Posts: 3
Re: [Hack] VM1.1.8 - Customise Products in Attribute_Drop
« Reply #1 on: October 11, 2012, 17:59:12 pm »
This didn't work for me.
I have virtuemart 1.1.5 and I kept getting syntax errors.

My attributes (sizes) look like graphic boxes.
I have different quantities of different sizes   
goo.gl/fotCg

Do you have any advice?? I dont want to upgrade because then i gotta pay more money for the template to work.  ;)