Blog

Sugar Professional MOD: Add Picture to Products Module

I posted the following Code Snippets as a Forumpost in the Sugar Professional Forum (restricted to clients emoticon ).

Well it did not get to many attention (like the whole prof. Forum Area!!) so i put it here to the public.

After insering the following code into your Sugar 3.0 Files you will be able to add a picture to a product … hey great Sugar guy´s it´s not even in you new 4.0 Sugarcrm professional version, at least not in your Demo … great worxs

I have not looked to deep into the 4.0 Sugarcrm Professional Code and skipped the 3.5 Version. It should be done the same way and you´ll see when you insert it. But maybe there are possibilities to make more use of global classes and hooks … thats what their marketing said.
If you want to learn a bit how to extend Sugar just see this as a little " How To" – Lesson

 Remarks

– PLEASE Notice: There might be some hidden probs in my code pieces so be carefull and BAckup Backup..!

– The Line numbers are just an orientation .. most pieces can slightly be put somewhere else in the file.

– This field can also contain any other allowed file types and then will not show the image in the detailView

– it is already very late (in germany) so i´ll hope i don´t miss anything.

- BACKUP BACKUP BACKUP both Files and Database (the Database is extended by two fields in the product table, nothing spectacular)

———————– 

Changed files: all in modules/Products/…

Product Insert files:

products.php
Save.php
editView.php
editView.html

Product View Files

DetailView.php
DetailView.html

Changed Db Tables:

table Products added 2 colums
filename
file_mime_type

SQL Insert:
ALTER TABLE `products` ADD `filename` VARCHAR( 100 ) DEFAULT NULL ,
ADD `file_mime_type` VARCHAR( 100 ) DEFAULT NULL ;

 

———————–

Ok now we go through each file and Apply the changes:

———————– 

editView.php

//around Line 61 change the duplicate checker
  
if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == ‘true’) {
    
//added for product image
    
if (! empty($focus->filename) )
    {
     
$old_id = $focus->id;
     }
    
//END added for product image

    $focus->id = "";
}

//—second Piece———- around Line 110

//added for product image   Georg Leciejewski
if (isset($_REQUEST['filename']) && $_REQUEST['isDuplicate'] != ‘true’) {
        
$focus->filename = $_REQUEST['filename'];
}
if ( empty(
$focus->filename))
{   
    
$xtpl->assign("FILENAME_TEXT", "");  //FILENAME_TEXT add to language file please
    
$xtpl->assign("FILENAME", "");  // add FILENAME to language file please
}
else
{
    
$xtpl->assign("FILENAME_TEXT", "(".$focus->filename.")");
    
$xtpl->assign("FILENAME", $focus->filename);
}
//added for product image  Georg Leciejewski 

——————————–

product.php

//added to class-variables on top … around Line 86
    
var $filename;                     //product image Georg Leciejewski
    
var $file_mime_type;               //product image Georg Leciejewski

// —–Second Piece ———
//added to  colum field Array … around Line 155

     var $column_fields = Array(…..
     …..
    ,
"filename"                 //product image Georg Leciejewski
    
, "file_mime_type"          //product image Georg Leciejewski 

——————————–

Save.php
 // Line 35 on the very top .. now you can create instances of the UploadFile Class :-)
require_once(‘include/upload_file.php’); //product image GL

// —–Second Piece ——— Line 81

//Product Image

    $upload_file = new UploadFile(‘uploadfile’);
    
$do_final_move = 0;
    if (isset(
$_FILES['uploadfile']) && $upload_file->confirm_upload())
    {

             if (!empty($focus->id) && !empty($_REQUEST['old_filename']) )
             {
                      
$upload_file->unlink_file($focus->id,$_REQUEST['old_filename']);
                        }
                                
$focus->filename = $upload_file->get_stored_file_name();
                                        
$focus->file_mime_type = $upload_file->mime_type;

                                         $do_final_move = 1;
                                         }
                                         else if ( isset(
$_REQUEST['old_filename']))
                                         {
                                          
$focus->filename = $_REQUEST['old_filename'];
                                          }

                                          $return_id = $focus->save();

                                          if ($do_final_move)
                                          {
                                           
$upload_file->final_move($focus->id);
                                           }
                                           else if ( ! empty(
$_REQUEST['old_id']))
                                           {
                                            
$upload_file->duplicate_file($_REQUEST['old_id'], $focus->id, $focus->filename);
                                            }

//END Product Image

—————————— 

editView.html

 <!– // changed formtype to multipart on top Line 35–>

<form name="EditView" method="POST" action="index.php" enctype="multipart/form-data">

<!– // insert upload file field input somewhere .. just be aware not to break the html structure –>

<td width="dataField" class="dataLabel"><slot>{MOD.LBL_FILENAME}</slot></td>

<td width="dataField" class="dataField"><slot><input name="uploadfile" tabindex="2" type="file" size="60"/> {FILENAME_TEXT}<input type=’hidden’ name=’old_filename’ value=’{FILENAME}’/><input type=’hidden’ name=’old_id’ value=’{OLD_ID}’/></slot>
</td>

——————————

DetailView.html

<!–i added it around Line 147 but you can put it anywhere you want .. just be aware not to break the html structure–>

<td class="tabDetailViewDL"><slot>{MOD.LBL_FILENAME}</slot></td>

<td class="tabDetailViewDF"><slot>{FILELINK}</slot></td>

 ——————————

DetailView.php

 // on the very top .. Line 38
require_once(‘include/upload_file.php’);  // product image Georg Leciejewski

//————-second piece———————- .. Line 147

//added for product image   Georg Leciejewski
if ( isset($focus->filename) && $focus->filename != )
{
        
$fileurl = "<a href=\"".UploadFile::get_url($focus->filename,$focus->id)."\" target=\"_blank\">". $focus->filename ."</a>";
        
$xtpl->assign("FILELINK", $fileurl);
}
//END added for product image  Georg Leciejewski

 

2 Comments to Sugar Professional MOD: Add Picture to Products Module

  1. Stephen Billington's Gravatar Stephen Billington
    08.09.2006 at 12:38

    Dear Sir

    Thanks for sharing your code. One question will this work on the open source of Sugar crm with the product addon “C3CRM-Quotes”?

    Thanks a lot for any advice