-
-
Save deivisonarthur/6224419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
############### Exemplo do XML do Jacotei | |
Basta chamar o price com as funcões assim: | |
<parcelas>{price,[numerototalparcelas]}</parcelas> | |
<valor>{price,[valortotalparcelas]}</valor> | |
*/ | |
/* | |
<?xml version="1.0" encoding="utf-8"?> | |
<produtos> | |
{each type="product"} | |
<produto> | |
<codigo>{sku}</codigo> | |
<nome>{name,[utf8_encode]}</nome> | |
<categoria><![CDATA[{category,[utf8_encode]}]]></categoria> | |
<marca><![CDATA[{manufacturer,[utf8_encode]}]]></marca> | |
<preco>{price,[number_format 2]}</preco> | |
<condicao_especial><![CDATA[No Boleto ou Depósito bancário - 5% de desconto]]></condicao_especial> | |
<link><![CDATA[{url}?&utm_source=jacotei&utm_medium=cpc&utm_campaign={name}]]></link> | |
<imagem><![CDATA[{image}]]></imagem> | |
<parcelamento> | |
<parcelas>{price,[numerototalparcelas]}</parcelas> | |
<valor>{price,[valortotalparcelas]}</valor> | |
<max_parcelas_sem_juros>{price,[numerototalparcelas]}</max_parcelas_sem_juros> | |
</parcelamento> | |
</produto> | |
{/each} | |
</produtos> | |
*/ | |
class Mirasvit_FeedExport_Helper_Eval extends Mage_Core_Helper_Abstract { | |
public function execute($value, $formatterLine) { | |
$formatter = explode(' ', $formatterLine); | |
$method = $formatter[0]; | |
array_shift($formatter); | |
$args = $formatter; | |
if (!is_array($args)) { | |
$args = array(); | |
} | |
if (function_exists($method)) { | |
foreach ($args as $key => $arg) { | |
if (!is_numeric($arg)) { | |
$args[$key] = "'" . $arg . "'"; | |
} | |
} | |
$cmd = 'return ' . $method . '("' . addslashes($value) . '"'; | |
if (count($args)) { | |
$cmd .= ',' . implode(',', $args) . ''; | |
} | |
$cmd .= ');'; | |
$value = @eval($cmd); | |
} elseif (method_exists($this, $method)) { | |
array_unshift($args, $value); | |
$value = call_user_func_array(array($this, $method), $args); | |
} else { | |
$value .= $formatterLine; | |
} | |
/* | |
############################################################################################################ | |
CRIADO POR DEIVISON PARA TRATAR NUMERO TOTAL DO PARCELAMENTO / ALTERADO POR ISAAC PARCELA NO VALOR MINIMO | |
############################################################################################################ | |
*/ | |
if ($method == "numerototalparcelas") { | |
$parcelas = 6; | |
$valor_min_parcelas = 15; | |
$valor = $value; | |
if ($valor > $valor_min_parcelas){ | |
for ($counter = $parcelas; $counter >= 1; $counter--){ | |
if ($valor/$counter >= $valor_min_parcelas){ | |
$parcelas = $counter; | |
break; | |
} | |
} | |
}else{ | |
$parcelas = 1; | |
} | |
return $parcelas; | |
} | |
/* | |
############################################################################################################ | |
CRIADO POR DEIVISON PARA TRATAR VALOR TOTAL DO PARCELAMENTO | |
############################################################################################################ | |
*/ | |
if ($method == "valortotalparcelas") { | |
$parcelas = 6; | |
$valor_min_parcelas = 15; | |
$valor = $value; | |
if ($valor > $valor_min_parcelas){ | |
for ($counter = $parcelas; $counter >= 1; $counter--){ | |
if ($valor/$counter >= $valor_min_parcelas){ | |
$valor_parcelas = $valor/$counter; | |
break; | |
} | |
} | |
}else{ | |
$valor_parcelas = $valor; | |
} | |
return number_format($valor_parcelas, 2, '.', ''); | |
//return $valor_parcelas; | |
} | |
/* ####################### */ | |
//retorno defeault caso nao encontre nenhum metodo | |
return $value; | |
} | |
public function convert($value, $currency) { | |
$value = Mage::helper('directory')->currencyConvert($value, Mage::app()->getStore()->getBaseCurrencyCode(), $currency); | |
$value = number_format($value, 2, '.', ''); | |
return $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment