You are here:  » Niche Mode - creating a shadow products_all table

Active Forum Topics


Niche Mode - creating a shadow products_all table

Submitted by support on Tue, 2017-10-31 11:20 in

Hi All,

Niche Mode enables the import to be restricted to only those product names configured in Product Mapping or derived from a Product Mapping By RegExp rule. This means however that once enabled, admin tools that query the products table only have visibility of the imported products.

To create a shadow `products_all` table that can be used by the admin search functions and Imported Analysis, first create and run the following dbmod.php from the top level of your Price Tapestry installation:

<?php
  
require("includes/common.php");
  
$sql "CREATE TABLE `".$config_databaseTablePrefix."products_all` LIKE `".$config_databaseTablePrefix."products`";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next, edit includes/admin.php and look for the following code beginning at line 451:

    /* niche mode */
    if ($config_nicheMode)
    {
      if (
         !in_array($importRecord["name"],$admin_importProductMappings)
         &&
         !$regexpMapped
         )
         return;
    }

...and REPLACE with:

    /* niche mode */
    if ($config_nicheMode)
    {
      $nicheModeImport = (
         in_array($importRecord["name"],$admin_importProductMappings)
         ||
         $regexpMapped
         );
    }
    else
    {
      $nicheModeImport = TRUE;
    }

And then the following code at line 523:

    if (database_queryModify($sql,$insertId))
    {
      $admin_importProductCount++;
    }

...and REPLACE with:

    if ($nicheModeImport)
    {
      database_queryModify($sql,$insertId);
    }
    $sql = str_replace("`".$config_databaseTablePrefix.$table."`","`".$config_databaseTablePrefix."products_all`",$sql);
    if (database_queryModify($sql,$insertId))
    {
      $admin_importProductCount++;
    }

And finally the following code at line 738:

    $admin_importProductCount = 0;

...and REPLACE with:

    $sql = "DELETE FROM `".$config_databaseTablePrefix."products_all` WHERE filename='".database_safe($admin_importFeed["filename"])."'";
    database_queryModify($sql,$insertId);
    $admin_importProductCount = 0;

Edit admin/helper.php and look for the following code at line 22:

    $sql = "SELECT DISTINCT(".$field.") FROM `".$config_databaseTablePrefix."products` WHERE ".$field." LIKE '%".database_safe($q)."%' ORDER BY ".$field." LIMIT 6";

...and REPLACE with:

    $sql = "SELECT DISTINCT(".$field.") FROM `".$config_databaseTablePrefix."products_all` WHERE ".$field." LIKE '%".database_safe($q)."%' ORDER BY ".$field." LIMIT 6";

Edit admin/feeds_utils_imported.php and use your text editor's Search and Replace function to search:

`".$config_databaseTablePrefix."products`

...and REPLACE with:

`".$config_databaseTablePrefix."products_all`

(4 instances, lines 98/194/229/307)

With that in place; following the next full import, admin search functions and Imported Analysis will then have visibility of all products.

Cheers,
David
--
PriceTapestry.com