You are here:  » Import Only If Sale Price Exists?


Import Only If Sale Price Exists?

Submitted by ItsDavid on Fri, 2017-10-20 19:30 in

Hi David,

As you know i deal with very large data feeds 200k products or more per feed. I was wondering if there was a way to setup PT to only import products that have a sale price present?

So in order for PT to import the product from the feed there would have to be a "Retail Price" and "Sale Price" Present. The would reduce the amount of products that get imported and leave me with only products that have a sale price.

I am also using the Asynchronous Amazon / eBay API Modules on my product pages if that makes a difference.

What i would like to do is not only import sale price items but also display on the product page Retail Price = 2.00 Sale Price = 1.00 Savings = 50% with the retail price being struck out with a line through it.

Best Regards
David

Submitted by support on Sat, 2017-10-21 09:04

Hi David,

See this thread for the addition of rrp and discount fields (with discount optionally imported from a mapped field or calculated otherwise) and if you wish to include it, the option to sort by discount. After applying the mods, edit includes/admin.php and where you now have the following code beginning at line 465:

  /* decimalise price */
  $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
  $importRecord["discount"] = tapestry_decimalise($importRecord["discount"]);
  $importRecord["rrp"] = tapestry_decimalise($importRecord["rrp"]);
  if (($importRecord["discount"]=="0.00") && ($importRecord["rrp"] != "0.00"))
  {
    $discount = ((1 - ($importRecord["price"]/$importRecord["rrp"])) * 100);
    $importRecord["discount"] = tapestry_decimalise($discount);
  }

...REPLACE with:

  /* decimalise price */
  $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
  $importRecord["discount"] = tapestry_decimalise($importRecord["discount"]);
  $importRecord["rrp"] = tapestry_decimalise($importRecord["rrp"]);
  if (($importRecord["discount"]=="0.00") && ($importRecord["rrp"] != "0.00"))
  {
    $discount = ((1 - ($importRecord["price"]/$importRecord["rrp"])) * 100);
    $importRecord["discount"] = tapestry_decimalise($discount);
  }
  if ($importRecord["discount"]=="0.00") return;

With that new last line of the replacement only discounted products will be imported. Finally, to show rrp struck out, price and discount, edit html/prices.php and look for the following code at line 59:

  <td class='pt_pr_price'><?php print tapestry_price($product["price"]); ?></td>

...and REPLACE with, for example:

  <td class='pt_pr_price'>
    <s><?php print tapestry_price($product["rrp"]); ?></s>
    <br />
    <?php print tapestry_price($product["price"]); ?>
    <br />
    Save <?php print $product["discount"]; ?>%
  </td>

If you'd prefer to round the discount; use:

Save <?php print intval($product["discount"]); ?>%

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ItsDavid on Sun, 2017-10-22 05:18

Hi David,

This is working as expected, however, I am facing one problem. Some products in the feed have the same price amount in both the "Sale Price" and "Retail Price".

So it looks like this,

Sale Price: 19.99

Retail Price 19.99

How can I also skip (not Import) these products if the price in both fields is the same?

Best Regards
David

Submitted by support on Sun, 2017-10-22 10:00

Hi David,

If price and rrp are the same then $importRecord["discount"] should come out as 0.00 - could you check that the additional last line of the modification to incldus/admin.php described above is in place:

   if ($importRecord["discount"]=="0.00") return;

If all in place but still importing equal price / rrp let me know and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by ItsDavid on Sun, 2017-10-22 12:34

That seems to have done the trick!

I have one other question, it appears that when using the Asynchronous Amazon / eBay API Foundation Modules the code in html/prices.php is different and it also incorporates html/prices_table.php. Are the modification steps the same when using Asynchronous Amazon / eBay API Foundation Modules?

Best Regards
David

Submitted by ItsDavid on Sun, 2017-10-22 16:22

Hi David,

This modification is working great, however, i think it would be better if there was a way to produce a cleaner "Save XX%" value.

I am seeing values such as

$1150.00 $6555.00 Save 470%

and

$2.12 $395.99 Save 18578%

$3800.00 $17369.00 Save 357%

I would like to keep the savings % between 1-100.

Is this possible?

Best Regards
David

Submitted by support on Mon, 2017-10-23 11:20

Hello David,

Using the Async API modules, the display modification needs to be applied to the new html/prices_table.php file, and only in the case of datafeed results which can be identified by the $prices["api"] variable being set. So in that file, look for the following code at line 82:

  <td class='pt_pr_price'><?php print (function_exists("tapestry_price")?tapestry_price($product["price"]):$config_currencyHTML.$product["price"]); ?></td>

...and REPLACE with:

  <?php if (isset($prices["api"])): ?>
  <td class='pt_pr_price'><?php print (function_exists("tapestry_price")?tapestry_price($product["price"]):$config_currencyHTML.$product["price"]); ?></td>
  <?php else: ?>
  <td class='pt_pr_price'>
    <s><?php print tapestry_price($product["rrp"]); ?></s>
    <br />
    <?php print tapestry_price($product["price"]); ?>
    <br />
    Save <?php print intval($product["discount"]); ?>%
  </td>
  <?php endif; ?>

(using intval() for the percentage display as it looks like you are using that based on the output copied in your last post above)

On the subject of > 100% discounts, this will happen if price > rrp (tapestry_decimalise() will make positive a negative value). Double check that the feed has been registered correctly - if the price and rrp fields were swapped that would have this effect, but if that's all good then you can remove these records (assuming you want to) then you could change the drop condition to ensure discount is not 0.00 and not > 100.00 - so where you have the following code at the end of the modification described above:

   if ($importRecord["discount"]=="0.00") return;

...REPLACE with:

   if (($importRecord["discount"]=="0.00") || (intval($importRecord["discount"])>100)) return;

Cheers,
David.
--
PriceTapestry.com

Submitted by ItsDavid on Tue, 2017-10-24 03:07

Hi David,

I have added the changes and also double checked that, the fields were correct and I am still getting products with prices showing up as 0.00 have a look at the following URL {link saved}

Best Regards
David

Submitted by support on Tue, 2017-10-24 09:18

Hi David,

In this case the price value of 0.00 must be coming in from the feed. It may be the situation that for this particular feed a price value of 0.00 means not on sale and the rrp would be in effect for that product (if it were empty the record would have been dropped by the minimum required fields check) however since you are only interested in products on sale, assuming that you are happy for products with 0.00 price to be dropped then in addition to the discount range check in your modifications to includes/admin.php simply add a check for price is not equal to "0.00", so where you currently have:

   if (($importRecord["discount"]=="0.00") || (intval($importRecord["discount"])>100)) return;

...REPLACE with:

   if (($importRecord["price"]=="0.00") || ($importRecord["discount"]=="0.00") || (intval($importRecord["discount"])>100)) return;

That should cover all bases...

Cheers,
David.
--
PriceTapestry.com