Unique code in last price product number

Discussion in 'Payment Systems' started by williambangwill, Jul 7, 2017.

  1. williambangwill

    williambangwill New Member

    Joined:
    Jul 7, 2017
    Messages:
    2
    hi guys,
    how to make unique code in price product
    for example,
    my product price is $ 400

    if buyer click my product, the invoice total calculate is $ 401
    and if other buyer click buy again, the invoice total calculate is $ 402
    and more

    so how to add automatic unique code number in last price product ?

    at all, thanks alot
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    I am afraid it is not possible by default but I believe it is possible to implement
    custom plugin to accomplish such feature.

    Do you mind to contact us in helpdesk?
    https://www.amember.com/support

    We will help you with it.

    Best Regards.
  3. masdika

    masdika --

    Joined:
    Oct 6, 2013
    Messages:
    18
    Hai, insert this code in file site.php

    http://www.amember.com/docs/Site.php_file

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_CALCULATE, function(Am_Event $e) {
       if (@
    $GLOBALS['add_fraction']++) return;
       
    $invoice $e->getInvoice();
       
    $item $invoice->getItem(0);
       
    $id $invoice->pk() ?: $e->getDi()->db->selectCell("SELECT MAX(invoice_id)+1 FROM ?_invoice;");
       if (
    $item && !$item->data()->get('add_fraction')) {
           
    $item->data()->set('add_fraction'1);
           
    $item->data()->set('orig_first_price'$item->data()->get('orig_first_price') + ($id 100));
           
    $invoice->calculate();
       }
       unset(
    $GLOBALS['add_fraction']);
    });
    akuraid and caesar like this.
  4. williambangwill

    williambangwill New Member

    Joined:
    Jul 7, 2017
    Messages:
    2
    makasih @masdika untuk jawabannya.
    lalu cara me reset agar unik kode kembali ke nol lagi gimana ya mas.

    itukan nnti kalo ada 10.000 orang yg regist di amember saya, otomatis harga produk nambah Rp 10.000,-
    buyer jadi mikir 2x buat beli produk saya entar :D
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    This code automatically reset it to 0 after 100 order. Please note this code:
    PHP:
    $id 100
    result of this operation is always between 0 and 99
  6. masdika

    masdika --

    Joined:
    Oct 6, 2013
    Messages:
    18
    Itu sudah di jelaskan oleh Uncle@caesar :D

    Kalau mau diskusi bisa add facebook saya facebook.com/masdikacom om @williambangwill
  7. akuraid

    akuraid Member

    Joined:
    Jan 16, 2018
    Messages:
    34
    @masdika this code still generate value for free product.
    How to make it still free?

    maturnuwun
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @akuraid You need to replace code
    PHP:
    if ($item && !$item->data()->get('add_fraction')) {
    with
    PHP:
    if ($item && $item->first_price && !$item->data()->get('add_fraction')) {
    It should do the job.

Share This Page