Problems, need help? Have a tip or advice? Post it here.
17 posts Page 1 of 2
Okay so following on from my products, i've came up with the idea to display a total amount of products people have.

So lets say user seller has 50 products and buyer comes along and buys 50 of them through paypal, how can i get the if tag to count that and END the item

So at the moment i'm getting the seller to imput the total amount he has in stock. the editable would be

stock_amount

if the stock = 50 but sells 50 =0 and ends the item to stop buyers buying more. So this would stop any issues where lets say someone advertises a item but only has one of them, and then once its sold it'll end the item and stop others trying to buy it.

The code i've got is this code for the buy it button to paypal

Code: Select all
         <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                        <input type="hidden" name="cmd" value="_xclick"/>
                        <input type="hidden" name="business" value="<cms:show pp_email />"/>
                        <input type="hidden" name="item_name" value="<cms:show k_page_title />"/>
                        <input type="hidden" name="item_number" value="<cms:show k_page_id />"/>
                        <input type="hidden" name="amount" value="<cms:number_format pp_price />"/>
                        <input type="hidden" name="undefined_quantity" value="1"/>
                        <input type="hidden" name="item_address" value="No Street, Calverton, Nottingham, BG14"/>
                        <input type="hidden" name="show_shipping" value="1"/>
                        <input type="hidden" name="no_note" value="1"/>
                        <input type="hidden" name="currency_code" value="GBP"/>
                        <input type="hidden" name="rm" value="2"/>
                        <input type="hidden" name="custom" value="this is my address here">
                        <input type="hidden" name="return" value="http://www.torza.co.uk/selling/p_index.php?p=<cms:show k_page_id />"/>
                        <input type="hidden" name="cancel_return" value="http://www.torza.co.uk/selling/p_index.php?p=<cms:show k_page_id />"/>
                        <input type="hidden" value="http://www.torza.co.uk/selling/p_index.php?p=<cms:show k_page_id />&paypal_ipn=1" name="notify_url" />
                                                <input type="submit" value="BUY NOW" class="button-style" />
                        </form>

Hi,

I think you should set a variable (stock_amount) at the start of your form and update the database with if k_success ( stock_amount = stock_amount minus order amount). On the product page call the stock_amount and create a statement if stock_amount is 0 hide the buy now button.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
It's the code for the final bit, processing I'm struggling with. Getting the code to work is the hardest part :lol: the main bit is to update stock amount once processing is successful
the main bit is to update stock amount once processing is successful


I'm not sure but maybe you can wrap the update into <cms:if k_paypal_success ='1'> .... </cms:if>
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
I agree with @Tomarnst - the 'k_paypal_success' condition of <cms:paypal_processor> (http://docs.couchcms.com/concepts/paypal.html ) is where you can update the stock
Code: Select all
<cms:paypal_processor>
    <cms:if k_paypal_success>

        <!-- here is where you can update the stock -->

    </cms:if>

    ..
</cms:paypal_processor>

As to how, you should use cms:db_persist for that (please search for the term and you'll find several examples of it).
Okay so here goes what i've found and hope i'm somewhere near. please let me know where i've gone wrong.


I've set a editable called amount_c within the clone page of the products. Now within the clone page i've set this code to show the buy button and the ended button.

Code: Select all
<cms:if amount_c='0' >
<---! show the ended button --->
<cms:else />
<---! show the buy it now button --->
</cms:if>


Okay so if i change the amount to 0 within that product it ends it, sorted. If the user has 10 in stock it'll show the buy it now button. sorted.

Now to work on the if k paypal success

So here's my attempt.

Code: Select all

<cms:paypal_processor>
    <cms:if k_paypal_success>
   
    <cms:db_persist  count='<cms:show amount_c />' count_down='1' />
       
       
       
    </cms:if>

    <cms:if k_paypal_error>
        <cms:set msg="ERROR: <cms:show k_paypal_error/>" />
        <cms:log msg />
    </cms:if>
</cms:paypal_processor>



I'm not sure how far off i am with that code above to submit a updated amount. So to -1 item when its brought.
Try this, Simon.
Code: Select all
    <cms:db_persist  
       amount_c = "<cms:sub amount_c '1' />"
     />
Hey Tim,

I've used the code above but no luck so far.

Code

Code: Select all
<cms:paypal_processor>
    <cms:if k_paypal_success>
   
   <cms:db_persist 
       amount_c = "<cms:sub amount_c '1' />"
     />

       
    </cms:if>

    <cms:if k_paypal_error>
        <cms:set msg="ERROR: <cms:show k_paypal_error/>" />
        <cms:log msg />
    </cms:if>
</cms:paypal_processor>


No Joy. I've brought the product that states 1 in stock and paid via paypal, no joy :| Ifg i go into the post and edit to 0 it works fine, showing ended button. Just the processor part. I've search for count but nothing in the results that i can work out to count down.
I've also tried this too

Code: Select all
<cms:paypal_processor>
    <cms:if k_paypal_success>
<cms:db_persist  amount_c = "<cms:sub amount_c '1' />"/>
</cms:if>
</cms:paypal_processor>
Haven't actually tested the following out but it should work -
Code: Select all
<cms:paypal_processor>
    <cms:if k_paypal_success>
        <cms:pages masterpage='products.php' id=pp_item_number>
            <cms:db_persist
                 _masterpage=k_template_name
                 _mode='edit'
                 _page_id=k_page_id
                 
                 amount_c = "<cms:sub amount_c '1' />"
            >
           
                <cms:if k_error >
                    <cms:set msg="ERROR db_persist: <cms:show k_error/>" />
                    <cms:log msg />
                </cms:if>
               
            </cms:db_persist>
        </cms:pages>
    </cms:if>

    <cms:if k_paypal_error>
        <cms:set msg="ERROR: <cms:show k_paypal_error/>" />
        <cms:log msg />
    </cms:if>
</cms:paypal_processor>

The idea above is to use the 'pp_item_number' variable made available by cms:paypal_processor to fetch the actual page from products.php (use your template's name) and then modify its region.

Does it help?
17 posts Page 1 of 2