Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How To Check If User Purchased An Item On The Product Page Rate Topic   - - - - -

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 20 July 2020 - 11:32 AM #1

how can I check if a buyer purchased an item, I'm trying to show verified purchase on reviews that where left by users who purchased the item.

 

I have tried this but it didn't work

{if $product.users|fn_my_changes_get_product_orders} verified purchase {/if}



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22171 posts

Posted 20 July 2020 - 01:41 PM #2

Try something like

{if $auth.user_id}
    {$params = [
        'user_id' => $auth.user_id,
        'p_ids' => $product.product_id
    ]}
    {$data = $params|fn_get_orders:0:true}
    {if $data.2}
         {$data.2}
    {/if}
{/if}

(!) Not tested


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 21 July 2020 - 04:58 PM #3

Try something like

{if $auth.user_id}
    {$params = [
        'user_id' => $auth.user_id,
        'p_ids' => $product.product_id
    ]}
    {$data = $params|fn_get_orders:0:true}
    {if $data.2}
         {$data.2}
    {/if}
{/if}

(!) Not tested

I tried it but it's not working



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 21 July 2020 - 06:31 PM #4

Create a function in my_changes/func.php like:
 
function my_check_previous_order($product_id, $user_id) {
  if( empty($user_id) || empty($product_id) ) return false;
  return db_get_field("SELECT count(od.product_id) FROM ?:orders AS o LEFT JOIN ?:order_details AS od ON od.order_id=o.order_id AND od.product_id=?i WHERE o.user_id=?i", $product_id, $user_id);
  UNTESTED
}
And then in template:
{assign var="ordered_before" value=$oi.product_id|my_check_previous_order:$auth.user_id}
[if $ordered_before}
  verified order
{/if}
I updated the db_query above to use db_get_field instead.

Edited by tbirnseth, 22 July 2020 - 06:25 PM.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22171 posts

Posted 22 July 2020 - 05:52 AM #5

I tried it but it's not working

 

Do you receive error or empty value?


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 24 July 2020 - 07:41 PM #6

Do you receive error or empty value?


Yes empty value

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 24 July 2020 - 07:43 PM #7

Create a function in my_changes/func.php like:

function my_check_previous_order($product_id, $user_id) {
  if( empty($user_id) || empty($product_id) ) return false;
  return db_get_field("SELECT count(od.product_id) FROM ?:orders AS o LEFT JOIN ?:order_details AS od ON od.order_id=o.order_id AND od.product_id=?i WHERE o.user_id=?i", $product_id, $user_id);
  UNTESTED
}
And then in template:
{assign var="ordered_before" value=$oi.product_id|my_check_previous_order:$auth.user_id}
[if $ordered_before}
  verified order
{/if}
I updated the db_query above to use db_get_field instead.

I tried this it's not showing verified purchase if it's not the user that left the feedback that's logged in, but i need even guests to be able to see the verified purchase

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 24 July 2020 - 09:56 PM #8

how can I check if a buyer purchased an item, I'm trying to show verified purchase on reviews that where left by users who purchased the item.

 

Your requirements are not clear.  You reference 'buyer purchases' and then say you want guests to see.  At this point I have no idea what you want.  If you want further help, you'll have to request a quote via the link in my signature.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 26 July 2020 - 08:54 AM #9

This is what i'm looking to do, on the review page to show verified purchase on reviews from users that bought the item


https://ibb.co/PW8MVtQ[image example]



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22171 posts

Posted 27 July 2020 - 06:03 AM #10

It is not clear how do you want to get purchased items of anonymous customers


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 27 July 2020 - 07:30 PM #11

So what is a "verified purchase" to you? It doesn't really mean anything as text relative to the current user.  If they didn't purchase, what to they care who else purchased but didn't leave a review?


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 26 January 2021 - 08:03 AM #12

Create a function in my_changes/func.php like:
 

function my_check_previous_order($product_id, $user_id) {
  if( empty($user_id) || empty($product_id) ) return false;
  return db_get_field("SELECT count(od.product_id) FROM ?:orders AS o LEFT JOIN ?:order_details AS od ON od.order_id=o.order_id AND od.product_id=?i WHERE o.user_id=?i", $product_id, $user_id);
  UNTESTED
}
And then in template:
{assign var="ordered_before" value=$oi.product_id|my_check_previous_order:$auth.user_id}
[if $ordered_before}
  verified order
{/if}
I updated the db_query above to use db_get_field instead.

 

 

This no longer works



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 26 January 2021 - 06:09 PM #13

I know of no changes that would affect the code I freely provided.  


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 26 January 2021 - 07:38 PM #14

Yeah I'm trying to use this to tell the customer that they have purchased an item before and then give them a link to the order on the product page, e.g you purchased this item <a href="link to the ordered product"></a>



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 27 January 2021 - 04:19 AM #15

Are you trying to reduce duplication and returns?  Or are you just trying to be nice?  If you just want to give them a warning, create a app/addons/my_changes/controllers/frontend/checkout.post.php file and put this content in it.

<?php
  if( !defined('BOOTSTRAP') ) die('Access denied');
  if( $mode == 'add' && ($user_id = $_SESSION['auth']['user_id']) ) { // Only check on add-to-cart for logged in users
    $product_id = $dispatch_extra; // $dispatch_extra should hold the product_id
    if( $product_id) {
      $order_id = db_get_field("SELECT order_id FROM ?:orders AS o
           INNER JOIN ?:order_details AS od ON o.order_id=od.order_id AND od.product_id=?i 
           WHERE o.user_id=?i
           ORDER BY order_id DESC", $product_id, $user_id);
      if( $order_id ) {
        $product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id=?i AND lang_code=?s", $product_id, CART_LANGUAGE);
        $msg = sprintf("You've ordered '$product' before in order ID '$order_id'.  <a href=\"%s\">Click here to view the order</a>.", fn_url("orders.details&amp;order_id=$order_id") );
        fn_set_notification('W', __("warn"), $msg, 'K');
      }
    }
  }
  return array(CONTROLLER_STATUS_OK);
?>

**UNTESTED**

 

If you want to put the '$msg' on a product page instead, just wrap the above in a function tarting where the product_id is assigned and have it return $msg instead of setting the notification If no HIT then return an empty string..  Then your template code would look like (assuming you named this 'function my_purchased_before($product_id)'.

{$purchaed_before={$product.product_id|my_purchased_before}
{if $purchased_before}
  <p>{$purchased_before nofilter}</p>
{/if}

You get the idea....


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 28 January 2021 - 04:13 AM #16

Yes, but I'm trying to show this as a note on the product page not a notification



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12091 posts

Posted 28 January 2021 - 05:25 PM #17

If you can't get from there to where you want to be, then again, suggest you hire a developer to assist you.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 28 January 2021 - 09:19 PM #18

I couldn't even get the alert to work, but thanks



 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 28 January 2021 - 09:45 PM #19

I'm still working on understanding how all this works, hopefully i'd be able to get it to work, if not i can then look to hire someone when i have the funds, I appreciate your help



 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 339 posts

Posted 28 January 2021 - 10:33 PM #20

I managed to get the text to show "you bought this item", please how can i show the <a> hink to the order in the product page?