Nenex Posted September 8, 2009 Share Posted September 8, 2009 BonjourEn référence à mon précédent message:http://www.prestashop.com/forums/viewthread/27403/developpement_et_modules/id_dattribue_incorrecteJ'ouvre un nouveau fil pour comprendre comment PS se débrouille sans Javascript, et notamment lors de l'ajout d'un produit décliné au panier. Jusqu'à maintenant j'ai constaté qu'il se servait du paramètre POST "id_product_attribute" ou "ipa" qui est unique et découle de la combinaison des attributs sélectionnés dans la page produit. Mais cette combinaison est effectuée en Javascript!De plus, il semblerait que la page cart.php s'attende à recevoir cet "ipa" combiné et non une liste, donc il laisse tout le boulot à Javascript. Ok mais alors sans Javascript, comment dois-je procéder ?Merci Link to comment Share on other sites More sharing options...
Nenex Posted September 8, 2009 Author Share Posted September 8, 2009 Je pensais bien que ça n'intéresserait personne mais bon,voici quand même ce que j'ai fait pour résoudre le problème.Attribute.php /** * Get a product attribute combination id from an array of attributes * * @param array $id_attributes Attribute IDs * @return integer ID for the product attribute if there is a match, 0 instead */ static public function getProductCombinationId($id_attributes) { $where = array(); $count = array(); $index = 0; $limit = 0; foreach($id_attributes AS $groupId => $attributeId) { array_push($where, '`id_attribute` = '.$attributeId); } $result = Db::getInstance()->ExecuteS(' SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE '.implode(' OR ', $where)); foreach($result AS $row) { array_push($count, intval($row['id_product_attribute'])); } foreach(array_count_values($count) AS $i => $found) { if($limit < $found) { $index = $i; $limit = $found; } } return $limit > count($id_attributes) - 1 ? $index: 0; } Cart.php //get the values $idProduct = intval(Tools::getValue('id_product', NULL)); $idProductAttribute = /* ##### ##### intval( */Attribute::getProductCombinationId(/* ##### ##### */Tools::getValue('id_product_attribute', Tools::getValue('ipa'))); $customizationId = intval(Tools::getValue('id_customization', 0)); $qty = intval(abs(Tools::getValue('qty', 1))); if ($qty == 0) $errors[] = Tools::displayError('null quantity'); elseif (!$idProduct) $errors[] = Tools::displayError('product not found'); else { $producToAdd = new Product(intval($idProduct), false, intval($cookie->id_lang)); if ((!$producToAdd->id OR !$producToAdd->active /* ##### ##### */OR !$idProductAttribute/* ##### ##### */) AND !$delete) Et faire en sorte que le template de product.php produise des noms correctes pour les , de telle sorte qu'un array soit passé en paramètre: Taille : 34 - 60cm 34 - 65cm Couleur : Blanc Noir Écru Voici donc comment faire pour pouvoir désactiver javascript tout en gardant ce système de groupe. J'suis pas très fan mais ça fonctionne, d'autant plus qu'au moindre update... Enfin bon, pour mes besoins ça ira. Link to comment Share on other sites More sharing options...
Tropical Dream Posted September 8, 2009 Share Posted September 8, 2009 c'est pour permettre d'ajouter des produits dans le panier sans utiliser javascript? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now