Back to top

Autore Topic: [HACK] Inserire immagini per i produttori  (Letto 14008 volte)

Offline arjuna

  • Esploratore
  • **
  • Post: 79
    • Mostra profilo
[HACK] Inserire immagini per i produttori
« il: 03 Giu 2006, 14:06:59 »
Ho provato a modificare VM per aggiungere un'immagine (il logo) ai produttori.

Alla fine c'è anche un commento agli interventi effettuati.

Adding Image to Manufacturer

SQL:

Codice: [Seleziona]
ALTER TABLE `jos_vm_manufacturer` ADD `mf_thumb_image` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `mf_desc` ,
ADD `mf_full_image` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `mf_thumb_image` ;

\administrator\components\com_virtuemart\htmlmanufacturer.manufacturer_form.php:

find:
Codice: [Seleziona]
global $ps_manufacturer_category;
replace:
Codice: [Seleziona]
global $ps_manufacturer_category, $ps_product;
find:
Codice: [Seleziona]
$formObj->startForm();

replace:
Codice: [Seleziona]
$formObj->startForm( 'adminForm', 'enctype="multipart/form-data"');

$tabs = new mShopTabs(0, 1, "_main");
$tabs->startPane("manufacturer-pane");
$tabs->startTab( "<img src=\"". IMAGEURL ."ps_image/edit.png\" align=\"center\" width=\"16\" height=\"16\" border=\"0\" />&nbsp;".$VM_LANG->_PHPSHOP_MANUFACTURER_FORM_LBL, "info-page");

find:
Codice: [Seleziona]
</table>
<?php
(It's approssimately at line 80, it's the end of the html template)

add after:
Codice: [Seleziona]
$tabs->endTab();
$tabs->startTab( "<img src=\"". IMAGEURL ."ps_image/image.png\" width=\"16\" height=\"16\" align=\"center\" border=\"0\" />&nbsp;"._E_IMAGES, "status-page");

if( !stristr( $db->f("mf_thumb_image"), "http") )
  echo "<input type=\"hidden\" name=\"mf_thumb_image_curr\" value=\"". $db->f("mf_thumb_image") ."\" />";

if( !stristr( $db->f("mf_full_image"), "http") )
  echo "<input type=\"hidden\" name=\"mf_full_image_curr\" value=\"". $db->f("mf_full_image") ."\" />";

   $ps_html->writableIndicator( array( IMAGEPATH."manufacturer") );

?>

  <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td valign="top" width="50%" style="border-right: 1px solid black;">
        <h2><?php echo $VM_LANG->_PHPSHOP_PRODUCT_FORM_FULL_IMAGE ?></h2>
        <table>
          <tr>
            <td colspan="2" ><?php
              
if ($manufacturer_id) {
                echo 
$VM_LANG->_PHPSHOP_PRODUCT_FORM_IMAGE_UPDATE_LBL "<br />"; } ?>

              <input type="file" class="inputbox" name="mf_full_image" size="50" maxlength="255" />
            </td>
          </tr>
          <tr>
            <td colspan="2" ><strong><?php echo $VM_LANG->_PHPSHOP_IMAGE_ACTION ?>:</strong><br/>
              <input type="radio" class="inputbox" name="mf_full_image_action" id="mf_full_image_action0" checked="checked" value="none" onchange="toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image, true );toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image_url, true );"/>
              <label for="mf_full_image_action0"><?php echo $VM_LANG->_PHPSHOP_NONE ?></label><br/>
              <?php
              
if( function_exists('imagecreatefromjpeg')) {
              
?>

              <input type="radio" class="inputbox" name="mf_full_image_action" id="mf_full_image_action1" value="auto_resize" onchange="toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image, true );toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image_url, true );"/>
              <label for="mf_full_image_action1"><?php echo $VM_LANG->_PHPSHOP_FILES_FORM_AUTO_THUMBNAIL "</label><br />";
              }
              if (
$manufacturer_id and $db->f("mf_full_image")) { ?>

                <input type="radio" class="inputbox" name="mf_full_image_action" id="mf_full_image_action2" value="delete" onchange="toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image, true );toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image_url, true );"/>
                <label for="mf_full_image_action2"><?php echo $VM_LANG->_PHPSHOP_PRODUCT_FORM_IMAGE_DELETE_LBL "</label><br />";
              } 
