You are here:  » Size aggregation


Size aggregation

Submitted by marco on Sat, 2015-09-26 08:55 in

Hello,

It may have been covered before but I could not find it, so here is my question:
When it comes to sizes there are basically two types of data feeds from clothing shops:
1. The item has one record with all the available sizes, for example: ’S, M, L, XL, XXL’.
2. The item has different records for each size field (with the same item title/name).
Is it possible to import type 2 data feeds so all the available sizes with be aggregated into one record like type 1 data feeds (13/03A)?

Best Regards,
Marco

Submitted by support on Sat, 2015-09-26 11:25

Hi Marco,

This could be hard coded in to the import process reasonably easily - if the INSERT fails due to the de-duplication a second query can then be made to append the size value of the current record to the end of the already inserted record, separated by comma, resulting in the same format size field as type 1 feeds.

To give this a go, edit includes/admin.php and look for the following code at line 400:

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

...and REPLACE with:

    if (database_queryModify($sql,$insertId))
    {
      $admin_importProductCount++;
    }
    else
    {
      $type2feeds = array("Merchant1.xml","Merchant2.xml");
      if (in_array($admin_importFeed["filename"],$type2feeds))
      {
        $sql = "UPDATE `".$config_databaseTablePrefix.$table."` SET
                  size = CONCAT(size,',',database_safe($importRecord["size"]))
                         WHERE dupe_hash = '".$dupe_hash."'";
        database_queryModify($sql,$insertId);
      }
    }

Edit the $type2feeds array to contain the list of feeds to process in this way, and that should do the trick...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco on Mon, 2017-01-09 16:29

Hi David,

Sorry for my late response on this thread, but have not been able to get this to work yet.
I think it might be because of the timestamp mod implemented (node/3291).
Could that need another solution?

Best,
Marco

Submitted by support on Tue, 2017-01-10 09:26

Hi Marco,

Would simply adding a Text After filter to the Product Name field for type 2 feeds do the trick? The Text After filter supports placeholders, so you would add, for example;

" %size%"

- without the quotes, but notice the leading SPACE which is important otherwise there would be no space between the product name and the sizes. The field name, size in this case, is exactly as it appears in the product record as seen in the sample data below the form on Feed Registration Step 2...

Apologies if mis-understood, let me know if that's not going to be suitable and what additional processing you think is required and it should be able to be worked around the timestamp mod already in place...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco on Tue, 2017-01-10 10:35

Hi David,

That would give five records of the same product.
I would like to have one, but with the available sizes displayed, like type 1 feeds.

Since the timestamp mod changed the import process, I think the latest ‘else’ in the code below is never triggered?

    global $now;
    if (!$now)
    {
      $now = time();
    }
    $sql .= ",deleteme='0'";
    $sql2 = "SELECT id FROM `".$config_databaseTablePrefix.$table."`
               WHERE original_name='".database_safe($importRecord["original_name"])."' AND filename='".database_safe($admin_importFeed["filename"])."'
               LIMIT 1";
    if (database_querySelect($sql2,$result))
    {
      $search = "INSERT INTO `".$config_databaseTablePrefix.$table."`";
      $replace = "UPDATE `".$config_databaseTablePrefix.$table."`";
      $sql = str_replace($search,$replace,$sql);
      $sql .= " WHERE original_name='".database_safe($importRecord["original_name"])."' AND filename='".database_safe($admin_importFeed["filename"])."'";
    }
    else
    {
      $sql .= ",timestamp='".$now."'";
    }
    if (database_queryModify($sql,$insertId))
    {
      $admin_importProductCount++;
    }
    else
    {
      $type2feeds = array("Merchant1.xml","Merchant2.xml");
      if (in_array($admin_importFeed["filename"],$type2feeds))
      {
        $sql = "UPDATE `".$config_databaseTablePrefix.$table."` SET
                  size = CONCAT(size,',','".databasesafe($importRecord["size"])."')
                   WHERE original_name='".database_safe($importRecord["original_name"])."' AND filename='".database_safe($admin_importFeed["filename"])."'";
        database_queryModify($sql,$insertId);
      }
    }

Best,
Marco

Submitted by support on Wed, 2017-01-11 11:17

Hi Marco,

I think it would be easier to check for and re-create the product name prior to the insert / update code - please could you email me the modified includes/admin.php from this installation and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com