Jump to content

steph3838

Members
  • Posts

    14
  • Joined

  • Last visited

Everything posted by steph3838

  1. I've tried it this way : $match_product2 = array(3,4,5,6,7,12); $match_product1 = array(9,10,11) $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product) { if (in_array($product->product_id, $match_product1)) { foreach($cart->products as $product) { if (in_array($product->product_id, $match_product2)) { return true; break 2; } } } } returning a state, but have still an error... Have to say that at this point I am lost... thanks for your help and advise, best regards, Steph
  2. I have changed the $result = 'OK'; to $result = true; in order to have a boolean variable... but apparently it is not right what I am doing... Am I wrong in declaring this way ? Thanks for your help and advise, best regards, steph
  3. Ok understand it... but I will try it later on when I have more time to spend on it. again thanks for your help ! Regards Steph
  4. Another question : you define a variable $result. this variable can store string elements. I do need a true or false state. If I declare the $result variable as this : $result = false; I should have a boolean variable no ? Thanks in advance for your help and advise, regards, Steph
  5. Many thanks Barand !! I understand my error. But i'd like to learn a bit more... how could we "shorten" it ? If you don't mind, could you please explain me ? Thanks in advance for the time spended on my queries, Best regards Steph
  6. Thanks Barand ! two points : return : you're right... How can I set a function in order to select from $cart the product and then the product_id ? I have not understood the "function logic" apparently... It is more logical to me with the foreach... the code could then be : $match_product2 = array(3,4,5,6,7,12); $match_product1 = array(9,10,11) $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if (in_array($product->product_id, $match_product2)) { if (in_array($product->product_id, $match_product1)) } return false; } If I keep the foreach... I have problems to understand the true or false statement : Normaly a true state is declared after an if and a false after an else (or reverse depending on the logic used) If I try to have describe what I have, it would be : if (in_array($product->product_id, $match_product2)) { (true state of first if if (in_array($product->product_id, $match_product1)) { (here we create the AND logic for the two tests) return true; (true state of the second if) } } else { return false; (false state of first if) } Am I right ? or what do I miss ? Thanks in advance for your help and advise, Best regards, Steph
  7. could this be the right code then ? $match_product1 = array(9,10,11) $match_product2 = array(3,4,5,6,7,12); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if (array_intersect($product->product_id, $match_product1)) { return (array_intersect($product->product_id, $match_product2)) } return false; } Thanks in advance for your help and advise, Best regards, Stéphane
  8. Many thanks Barand ! I like your pseudocode explaination, I understood right away what you're doing ! Great, I will try to convert, it into PHP with my givens and let you know if I have some problems Again thanks for your help ! Best regards Stéphane
  9. My PHP knwoledge is, as said, very low. But if I understand right what you are writting You set 2 groups (arrays ?) and comparre if the cart content is in those groups. but then you are using an unknown function to me array_intersect, but what I could read about it is that it compares the two arrays $prods and $g1 , but then I am lost with the rest... what I need is that the cart has to contain a product from $group1 AND $group2 in order to deliver a true state for anything eslse the false state has to be delivered. Many thanks in advance for your help and advise, Best regards Steph
  10. You know dear Benanamen, I am teaching on other subject for about 30+ years, and a good teacher is the one who can place itself at the same level than it's students... I cannot explain again a whole week of discussion between me and 2 other devloppers just to answer your XY question... Teaching = helping people is fisrt set yourself at their level and not reverse. As said my question is just a syntaxic question not a logical question, you beleve it or not is not the point. But as you said give up if you want, I do not force anybody, but hope you will think about my statments... I am not upset at all, just not surprised by your answer. have a nice evening, Steph
  11. Global code would be : $match_products = array(9,10,11); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_products)) return $result = false; } return $result = true; } //test2 $match_product1 = array(3,4,5,6,7,12); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_product1)) return $result1 = false; } return $result1 = true; } //test1 AND 2 if ($result = true && $result1 = true); { return true; } else { return false; } test 1 like this works : $match_products = array(9,10,11); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_products)) { return true; } return false; } test 2 like this works : $match_product1 = array(3,4,5,6,7,12); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_product1)) { return true; } return false; } But when combined in the same code I do not know if the syntax is right or not (have I missed a ; , a } etc... maybe I should not put a return before the $result1 = true etc.) that's my question Thanks in advance for your help, Best regards Steph
  12. Dear Benanamen, What I am trying to accomplish, and believe me, the logic of it is the right one, is to combine the result of two tests having as result true or false in one global true/false result where (test1=true AND test2=true) leads to a global=true else global=false. But where I really need help is in the PHP syntax in which I am really not comfident and where I lak of experience and knowledge. Setting up the right test took about a week with Hikashop and Regularlabs people. So please consider the logical point of my question solved. The global test should be better this way : Missing in the syntax are also closing } for each test1 and test2... //test1 AND 2 if ($result = true && $result1 = true) { return true; } else { return false; } thanks for your help and advise best regards Steph
  13. I tought about this code to combine the two tests : //test 1 $match_products = array(9,10,11); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_products)) return $result = false; } return $result = true; //test2 $match_product1 = array(3,4,5,6,7,12); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_product1)) return $result1 = false; } return $result1 = true; //test1 AND 2 if ($result = true && $result1 = true); return true; return false; but I am really not sure about it As said the aim of it is to test if products (by their id - 9,10,11) are within an array. But the customer has to add a product in step one into the basket that's tested by the //test1 and working. Now on step 2 the customer has to add a second product from within the second array (ids 3,4,5,6,7,12) In order to be sure the customer hasn't removed a product from step one I have to check again both arrays and both have to be true. I use this PHP with the Joomla! extention ReReplacer from RegularLabs. For this extension I need a global true or false state I don't know if it is more clear now. Thanks for your help and advise, Best regards Steph
  14. Hi, I am totaly new to PHP. I do need to test the availability of a product in a basket via an array of the product ids. This code works : $match_products = array(9,10,11); $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); foreach($cart->products as $product){ if(in_array($product->product_id, $match_products)) { return true; } return false; } but I need to test 2 differents array and have to be sure that both of them are true in order to get a global true value, for all other situations I need a false global value. Second array would be array(3,4,5,6,7,12). the logical shema would be test1 = product in array1 : true/false test2 = product in array 2 : true/false Global test : test1=true AND test2=true than global=true else global=false How can I do this ? Maybe my question is a bit silly for some of you, sorry about that, but as said, my PHP knowledge is very limited. Thanks in advance for your help and advise, Best regards Steph
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.