?>

            </td>
          </tr>
          <tr><td colspan="2">&nbsp;</td></tr>
          <tr>
            <td width="21%" ><?php echo _URL." ("._CMN_OPTIONAL."!)&nbsp;"?></td>
            <td width="79%" >
              <?php
              
if( stristr($db->f("mf_full_image"), "http") )
                
$manufacturer_full_image_url $db->f("mf_full_image");
              else if(!empty(
$_REQUEST['mf_full_image_url']))
                
$manufacturer_full_image_url $_REQUEST['mf_full_image_url'];
              else
                
$manufacturer_full_image_url "";
              
?>

              <input type="text" class="inputbox" size="50" name="mf_full_image_url" value="<?php echo $manufacturer_full_image_url ?>" onchange="if( this.value.length>0) document.adminForm.auto_resize.checked=false; else document.adminForm.auto_resize.checked=true; toggleDisable( document.adminForm.auto_resize, document.adminForm.mf_thumb_image_url, true );toggleDisable( document.adminForm.auto_resize, document.adminForm.mf_thumb_image, true );" />
            </td>
          </tr>
          <tr><td colspan="2">&nbsp;</td></tr>
          <tr>
            <td colspan="2" >
              <div style="overflow:auto;">
                <?php echo $ps_product->image_tag($db->f("mf_full_image"), ""0"manufacturer"?>
              </div>
            </td>
          </tr>
        </table>
      </td>

      <td valign="top" width="50%">
        <h2><?php echo $VM_LANG->_PHPSHOP_PRODUCT_FORM_THUMB_IMAGE ?></h2>
        <table>
          <tr>
            <td colspan="2" ><?php if ($manufacturer_id) {
                echo 
$VM_LANG->_PHPSHOP_PRODUCT_FORM_IMAGE_UPDATE_LBL "<br>"; } ?>

              <input type="file" class="inputbox" name="mf_thumb_image" size="50" maxlength="255" onchange="if(document.adminForm.mf_thumb_image.value!='') document.adminForm.mf_thumb_image_url.value='';" />
            </td>
          </tr>
          <tr>
            <td colspan="2" ><strong><?php echo $VM_LANG->_PHPSHOP_IMAGE_ACTION ?>:</strong><br/>
              <input type="radio" class="inputbox" id="mf_thumb_image_action0" name="mf_thumb_image_action" checked="checked" value="none" onchange="toggleDisable( document.adminForm.image_action[1], document.adminForm.mf_thumb_image, true );toggleDisable( document.adminForm.image_action[1], document.adminForm.mf_thumb_image_url, true );"/>
              <label for="mf_thumb_image_action0"><?php echo $VM_LANG->_PHPSHOP_NONE ?></label><br/>
              <?php
              
if ($manufacturer_id and $db->f("mf_thumb_image")) { ?>

                <input type="radio" class="inputbox" id="mf_thumb_image_action1" name="mf_thumb_image_action" value="delete" onchange="toggleDisable( document.adminForm.image_action[1], document.adminForm.mf_thumb_image, true );toggleDisable( document.adminForm.image_action[1], document.adminForm.mf_thumb_image_url, true );"/>
                <label for="mf_thumb_image_action1"><?php echo $VM_LANG->_PHPSHOP_PRODUCT_FORM_IMAGE_DELETE_LBL "</label><br />";
              } 
?>

            </td>
          </tr>
          <tr><td colspan="2">&nbsp;</td></tr>
          <tr>
            <td width="21%" ><?php echo _URL." ("._CMN_OPTIONAL.")&nbsp;"?></td>
            <td width="79%" >
              <?php
              
if( stristr($db->f("mf_thumb_image"), "http") )
                
$manufacturer_thumb_image_url $db->f("mf_thumb_image");
              else if(!empty(
$_REQUEST['mf_thumb_image_url']))
                
$manufacturer_thumb_image_url $_REQUEST['mf_thumb_image_url'];
              else
                
$manufacturer_thumb_image_url "";
              
?>

              <input type="text" class="inputbox" size="50" name="mf_thumb_image_url" value="<?php echo $manufacturer_thumb_image_url ?>" />
            </td>
          </tr>
          <tr><td colspan="2">&nbsp;</td></tr>
          <tr>
            <td colspan="2" >
              <div style="overflow:auto;">
                <?php echo $ps_product->image_tag($db->f("mf_thumb_image"), ""0"manufacturer"?>
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
<?php
$tabs
->endTab();
$tabs->endPane();

find the end of the file:

Codice: [Seleziona]
$formObj->finishForm( $funcname, $modulename.'.manufacturer_list', $option );
?>

add after:

Codice: [Seleziona]
<script language="javascript">
<!--
function toggleDisable( elementOnChecked, elementDisable, disableOnChecked ) {
  if( !disableOnChecked ) {
    if(elementOnChecked.checked==true) {
      elementDisable.disabled=false;
    }
    else {
      elementDisable.disabled=true;
    }
  }
  else {
    if(elementOnChecked.checked==true) {
      elementDisable.disabled=true;
    }
    else {
      elementDisable.disabled=false;
    }
  }
}

toggleDisable( document.adminForm.mf_full_image_action[1], document.adminForm.mf_thumb_image, true );
-->
</script>


Add Dir:
\components\com_virtuemart\shop_image\manufacturer


Ho usato come modello il file:
\administrator\components\com_virtuemart\htmlproduct.product_category_form.php

Ho semplicemente aggiunto il codice per i TAB e inserito il codice per il TAB delle immagini.
Poi ho sostituito i riferimenti a category_ con mf_

La cosa è più semplice di quanto sembri...
« Ultima modifica: 12 Set 2006, 12:17:09 da giorgioblu »

Offline arjuna

  • Esploratore
  • **
  • Post: 79
    • Mostra profilo
Re: [HACK] Inserire immagini per i produttori
« Risposta #1 il: 03 Giu 2006, 18:46:56 »
C'è anche questo file da modificare
Lo posto tutto perchè ci sono molte modifiche da fare (inerenti i due nuovi campi da aggiungere: mf_full_image e mf_thumb_image)

\administrator\components\com_virtuemart\classes\ps_manufacturer.php:

Codice: [Seleziona]
<?php
defined
'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
/**
*
* @version $Id: ps_manufacturer.php,v 1.4.2.2 2006/03/14 18:42:11 soeren_nb Exp $
* @package VirtueMart
* @subpackage classes
* @copyright Copyright (C) 2004-2005 Soeren Eberhardt. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/

/****************************************************************************
*
* CLASS DESCRIPTION
*
* ps_manufacturer
*
* The class is is used to manage the manufacturers in your store.
*
* properties:
*
*       error - the error message returned by validation if any
* methods:
*       validate_add()
* validate_delete()
* validate_update()
*       add()
*       update()
*       delete()
*
*
*************************************************************************/
class ps_manufacturer {
var $classname "ps_manufacturer";
var $error;

/**************************************************************************
** name: validate_add()
** created by: soeren
** description:
** parameters:
** returns:
***************************************************************************/
function validate_add(&$d) {
        global 
$vmLogger;
$valid true;
$db = new ps_DB;

if (!$d["mf_name"]) {
$vmLogger->err"ERROR:  You must enter a name for the manufacturer.");
$valid False;
}
else {
$q "SELECT count(*) as rowcnt from #__{vm}_manufacturer where";
$q .= " mf_name='" .  $d["mf_name"] . "'";
$db->setQuery($q);
$db->query();
$db->next_record();
if ($db->f("rowcnt") > 0) {
$vmLogger->err"The given manufacturer name already exists.");
$valid False;
}
}

/** Image Upload Validation **/

// do we have an image URL or an image File Upload?
if (!empty( $d['mf_thumb_image_url'] )) {
// Image URL
if (substr$d['mf_thumb_image_url'], 04) != "http") {
$vmLogger->err"Image URL must begin with http." );
$valid =  false;
}

$d["mf_thumb_image"] = $d['mf_thumb_image_url'];
}
else {
// File Upload
if (!validate_image$d"mf_thumb_image""manufacturer")) {
$valid false;
}
}

if (!empty( $d['mf_full_image_url'] )) {
// Image URL
if (substr$d['mf_full_image_url'], 04) != "http") {
$vmLogger->err"Image URL must begin with http." );
return false;
}
$d["mf_full_image"] = $d['mf_full_image_url'];
}
else {
// File Upload
if (!validate_image$d"mf_full_image""manufacturer")) {
    $vmLogger->err"immagine non validata." );
$valid false;
}
}
return $valid;
        }

        
/**************************************************************************
        ** name: validate_update
        ** created by: soeren
        ** description:
        ** parameters:
        ** returns:
        ***************************************************************************/
        
function validate_update(&$d) {
            global 
$vmLogger;
    $valid true;
                if (!
$d["mf_name"]) {
                        
$vmLogger->err"ERROR:  You must enter a name for the manufacturer.");
                        
$valid =  false;
                }

                
$db =& new ps_DB;
        
$q "SELECT mf_thumb_image,mf_full_image FROM #__{vm}_manufacturer WHERE manufacturer_id='"$d["manufacturer_id"] . "'";
        
$db->query$q );
        
$db->next_record();

        
/** Image Upload Validation **/

        
// do we have an image URL or an image File Upload?
        
if (!empty( $d['mf_thumb_image_url'] )) {
        
// Image URL
        
if (substr$d['mf_thumb_image_url'], 04) != "http") {
        
$vmLogger->err"An Image URL must begin with 'http'." );
        
