IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

[Magento] reloadPrice() pour des options personnalisables en jQuery


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Mars 2015
    Messages : 2
    Points : 2
    Points
    2
    Par défaut [Magento] reloadPrice() pour des options personnalisables en jQuery
    Bonjour tous,

    J'ai un souci avec utilisé avec jQuery qui n'actutalise pas le panier. Je pars d'un produit configurable avec des options personnalisables. Normalement, sans jQuery, le code d'un SELECT avec option est le suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <select id="select_281" class=" required-entry product-custom-option" title="" name="options[281]" onchange="opConfig.reloadPrice()">
    <option value="0"></option>
    <option rel="1" price="0" value="275"></option>
    <option rel="2" price="0" value="276"></option>
    </select>
    Avec jQuery je gèle le (pris en charge par Prototype) tout en donnant mon propre prix de l'option de 50 euros :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    jQuery('#select_281').removeAttr('onchange').change(function(){
     
    //Calcul du prix
    price = 50;
     
    optionsPrice.changePrice('opConfig', price);
    optionsPrice.reload();
     
    });

    Le prix de mon produit au départ :150 euros
    En choisissant l'option : on ajoute 50 euros
    Le nouveau prix de 200 euros s'affiche bien sur la page produit, mais pas sur le panier qui continue d'afficher 150 euros.

    Deuxième question : quelqu'un a une idée sur comment afficher sur le panier une ligne pour le prix normal, puis une ligne pour le prix des options.


    COM

  2. #2
    Candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Mars 2015
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Résolu avec deux observers
    Hi,

    The reloadPrice() cant change any price serverside.
    So we solved this issue by using 2 observers :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    checkout_cart_product_add_after
    observer to change the price the first time the product is added to the cart, and
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    checkout_cart_update_items_after
    observer to change the price for each item in the cart (when user click the "Modify cart" button on cart page).

    The code here. Code tested for configurable products with 2 custom options numberOfColors and engravingType. For each couple numberOfColors/engravingType we have tierprices stored in special MySQL table, we may change price with a custom price. Each simple product has its tierPrices.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    //checkout_cart_product_add_after observer
       public function modifyPrice(Varien_Event_Observer $observer)
        {
    		$item = $observer->getQuoteItem();
    		$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
    		$productType = $product->getTypeID();
    		$price = 100;//Unit price of product without engraving, 100 for example
     
    		//Unit price with engraving, depending of 2 custom options of configurable product
    		if($productType == 'configurable'){
    			//get custom options of config here
    			.
    			.
    			$engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
    			$finalUnitPrice = $price + $engravingPrice;//Final custom price
     
    			//Modify the price
    			$item->setCustomPrice($finalUnitPrice);
    			$item->setOriginalCustomPrice($finalUnitPrice);
    			$item->getProduct()->setIsSuperMode(true);
    		}
        }
     
    	//checkout_cart_update_items_after observer
    	public function modifyCartItems(Varien_Event_Observer $observer)
        {
    		foreach ($observer->getCart()->getQuote()->getAllVisibleItems() as $item ) {
    			if ($item->getParentItem()) {$item = $item->getParentItem();}
    			$productType = $product->getTypeID();
    			$productType = $product->getTypeID();
    			$price = 100;//Unit price of product without engraving
     
    			//Unit price with engraving, depending of 2 custom options of configurable product
    			if($productType == 'configurable'){
    				.
    				.
    				$engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
    				$finalUnitPrice = $price + $engravingPrice;//Final custom price
     
    				//Modify the price for the item
    				$item->setCustomPrice($finalUnitPrice);
    				$item->setOriginalCustomPrice($finalUnitPrice);
    				$item->getProduct()->setIsSuperMode(true);
    			}
    		}
        }
    But.....one problem remains : on the cart page, when user clicks the link "Edit" to edit the product in product page so he can change quantity, ...and click the "Update cart" button, this update button does not read the checkout_cart_product_add_after to refresh price.

    Dont't know how to force this "Update cart" action to process the code in checkout_cart_product_add_after observer? Is this code executed just the first time the product is added to the cart?

    Thanks.

    Tokey

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Enumerate, tikz pour des listes personnalisées
    Par olivier_1970 dans le forum Mise en forme
    Réponses: 2
    Dernier message: 01/07/2015, 22h15
  2. Réponses: 0
    Dernier message: 03/11/2007, 09h52
  3. disparition des options pour les fichiers cachés
    Par ph4prod dans le forum Windows XP
    Réponses: 8
    Dernier message: 07/08/2007, 02h28
  4. [PHP-JS] Personnalisation des options d'affichage
    Par cirtey dans le forum Langage
    Réponses: 3
    Dernier message: 14/12/2006, 17h35
  5. Composant pour éditer des options
    Par Patrick Seuret dans le forum C++Builder
    Réponses: 1
    Dernier message: 13/09/2006, 13h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo