-
- guigouzz

-
Total Posts: 1
Joined: 2012-08-05
|
Bonjour,
Je développe actuellement une fonction qui vient ajouter des calques de couleurs sur l’image produit existante par rapport à un attribut sélectionné (produit personnalisable avec plusieurs attributs couleur)
J’ai réalisé cela avec GD library (fonction merge).
La fonction merge fonctionne avec le premier attribut mais pas avec les suivants.
Le problème est :
Je veux envoyer la première variable à une autre fonction ($imagedone1) dans le fichier php
L’erreur :
A chaque fois que je clique sur un autre attribut (second par exemple), la valeur ($imagedone1) devient vide.
Peut-être que l’image crée par la première fonction est détruite quand je clic sur un autre attribut, car à chaque fois que l’on clique sur un attribut, ajax rafraichit la page.
J’ai utilisé les cookies et les sessions mais j’ai besoin de rafraichir la page pour obtenir la valeur.
C’est peut-être compliqué de comprendre ce que je veux faire, la version simple est :
Je veux envoyer la valeur de la première fonction à une autre fonction dans le fichier php en utilisant ajax et « onclick event ».
Si quelqu’un connait la solution,
Merci de m’aider.
Voici mon code :
I used color swatches module and edited the code there
<?php
$productid=Mage::registry('current_product')->getId();
$productyes = Mage::getModel('catalog/product')->load($productid);
$productimagevar= Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'image')->resize(265,265);
?>
<?php
$_option = $this->getOption(); ?>
<ul class="swatches-customoptions-list <?php echo $_option->getTitle(); ?>">
<?php foreach ($_option->getValues() as $value): ?>
<?php
foreach ($productyes->getMediaGalleryImages() as $image) {
$krishna=$this->helper('core')->htmlEscape($value->getSku());
$varibale1img= $image->getLabel();
$variable2img=$image->getUrl();
if($varibale1img)
{
if($krishna==$varibale1img)
{
$atttitle = $_option->getTitle();
$variable3img=$variable2img;
$variable4img=$varibale1img;
}
}
}
?> <?php $imagePath = $this->helper('swatches_customoptions')
->getResizedUrl($value->getImage()) ?>
<li class="swatches-customoptions-list-item">
<a title="<?php echo $this->helper('core')->htmlEscape($value->getTitle())?>”
href="[removed]void(0);" rel="<?php echo $_option->getId() . '_' . $value->getId()?>">
<img src="<?php echo $imagePath ?>”
alt="<?php echo $this->helper('core')->htmlEscape($value->getTitle())?>” onclick=’changeImage("<?php echo $variable3img; ?>","<?php echo $variable4img; ?>","<?php echo $productimagevar; ?>","<?php echo $atttitle; ?>");’/></a>
</li>
<?php endforeach; ?>
</ul>
<?php if(Mage::getStoreConfig('swatches/customoptions/show_text')): ?>
<span id="swatches_state_<?php echo $_option->getId() ?>"> </span>
<?php endif; ?>
In this code
<img src="<?php echo $imagePath ?>”
alt="<?php echo $this->helper('core')->htmlEscape($value->getTitle())?>” onclick=’changeImage("<?php echo $variable3img; ?>","<?php echo $variable4img; ?>","<?php echo $productimagevar; ?>","<?php echo $atttitle; ?>");’/>
on click change image is sending data to php by javascript
<script>
function changeImage(a,b,c,d)
{
jQuery.ajax({
url: “http://192.168.1.94/magento/lhcorporate/test.php”,
data: {"test":a, “test2”:b, “test3”:c,"test4":d},
type: ‘get’,
success: function(output) {
document.getElementById("img").src=output;
}
});
}
</script>
Then to php file by ajax
<?php
$ms = $_GET['test'];
$ms2 = $_GET['test2'];
$ms3 = $_GET['test3'];
$ms4 = $_GET['test4'];
if($ms4=="Embroidary Color")
{
function merge1($ms,$ms2,$ms3,$ms4)
{
$mo= imagecreatefromjpeg($ms);
$im = imagecreatefromjpeg($ms3);
$marge_right = 10;
$marge_bottom = 10;
imagecopymerge($im, $mo, $marge_right, $marge_bottom, 0, 0, imagesx($mo), imagesy($mo), 50);
$imagepath='merge/ '.$ms2.'.png';
imagejpeg($im,$imagepath);
$moo='http://www.wibigroup.com/lecoanethemant/coorporate-shop/merge/'.$ms2.'.png';
imagedestroy($im);
return $moo;
}
echo $imagedone1= merge1($ms,$ms2,$ms3,$ms4);
}
if($ms4=="Fabric Color")
{
function merge1($ms,$ms2,$imagedone1,$ms4)
{
$mo= imagecreatefromjpeg($ms);
$im = imagecreatefromjpeg($ms3);
$marge_right = 10;
$marge_bottom = 10;
imagecopymerge($im, $mo, $marge_right, $marge_bottom, 0, 0, imagesx($mo), imagesy($mo), 50);
$imagepath='merge/'.$ms4.$ms2.'.png';
imagejpeg($im,$imagepath);
$moo='http://www.wibigroup.com/lecoanethemant/coorporate-shop/merge/'.$ms4.$ms2.'.png';
imagedestroy($im);
return $moo;
}
echo merge1($ms,$ms2,$ms3,$ms4);
}
?>
|