$valid =  false;
        
}

        
// if we have an uploaded image file, prepare this one for deleting.
        
if( $db->f("mf_thumb_image") && substr$db->f("mf_thumb_image"), 04) != "http") {
        
$_REQUEST["mf_thumb_image_curr"] = $db->f("mf_thumb_image");
        
$d["mf_thumb_image_action"] = "delete";
        
if (!validate_image$d"mf_thumb_image""manufacturer")) {
        
return false;
        
}
        
}
        
$d["mf_thumb_image"] = $d['mf_thumb_image_url'];
        
}
        
else {
        
// File Upload
        
if (!validate_image$d"mf_thumb_image""manufacturer")) {
        
$valid false;
        
}
        
}

        
if (!empty( $d['mf_full_image_url'] )) {
        
// Image URL
        
if (substr$d['mf_full_image_url'], 04) != "http") {
        
$vmLogger->err"Image URL must begin with 'http'." );
        
return false;
        
}
        
// if we have an uploaded image file, prepare this one for deleting.
        
if( $db->f("mf_full_image") && substr$db->f("mf_thumb_image"), 04) != "http") {
        
$_REQUEST["mf_full_image_curr"] = $db->f("mf_full_image");
        
$d["mf_full_image_action"] = "delete";
        
if (!validate_image$d"mf_full_image""manufacturer")) {
        
    $vmLogger->err"immagine2 non validata." );
        
return false;
        
}
        
}
        
$d["mf_full_image"] = $d['mf_full_image_url'];
        
}
        
else {
        
// File Upload
        
if (!validate_image$d"mf_full_image""manufacturer")) {
        
    $vmLogger->err"immagine non validata3." );
        
