简体   繁体   中英

Compare products in Virtuemart

I am doing compare page in virtuemart. I want to modify joomla\\components\\com_virtuemart\\views\\category\\tmpl\\default.php file in this way:

<?php

include ("/includes/compare.php");

$con=mysqli_connect("localhost","root","","auto2");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM auto_virtuemart_products");
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">Value1</font>
</td>
</tr>

<?php
while($row = mysqli_fetch_array($result)) {
?>

<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $row['product_sku']; ?></font>
</td>
<td>
<form action="compare.php" method="get">
<input type="checkbox" name="send1[]" value="<?php echo $row?>" />

</td>
</tr>

<?php
}
mysqli_close($con);
?>

And then I add compare.php to includes folder:

 <?php
   $con=mysqli_connect("localhost","root","","auto2");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

  if ( isset($_GET['send1']) ) {
        $compare1 = $_GET['send1'];


 if (isset($_GET['Submit'])) {
   for ($i=0; $i<sizeof($compare1);$i++) {

   $result = mysqli_query($con,"SELECT * FROM auto_virtuemart_products WHERE '$compare1[$i]' LIKE product_sku");

   while($row = mysqli_fetch_array($result))
  {
  echo $row['product_sku'] . " " . $row['product_weight'];
  echo "<br>";
  }

   }
    }
    else {
    echo ("error");
    }
    }
   ?>

Everything is functional, but when I click on button Submit the next error is occured:

An error has occurred. The requested page cannot be found.

404 Article not found

I expect that problem is, that joomla will not show another page if it is not defined as article.

Please do not solve security issues, I know about them and I will solve them later. Now I have it launched just on localhost.

Please could you advice me, how can I solve this problem?

Thank you very much

Why you are using external page and submit like normal forms.

Joomla & VM are MVC so use that features. Also do not use mysql functions like this, use Joomla DB object.

I think you can work like this way,

The compare product is VM related option so create a view inside your VM component(Assume VM2.x) Just create related controller and model for your new view.

the view have facility to add new layout so your compare form should be layout.

and your form have something like below. on your form action

index.php?option=com_virtuemart&controller=yourcontroller&task=yourtask

the task is the function inside your controller.

this can be include like below method (insted of using form action).

<input type="hidden" value="com_virtuemart" name="option">
<input type="hidden" value="yourcontroller.yourtask" name="task">.

Also in your model you can use DB object like below.

$db = JFactory::getDBO();
$sql= "your sql query";
$db->setQuery($sql);
$db->query();//This may changed based on Joomla versions.

Hope its helps.. try to follow Joomla and VM standard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM