You are here:  » Add admin product + Regexp


Add admin product + Regexp

Submitted by Csaba on Mon, 2015-04-27 10:53 in

Hi David!

I would like to request for help to make this idea come true.

I would like to expand the "Admin" page with a new option. It should be the "Add product".
Here anyone could create a new product with the necessary data: name, description, image url, category, etc. The merchant name of it could be the "Administration".
There would be a new record too, named Regexp, in the Product table.

If I view this product on the page, then the suitable matches for Regexp would be shown, sorted by price at the bottom of the product page, just like for example testing the Product Mapping RegExp.

Thanks in advance.

Best regards
Csaba

Submitted by support on Mon, 2015-04-27 12:08

Hello Csaba and welcome to the forum!

A manual product addition by admin tool could be a candidate for an "Extension" as supported by the new Admin area in 15/01A however in the mean time, it is straight forward to add products manually by managing your own feed.

First of all however, add a new "regexp" field to your site by following the standard instructions in this thread.

With that in place, a spreadsheet program such as Microsoft Excel or OpenOffice.org Sheet (Free) is the easiest way to manage your own products. Create columns headings in row A, Merchant, ProductName, Price, BuyURL, ImageURL, Description, Category, Brand and RegExp and then enter the product information one product per row (only ProductName, BuyURL and Price are required).

The default settings of the Export function of both Microsoft Excel and OpenOffice.org Calc will create a .csv file that is compatible with Price Tapestry. Upload this to the /feeds/ folder of your installation and register / import as normal.

With that in place, it's straight forward to pull up all other products matching the custom `regexp` field in your installation, and the results can be displayed using the built-in html/prices.php module. To do this, edit products.php and look for the following code at line 158:

  if (isset($related)) require("html/related.php");

...and REPLACE with:

  if (isset($related)) require("html/related.php");
  if ($product["products"][0]["regexp"])
  {
    $regexp = $product["products"][0]["regexp"];
    $ins = array();
    $link = mysqli_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword,$config_databaseName);
    mysqli_set_charset($link,"utf8");
    $sql = "SELECT DISTINCT(name) FROM `".$config_databaseTablePrefix."products`";
    mysqli_real_query($link,$sql);
    $result = mysqli_use_result($link);
    while($row = mysqli_fetch_assoc($result))
    {
      preg_match($regexp,$row["name"],$matches);
      if (count($matches))
      {
        $ins[] = "'".database_safe($row["name"])."'";
      }
    }
    $in = implode(",",$ins);
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") ORDER BY price";
    database_querySelect($sql,$rows);
    $prices["products"] = $rows;
    require("html/prices.php");
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com