$valid false;
        
}
        
}

        
return $valid;
        }

        
/**************************************************************************
        ** name: validate_delete()
        ** created by: soeren
        ** description:
        ** parameters:
        ** returns:
        ***************************************************************************/
        
function validate_delete($manufacturer_id) {
                global 
$db$vmLogger;

                if (empty( 
$manufacturer_id )) {
                        
$vmLogger->err"ERROR:  Please select a manufacturer to delete.");
                        return 
False;
                }
                
$db->query"SELECT jos_vm_product.product_id, manufacturer_id
                                                FROM jos_vm_product, jos_vm_product_mf_xref
                                                WHERE manufacturer_id ="
.intval($manufacturer_id)."
                                                AND jos_vm_product.product_id = jos_vm_product_mf_xref.product_id" 
);
                if( 
$db->num_rows() > ) {
                        
$vmLogger->err"Error: This Manufacturer still has products assigned to it.");
                        return 
false;
                }
                
$q "SELECT mf_thumb_image, mf_full_image FROM #__{vm}_manufacturer WHERE manufacturer_id='$manufacturer_id'";
        
$db->query$q );
        
$db->next_record();

        
/* Prepare category_thumb_image for Deleting */
        
if( !stristr$db->f("mf_thumb_image"), "http") ) {
        
$_REQUEST["mf_thumb_image_curr"] = $db->f("mf_thumb_image");
        
$d["mf_thumb_image_action"] = "delete";
        
if (!validate_image($d,"mf_thumb_image","manufacturer")) {
        
$vmLogger->err"Failed deleting Manufacturer Images!" );
        
return false;
        
}
        
}
        
/* Prepare product_full_image for Deleting */
        
if( !stristr$db->f("mf_full_image"), "http") ) {
        
$_REQUEST["mf_full_image_curr"] = $db->f("mf_full_image");
        
$d["mf_full_image_action"] = "delete";
        
if (!validate_image($d,"mf_full_image","manufacturer")) {
        
    $vmLogger->err"immagine non validata4." );
        
return false;
        
}
        
}
                return 
True;

        }


/**************************************************************************
* name: add()
* created by: soeren
* description: creates a new manufacturer record
* parameters:
* returns:
**************************************************************************/
function add(&$d) {
        global 
$vmLogger;
        
$db = new ps_DB;

        
$GLOBALS['vmInputFilter']->safeSQL$d );

if ($this->validate_add($d)) {

if (!process_images($d)) {
return false;
}

while(list($key,$value)= each($d)) {
if (!is_array($value))
$d[$key] = addslashes($value);
}

$q "INSERT into #__{vm}_manufacturer (mf_name, mf_email, mf_desc, mf_category_id, mf_url, mf_thumb_image, mf_full_image)";
$q .= " VALUES ('";
    
$q .= $d["mf_name"] . "','";
    
$q .= $d["mf_email"] . "','";
    
$q .= $d["mf_desc"] . "','";
    
$q .= $d["mf_category_id"] . "','";
    
$q .= $d["mf_url"] . "')";

$q .= $d["mf_thumb_image"] . "','";
$q .= $d["mf_full_image"] . "','";

$db->setQuery($q);
$db->query();

$vmLogger->info"Successfully added new manufacturer: ".$d['mf_name'].'.');
return $manufacturer_id;
}
else {
return False;
}

}

/**************************************************************************
* name: update()
* created by: soeren
* description: updates manufacturer information
* parameters:
* returns:
**************************************************************************/
function update(&$d) {

    global $vmLogger;
        
$db = new ps_DB;
        
$timestamp time();

        
$GLOBALS['vmInputFilter']->safeSQL$d );

