Skip to content

Instantly share code, notes, and snippets.

@Ricardolau
Last active March 2, 2021 21:19
Show Gist options
  • Save Ricardolau/b4e5b051c3bd5a63c1229f8ba7b4123b to your computer and use it in GitHub Desktop.
Save Ricardolau/b4e5b051c3bd5a63c1229f8ba7b4123b to your computer and use it in GitHub Desktop.
Overwrite de com_virtuermat/sublayouts/customfields
<?php
/**
* sublayout products
* ORIGINAL DE :
* @package VirtueMart
* @author Max Milbers
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2014 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL2, see LICENSE.php
* @version $Id: cart.php 7682 2014-02-26 17:07:20Z Milbo $
*
* CAMBIOS POR:
* @ autor:Ricardo Carpintero
* @ link:http://ayuda.svigo.es/index.php/programacion/cms/joomla/componentes/virtuemart/211-vender-partes-de-un-producto
*/
defined('_JEXEC') or die('Restricted access');
$product = $viewData['product'];
$position = $viewData['position'];
$customTitle = isset($viewData['customTitle'])? $viewData['customTitle']: false;
if(isset($viewData['class'])){
$class = $viewData['class'];
} else {
$class = 'product-fields';
}
if (!empty($product->customfieldsSorted[$position])) {
?>
<div class="<?php echo $class?>">
<?php
if($customTitle and isset($product->customfieldsSorted[$position][0])){
$field = $product->customfieldsSorted[$position][0]; ?>
<div class="product-fields-title-wrapper">
<span class="product-fields-title">
<strong>
<?php echo vmText::_ ($field->custom_title); ?>
</strong>
</span>
<?php if ($field->custom_tip) {
echo JHtml::tooltip (vmText::_($field->custom_tip), vmText::_ ($field->custom_title), 'tooltip.png');
} ?>
</div> <?php
}
$custom_title = null;
foreach ($product->customfieldsSorted[$position] as $field) {
if ( $field->is_hidden || empty($field->display))//OSP http://forum.virtuemart.net/index.php?topic=99320.0
continue;
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if (!$customTitle and $field->custom_title != $custom_title and $field->show_title) { ?>
<div class="TituloCampos">
<span class="product-fields-title-wrapper">
<span class="product-fields-title">
<?php echo vmText::_ ($field->custom_title); ?>
</span>
<?php if ($field->custom_tip) {
echo JHtml::tooltip (vmText::_($field->custom_tip),'', '','<span class="glyphicon glyphicon-info-sign"></span>');
} ?>
</span>
</div>
<?php }?>
<div>
<?php
// Ahora recorremos las opciones y cambiamos si campo personalizado tiene id 3
$texto = array();
if ($field->virtuemart_custom_id === '3'){
$display = $field->display;
$opciones = $field->options;
foreach ($opciones as $opcion){
$gramos = $opcion->customfield_value;
// Lo que vamos a buscar NO puede ser $opcion->text , me imagino que pasa algo codificacion,
// ya que no va si.. tengo que poner en cada caso el texto.
switch ($gramos) {
case '100 grs' :
$texto[] = '100 grs a '.number_format($product->prices['salesPriceTemp']*(0.100),2);
$buscar[] = '100 grs --90 %';
break;
case '200 grs' :
$texto[] = '200 grs a '.number_format($product->prices['salesPriceTemp']*(0.200),2);
$buscar[] = '200 grs --80 %';
break;
case '250 grs' :
$texto[] = '250 grs a '.number_format($product->prices['salesPriceTemp']*(0.250),2);
$buscar[] = '250 grs --75 %';
break;
case '300 grs' :
$texto[] = '300 grs a '.number_format($product->prices['salesPriceTemp']*(0.300),2);
$buscar[] = '300 grs --70 %';
break;
case '350 grs' :
$texto[] = '350 grs a '.number_format($product->prices['salesPriceTemp']*(0.350),2);
$buscar[] = '350 grs --65 %';
break;
case '500 grs' :
$texto[] = '500 grs a '.number_format($product->prices['salesPriceTemp']*(0.500),2);
$buscar[] = '500 grs --50 %';
break;
case '600 grs' :
$texto[] = '600 grs a '.number_format($product->prices['salesPriceTemp']*(0.600),2);
$buscar[] = '600 grs --40 %';
break;
case '700 grs' :
$texto[] = '700 grs a '.number_format($product->prices['salesPriceTemp']*(0.700),2);
$buscar[] = '700 grs --30 %';
break;
case '750 grs' :
$texto[] = '750 grs a '.number_format($product->prices['salesPriceTemp']*(0.750),2);
$buscar[] = '750 grs --25 %';
break;
case '800 grs' :
$texto[] = '800 grs a '.number_format($product->prices['salesPriceTemp']*(0.800),2);
$buscar[] = '800 grs --20 %';
break;
case '1 Kilo' :
$texto[] = '1 Kilo a '.number_format($product->prices['salesPriceTemp']*(1.0),2);
$buscar[] = '1 Kilo Sin cargo adicional';
break;
case '1,2 Kilo' :
$texto[] = '1,2 Kilo a '.number_format($product->prices['salesPriceTemp']*(1.2),2);
$buscar[] = '1,2 Kilo +20 %';
break;
case '1,250 Kilo' :
$texto[] = '1,250 Kilo a '.number_format($product->prices['salesPriceTemp']*(1.25),2);
$buscar[] = '1,250 Kilo +25 %';
break;
case '1,5 Kilo' :
$texto[] = '1,5 Kilo a '.number_format($product->prices['salesPriceTemp']*(1.5),2);
$buscar[] = '1,5 Kilo +50 %';
break;
case '1,8 Kilo' :
$texto[] = '1,8 Kilo a '.number_format($product->prices['salesPriceTemp']*(1.8),2);
$buscar[] = '1,8 Kilo +80 %';
break;
case '2 Kilos':
$texto[] = '2 Kilos a '.number_format($product->prices['salesPriceTemp']*(2),2);
$buscar[] = '2 Kilos +100 %';
break;
case '2,5 Kilos' :
$texto[] = '2,5 Kilos a '.number_format($product->prices['salesPriceTemp']*(2.5),2);
$buscar[] = '2,5 Kilos +150 %';
break;
case '3 Kilos' :
$texto[] = '3 Kilos a '.number_format($product->prices['salesPriceTemp']*(3),2);
$buscar[] = '3 Kilos +200 %';
break;
case '4 Kilos' :
$texto[] = '4 Kilos a '.number_format($product->prices['salesPriceTemp']*(4),2);
$buscar[] = '4 Kilos +300 %';
break;
case '6,5 Kilos' :
$texto[] = '6,5 Kilos a '.number_format($product->prices['salesPriceTemp']*(6.5),2);
$buscar[] = '6,5 Kilos +550 %';
break;
case '7 Kilos' :
$texto[] = '7 Kilos a '.number_format($product->prices['salesPriceTemp']*(7),2);
$buscar[] = '7 Kilos +600 %';
break;
case '8 Kilos' :
$texto[] = '8 Kilos a '.number_format($product->prices['salesPriceTemp']*(8),2);
$buscar[] = '8 Kilos +700 %';
break;
case '13,5 Kilos' :
$texto[] = '13,5 Kilos a '.number_format($product->prices['salesPriceTemp']*(13.5),2);
$buscar[] = '13,5 Kilos +1250 %';
break;
}
}
}
if (count($texto) >0 ){
foreach ($texto as $key=>$t){
$texto[$key] = $t.'<span class="small">€</span>';
$display = str_replace($buscar[$key],$texto[$key],$display);
}
}
if (!empty($field->display)){
?>
<div class="product-field-display">
<?php echo $display; ?>
</div>
<?php
}
?>
<?php
if (!empty($field->custom_desc)){
?>
<div class="product-field-desc">
<?php echo $field->custom_desc;?>
</div>
<?php
}
?>
</div>
</div>
<?php
$custom_title = $field->custom_title;
} ?>
<div class="clear"></div>
</div>
<?php
}
?>
@Ricardolau
Copy link
Author

A ver si alguien se le ocurre algo para solucionar switch (DOCASE) que se puede hacer eterno.. jejej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment