Hello dear experts! My witchcraft begins for OpenCards 2 and now with this code in the model:

public function getVendorProduct ($vendor_id) { $query = $this->db->query("select vproduct_id from ".DB_PREFIX."vendor where vendor = ".$vendor_id); //$query = $this->db->query("select vendor, product_id, image, price, name from ".DB_RPEFIX."vendor, ".DB_PREFIX."product, ".DB_PREFIX."product_description where ".DB_RPEFIX."vendor.vendor = ".$vendor_id." and ".DB_RPEFIX."product_description.product_id = ".$qqqqq." and ".DB_PREFIX."product.product_id = ".$qqqqq); if ($query) { $count_id = count($query); $vproducts = array(); for ($i=0; $i<$count_id; $i++) { $sql_products_data = $this->db->query("select product_id, image, price, name from ".DB_PREFIX."product, ".DB_PREFIX."product_description where ".DB_PREFIX."product_description.product_id = ".$query['vproduct_id']." and ".DB_PREFIX."product.product_id = ".$query['vproduct_id']); } foreach($sql_products_data as $result) { $vproducts['prod_id'] = $result['product_id']; $vproducts['prod_image'] = $result['image']; $vproducts['prod_price'] = $result['price']; $vproducts['prod_name'] = $result['name']; } return $vproducts; } } 

Next, the controller:

 $vendor_product = $this->model_catalog_vendor->getVendorProduct($vendor_id); $data['products_list_vendor'][] = array(); if($vendor_producys) { foreach ($vendor_products as $result) { $data['products_list_vendor']['vproduct_id'] = $result['prod_id']; $data['products_list_vendor']['vproduct_image'] = $result['prod_image']; $data['products_list_vendor']['vproduct_price'] = $result['prod_price']; $data['products_list_vendor']['vproduct_name'] = $result['prod_name']; } } 

And finally, the very output to the store page:

 <div id="vendor_products"> <?php forech ($products_list_vendor as $products_list) { ?> <p><?php echo $products_list['vproduct_id']; ?></p> <p>- - - - - - - - - -</p> <?php } ?> </div> 

With such a spell, I only get 500 error so far, how to fix the code? Yuzal, did not find the answer

  • Open the error log on the server and see what caused the error. - And
  • Checked and there is no error in the log nor any - privetsh
  • one
    if($vendor_producys) { is this a typo in the controller? - Andrew Hobbit
  • Yes, I definitely noticed, thank you - privetsh
  • Fixed but still error 500 - privetsh

1 answer 1

 for ($i = 0; $i < $count_id; $i++) { $sql_products_data = $this->db->query("select product_id, image, price, name from " . DB_PREFIX . "product, " . DB_PREFIX . "product_description where " . DB_PREFIX . "product_description.product_id = " . $query['vproduct_id'] . " and " . DB_PREFIX . "product.product_id = " . $query['vproduct_id']); } foreach ($sql_products_data as $result) { $vproducts['prod_id'] = $result['product_id']; $vproducts['prod_image'] = $result['image']; $vproducts['prod_price'] = $result['price']; $vproducts['prod_name'] = $result['name']; } 

Logical error. The $sql_products_data constantly overwritten in the for loop. The following foreach result is included in the foreach below.

Perhaps you wanted to write something like this:

 $sql_products_data = array(); for ($i = 0; $i < $count_id; $i++) { $sql_products_data[] = $this->db->query("select product_id, image, price, name from " . DB_PREFIX . "product, " . DB_PREFIX . "product_description where " . DB_PREFIX . "product_description.product_id = " . $query['vproduct_id'] . " and " . DB_PREFIX . "product.product_id = " . $query['vproduct_id']); } foreach ($sql_products_data as $result) { if ($result) { $vproducts['prod_id'] = $result['product_id']; $vproducts['prod_image'] = $result['image']; $vproducts['prod_price'] = $result['price']; $vproducts['prod_name'] = $result['name']; } } 

  if ($vendor_producys) { foreach ($vendor_products as $result) { $data['products_list_vendor']['vproduct_id'] = $result['prod_id']; $data['products_list_vendor']['vproduct_image'] = $result['prod_image']; $data['products_list_vendor']['vproduct_price'] = $result['prod_price']; $data['products_list_vendor']['vproduct_name'] = $result['prod_name']; } } 

In this code, the condition checks the $vendor_producys variable and uses $vendor_products . There is a suspicion of a typo in the first version.


  <div id="vendor_products"> <?php forech($products_list_vendor as $products_list) { ?> <p><?php echo $products_list['vproduct_id']; ?></p> <p>- - - - - - - - - -</p> <?php } ?> </div> 

Estimated reason for the 500th error. A typo in the foreach construct (you have forech ).

  • Error 500 remained. Maybe it's in the cheek request ?? - privetsh
  • @privetsh The question is not all your code. Specifically, this site does not seem to contain an error. - VenZell
  • Maybe not on topic but! Can I make a request for a similar array? - privetsh
  • @privetsh, I did not understand what you want - VenZell
  • In general, I installed a multivendor module on opencard 2, which does not have the ability to display all sellers and their products on the site itself (not the admin panel), it’s not possible to look at the card of any seller and what products he has. I managed to do so that the brief information about the seller was displayed in the product card, which he added, it turned out to make a separate seller page with information about him, now on this page you need to display all of his goods. - privetsh