foreach ($d as $key => $value) {
if (!is_array($value))
$d[$key] = addslashes($value);
}
if ($this->validate_update($d)) {
if (!process_images($d)) {
return false;
}
$q "UPDATE #__{vm}_manufacturer set ";
$q .= "mf_name='" $d["mf_name"]."',";
    
$q .= "mf_email='" .$d["mf_email"] . "',";
    
$q .= "mf_desc='" .$d["mf_desc"] . "',";
    
$q .= "mf_category_id='" .$d["mf_category_id"] . "',";
    
$q .= "mf_url='" .$d["mf_url"] . "',";
    
$q .= "mf_thumb_image='" $d["mf_thumb_image"] . "',";
$q .= "mf_full_image='" $d["mf_full_image"] ."'";
    
$q .= "WHERE manufacturer_id='".$d["manufacturer_id"]."'";
$db->setQuery($q);
$db->query();

$vmLogger->info"Successfully updated manufacturer: ".$d['mf_name'].'.' );

return True;
}
else {
return False;
}
}

/**
* Controller for Deleting Records.
*/
function delete(&$d) {

$record_id $d["manufacturer_id"];

if( is_array$record_id)) {
foreach( $record_id as $record) {
if( !$this->delete_record$record$d ))
return false;
}
return true;
}
else {
return $this->delete_record$record_id$d );
}
}
/**
* Deletes one Record.
*/
function delete_record$record_id, &$d ) {
global $db$vmLogger;
if (!$this->validate_delete($record_id)) {

                        return 
False;
                }
                
$q "DELETE from #__{vm}_manufacturer WHERE manufacturer_id='$record_id'";
                
$db->query($q);

                
/* Delete Image files */
if (!process_images($d)) {
return false;
}
$vmLogger->info"Successfully deleted manufacturer ID: $record_id." );
return True;

        }

}

?>

L'ho modificato sulla sicia di \administrator\components\com_virtuemart\classes\ps_product_category.php
« Ultima modifica: 08 Giu 2006, 13:41:11 da arjuna »

Offline GiorgioBlu

  • Abituale
  • ****
  • Post: 861
  • Sesso: Maschio
  • Utente dal: 23/06/2004 Susegana - TV - Italy
    • Mostra profilo
Re: [HACK] Inserire immagini per i produttori
« Risposta #2 il: 05 Giu 2006, 12:33:11 »
Ottimo lavoro, non l'ho testato ma l'idea è molto buona ;).

Credo che se la segnalerai a Soeren nel forum ufficiale,
 la hack potrbbe diventare parte integrante del prossimo VM.

Tienici aggiornati!! :)

Offline arjuna

  • Esploratore
  • **
  • Post: 79
    • Mostra profilo
Re: [HACK] Inserire immagini per i produttori
« Risposta #3 il: 05 Giu 2006, 18:22:09 »
Il problema è che non funziona... non so perchè... ho seguito come un segugio tutti gli include... ho studiato le classi di VM ma nulla... purtroppo sul forum ufficiale ancora non mi hanno contattato e questa parte qui è fondamentale per adattare VM alle mie esigenze... Solo questa cosa qui mi tiene bloccato tutto il sito

Offline arjuna

  • Esploratore
  • **
  • Post: 79
    • Mostra profilo
Re: [HACK] Inserire immagini per i produttori
« Risposta #4 il: 08 Giu 2006, 13:38:01 »
Adesso funziona!!!

Ho modificato l'ultimo file... avevo dimenticato un &.

Ho controllato sul sito di VM, c'era gia la richiesta di questa modifica da parte di due utenti.

Uno di questi due aveva pure trovato la soluzione ma non l'aveva condivisa.

Adesso domando al tipo di porre la soluzione in rilievo...

tu invece che ne dici di porre questa in rilievo? oppure la riscriviamo per bene?

Offline Vix87

  • Esploratore
  • **
  • Post: 55
    • Mostra profilo
Re:[HACK] Inserire immagini per i produttori
« Risposta #5 il: 16 Mag 2011, 18:24:14 »
Vorrei sapere se qualcuno ha provato e utilizza questo hack.
Devo aprire un nuovo topic?

 



Web Design Bolzano Kreatif