Author Topic: Additional Product Fields  (Read 6095 times)

soupman

  • Beginner
  • *
  • Posts: 19
Re: Additional Product Fields
« Reply #15 on: October 01, 2010, 05:42:54 am »
Thanks for jogging my brain today on your issues qme1ster for it made me think!

And yes from what I can tell and what I have done I think it works. Now some of you may use the "product type" to add elements and it may work for most but I have on the order of 100 unique fields and that approach will not work long term.

Enough with my problems here is what I did to get the data to show up can't say it's all correct but it works and please add to this if there is something missing it helps everyone out or even to clarify.

We will work with 2 files

shop_browse_queries.php
shop.browse.php


1st we need to fetch the data from the database. (Logical)

You will find the info here:

/administrator/components/com_virtuemart/html/shop_browse_queries.php


About line 30 - 33 if no other mods done.

Here it is below:
----------------------------------------

/** Prepare the SQL Queries
*
*/
// These are the names of all fields we fetch data from
$fieldnames = "`product_name`,`products_per_row`,`category_browsepage`,`category_flypage`,`#__{vm}_category`.`category_id`,
            `#__{vm}_product`.`product_id`,`product_full_image`,`product_thumb_image`,`product_s_desc`,`product_parent_id`,`product_publish`,
`product_in_stock`,`b_brand`,`b_size`,  -and so on

--------------------------------------------

There, now we fetchd the data that we previously stored in the DB


It gets even easier - 2 steps in this file

Now go to ->    /administrator/components/com_virtuemart/html/shop.browse.php

STEP 1

About line 100 and add in your fields that you fetched "b_brand" and cast them "$b_brand" as below

 
      
/**
       * CATEGORY DESCRIPTION
       */
      $browsepage_lbl = $category_name;
      $tpl->set( 'browsepage_lbl', $browsepage_lbl );

      $tpl->set( 'desc', $desc );
         $tpl->set( 'b_brand', $b_brand );
         $tpl->set( 'b_size', $b_size );
         $tpl->set( 'b_UTQG', $b_UTQG );


STEP 2

Bottom of page about 470

Fetch them for the $db_browse

      $products[$i]['product_url'] = $db_browse->f("product_url");
      $products[$i]['b_brand'] = $db_browse->f("b_brand" );
      $products[$i]['b_size'] = $db_browse->f("b_size" );




That's all - add them to your "browse" template and they should show up



qme1ster

  • Jr. Member
  • **
  • Posts: 276
Re: Additional Product Fields
« Reply #16 on: October 01, 2010, 14:58:52 pm »
Hi soupman, I'm glad you sorted your issue !

Unfortunately my issues persist ! I've followed your instructions but am ending up with a parse error which I can't figure out.

When trying to access VM admin in Joomla backend I get the following:

Parse error: syntax error, unexpected T_DOUBLE_ARROW in /home/mydomain/public_html/administrator/components/com_virtuemart/classes/ps_product.php on line 305

This line 305 is the start of the code additions I made. I added the following in the code block as per your instructions:

Code: [Select]
// Insert into DB
        $fields = array ( 'vendor_id' => $vendor_id,
                        'product_parent_id' => vmRequest::getInt('product_parent_id'),
                        'product_sku' => vmGet($d,'product_sku'),
                        'product_name' => vmGet($d,'product_name'),
                        'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
                        'product_s_desc' => vmRequest::getVar('product_s_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
                        'product_thumb_image' => vmGet($d,'product_thumb_image'),
                        'product_full_image' => vmGet($d,'product_full_image'),
                        'product_publish' => $d['product_publish'],
                        'product_weight' => vmRequest::getFloat('product_weight'),
                        'product_weight_uom' => vmGet($d,'product_weight_uom'),
                        'product_length' => vmRequest::getFloat('product_length'),
                        'product_width' => vmRequest::getFloat('product_width'),
                        'product_height' => vmRequest::getFloat('product_height'),
                        'product_lwh_uom' => vmGet($d,'product_lwh_uom'),
                        'product_unit' => vmGet($d,'product_unit'),
                        'product_packaging' => (($d["product_box"] << 16) | ($d["product_packaging"]&0xFFFF)),
                        'product_url' => vmGet($d,'product_url'),
                        'product_in_stock' => vmRequest::getInt('product_in_stock'),
                        'attribute' => ps_product_attribute::formatAttributeX(),
                        'custom_attribute' => vmGet($d,'product_custom_attribute'),
                        'product_available_date' => $d['product_available_date_timestamp'],
                        'product_availability' => vmGet($d,'product_availability'),
                        'product_special' => $d['product_special'],
                        'child_options' => $d['child_options'],
                        'quantity_options' => $d['quantity_options'],
                        'product_discount_id' => vmRequest::getInt('product_discount_id'),
                        'cdate' => $timestamp,
                        'mdate' => $timestamp,
                        'product_tax_id' => vmRequest::getInt('product_tax_id'),
                        'child_option_ids' => vmGet($d,'included_product_id'),
                        'product_order_levels' => $d['order_levels'] );
                        'extra_diameter' => vmGet($d,'extra_diameter'),
                         'extra_colour' => vmGet($d,'extra_colour');
                        'extra_material' => vmGet($d,'extra_material');
                        'extra_lightbulb_type' => vmGet($d,'extra_lightbulb_type');
                        'extra_lightbulb_incl' => vmGet($d,'extra_lightbulb_incl');
                        'extra_dimmer' => vmGet($d,'extra_dimmer');
                        'extra_cordlength' => vmGet($d,'extra_cordlength');
                        'extra_ipnumber' => vmGet($d,'extra_ipnumber');

The last 8 items are my additions. I had followed your instructions here:
Quote
To add data - > ADD around line 250

// Insert into DB
      $fields = array ( 'vendor_id' => $vendor_id,
            'product_parent_id' => vmRequest::getInt('product_parent_id'),
            'product_sku' => vmGet($d,'product_sku'),
            'product_name' => vmGet($d,'product_name'),
            'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
            'b_brand' => vmGet($d,'b_brand'),

and so on..... for all the fields you need to ADD

It's probably a very simple error I've made somewhere but in the first instance I'd thought I'd run this by you in case you can see straight away what the issue might be.

These are the fields are added in the database:

extra_diameter
extra_colour
extra_material
extra_lightbulb_type
extra_lightbulb_incl
extra_dimmer
extra_cordlength
extra_ipnumber

I'm just wondering, was I supposed to create variables for these somewhere ?

Thanks again

q

soupman

  • Beginner
  • *
  • Posts: 19
Re: Additional Product Fields
« Reply #17 on: October 01, 2010, 16:11:48 pm »
qme1ster,

On a quick note I see this error you are using semicolons and commas

, and ; at the end of the line.

qme1ster

  • Jr. Member
  • **
  • Posts: 276
Re: Additional Product Fields
« Reply #18 on: October 01, 2010, 17:12:32 pm »
Thanks soupman. Well spotted ! I've corrected that code block as follows and that is now working.

Code: [Select]
// Insert into DB
        $fields = array ( 'vendor_id' => $vendor_id,
                        'product_parent_id' => vmRequest::getInt('product_parent_id'),
                        'product_sku' => vmGet($d,'product_sku'),
                        'product_name' => vmGet($d,'product_name'),
                        'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
                        'product_s_desc' => vmRequest::getVar('product_s_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
                        'product_thumb_image' => vmGet($d,'product_thumb_image'),
                        'product_full_image' => vmGet($d,'product_full_image'),
                        'product_publish' => $d['product_publish'],
                        'product_weight' => vmRequest::getFloat('product_weight'),
                        'product_weight_uom' => vmGet($d,'product_weight_uom'),
                        'product_length' => vmRequest::getFloat('product_length'),
                        'product_width' => vmRequest::getFloat('product_width'),
                        'product_height' => vmRequest::getFloat('product_height'),
                        'product_lwh_uom' => vmGet($d,'product_lwh_uom'),
                        'product_unit' => vmGet($d,'product_unit'),
                        'product_packaging' => (($d["product_box"] << 16) | ($d["product_packaging"]&0xFFFF)),
                        'product_url' => vmGet($d,'product_url'),
                        'product_in_stock' => vmRequest::getInt('product_in_stock'),
                        'attribute' => ps_product_attribute::formatAttributeX(),
                        'custom_attribute' => vmGet($d,'product_custom_attribute'),
                        'product_available_date' => $d['product_available_date_timestamp'],
                        'product_availability' => vmGet($d,'product_availability'),
                        'product_special' => $d['product_special'],
                        'child_options' => $d['child_options'],
                        'quantity_options' => $d['quantity_options'],
                        'product_discount_id' => vmRequest::getInt('product_discount_id'),
                        'cdate' => $timestamp,
                        'mdate' => $timestamp,
                        'product_tax_id' => vmRequest::getInt('product_tax_id'),
                        'child_option_ids' => vmGet($d,'included_product_id'),
                        'product_order_levels' => $d['order_levels'],
                        'extra_diameter' => vmGet($d,'extra_diameter'),
                         'extra_colour' => vmGet($d,'extra_colour'),
                        'extra_material' => vmGet($d,'extra_material'),
                        'extra_lightbulb_type' => vmGet($d,'extra_lightbulb_type'),
                        'extra_lightbulb_incl' => vmGet($d,'extra_lightbulb_incl'),
                        'extra_dimmer' => vmGet($d,'extra_dimmer'),
                        'extra_cordlength' => vmGet($d,'extra_cordlength'),
                        'extra_ipnumber' => vmGet($d,'extra_ipnumber') );

Commas after adding the call for each new field, and ending with a closing bracket and a semi colon.

I can see my new product fields in a new tab in VM admin, and have tested that new data is saved to the database. Thank you SO SO MUCH !

One small issue - the tab name is not being output for some reason. In product.product_form I did start the new tab code block as follows:

Code: [Select]
<?php
$tabs
->endTab();

$tabs->startTab$specs_label"specs-page");

?>

<h2><?php echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ITEM_ADD_SPECS_LBL'?></h2>

 I also added PHPSHOP_PRODUCT_FORM_ITEM_ADD_SPECS_LBL to the ...languages/product/english.php file as follows:

Code: [Select]
'PHPSHOP_PRODUCT_FORM_ITEM_ADD_SPECS_LBL' => 'Additional Product Information'
So  not sure why that's not being output. Again probably something really simple that I've overlooked !

Thanks again.

q

soupman

  • Beginner
  • *
  • Posts: 19
Re: Additional Product Fields
« Reply #19 on: October 01, 2010, 17:37:27 pm »
qme1ster,

Try outputing the entry from the language.php file anywhere on a page to see if it is reading correctly. The way I read your statement the page name should show up under the tab as a page heading.

<?php echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ITEM_ADD_SPECS_LBL') ?>

qme1ster

  • Jr. Member
  • **
  • Posts: 276
Re: Additional Product Fields
« Reply #20 on: October 01, 2010, 18:22:30 pm »
Hi soupman,

I think I see what the problem might be. I am getting the heading output at the top of the page, above my new product fields, as it's supposed to. The tab itself though does not have a title, and I've just resolved that - I had omitted to define that label variable.

I had started the code block for the creation of the new tab with:

Code: [Select]
$tabs->startTab( $specs_label, "specs-page");
I needed to define $specs_label, which I did as follows:-

Code: [Select]
$specs_label = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ITEM_ADD_SPECS_LBL');
I placed this code in 2 places - line 80 and line 100.

I now have a tab title !

Thanks again !!


edthenet

  • Beginner
  • *
  • Posts: 33
    • Scorpion Computers & Software
Re: Additional Product Fields
« Reply #21 on: November 08, 2010, 14:23:21 pm »
The problem with core changes is that you can't update to a newer version of Virtuemart. You loose the changes.