Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#901 2020-12-20 19:22:03

pexman
Member
Registered: 2016-02-27
Posts: 41

Re: yab_shop (simple textpattern shop with paypal support)

<txp:yab_shop_add /> quantity

My shop is now working and I have new wishes.

It would be nice if the number of items for sale could be indicated. If a unique item is offered, it makes no sense to enter more than 1 in the order field. In addition, after an order, the remaining number would have to be automatically reduced or, if the order was not completed, added again.

Maybe the topic has existed before, but I couldn’t find anything through the search.

Last edited by pexman (2020-12-20 19:22:52)

Offline

#902 2020-12-20 19:47:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,090
Website

Re: yab_shop (simple textpattern shop with paypal support)

Not quite sure I understand your request, sorry. Are you saying:

  1. You want a tag to allow people to specify the quantity of things on the article page near the ‘Buy’ button?
  2. You want to remove the quantity from the checkout so people cannot alter the quantity for some (all?) products?

For the “business logic” of altering inventory, that is not handled by the plugin natively. I would approach it like this:

a) Set a custom field to hold the ‘inventory’ value for each product (article).
b) Display this on the product page as an ‘Available to buy’ value.
c) There’s a plugin (unreleased and I don’t know if it still works with PayPal’s latest API) called smd_ipn that listens for successful transactions from PayPal. It then ‘wakes up’ and you can basically get it to do anything you want. Send off confirmation emails, log things, register orders, insert stuff in the database or, in your case, update the ‘inventory’ value in that custom field for the item that has just been bought.

You are more than welcome to have a copy of this plugin (just let me know) but as I say, I have no idea if it still works.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#903 2020-12-20 21:44:26

pexman
Member
Registered: 2016-02-27
Posts: 41

Re: yab_shop (simple textpattern shop with paypal support)

Yes, very professional, I didn’t expect anything else either :) I now have the following solution. On a form, I’ll check the rearranged custom_field named Item_Number to see if it’s empty.

Because I can’t sell all items in all quantities, I check the custom_field with the name Price (as entered in yab_shop.conf). If it is empty no output is given. If there is a price then starts the check if custom_field named Item_Number has a value. If no value is displayed, it indicates that the item is sold out.

I took the content out of the term <txp: yab_shop_add />. You can easily find the string by looking at your site’s source, something with <form> … yab_shop…<form>

Here is my code:

<a name="info"><h2><txp:title /></h2></a>
   <p class="footnote"><txp:text item="posted" /> 
<time datetime="<txp:posted format='iso8601' />"><txp:posted /></time></p>
<txp:body />
<br>
<txp:variable name="has-price"><txp:custom_field name="Preis" /></txp:variable>
<txp:variable name="has-anzahl"><txp:custom_field name="Anzahl" /></txp:variable>

 <!-- ############# check and output ############### -->

<txp:if_variable name="has-anzahl" value=""><txp:variable name="mehr"></txp:variable>
<txp:else />
<txp:variable name="mehr"><form method="post" action="https://arteurope.de/shop/Geist#yab-shop-form-582" id="yab-shop-form-582"><p class="yab-add"><input type="number"  name="qty" value="1" min="1" max="<txp:variable name="has-anzahl" />" /><input name="add" class="submit" type="submit" value="Bestellung" /></p></form></txp:variable></txp:if_variable>

<txp:if_variable name="has-price" value=""><txp:variable name="shopy"><hr width="240px"></txp:variable>
<txp:else />
<txp:if_variable name="mehr" value=""><txp:variable name="shopy"><p><strong>Nicht mehr erhältlich!</strong></p ></txp:variable>
<txp:else />
<txp:variable name="shopy"><big><txp:yab_shop_price/></big><br><br><txp:variable name="mehr" /><txp:yab_shop_cart ><txp:yab_shop_cart_items /><txp:image id="306" /><txp:yab_shop_cart_link  label='zur Kasse' /></txp:yab_shop_cart></txp:variable></txp:if_variable></txp:if_variable>

 <!-- ############# output ############### -->
<txp:variable name="shopy" />

<br>

<txp:text item="author" /> 
<span ><txp:author link="1" this_section="1" /></span><br>
  <txp:if_article_category>
                    <strong><i><txp:text item="categories" /></i></strong>
                    <span>
                        <i>
                            <txp:category1 title="1" link="1" this_section="1"/>
                            <txp:if_article_category number="1">
                                <txp:if_article_category number="2">, </txp:if_article_category>
                            </txp:if_article_category>
                            <txp:category2 title="1" link="1" this_section="1"/>
                        </i>
                    </span>
                </txp:if_article_category>

But how can I automaicly subtract a sold item from the Item_Number field? And how can it be added back if the customer cancels the process?

Last edited by pexman (2020-12-20 22:34:25)

Offline

#904 2020-12-20 21:58:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,090
Website

Re: yab_shop (simple textpattern shop with paypal support)

pexman wrote #327708:

But how can I automaicly subtract a sold item from the Item_Number field? And how can it be added back if the customer cancels the process?

You can’t (shouldn’t) do it client-side when people place things in their basket. The only reliable way is to intercept the “success” or “cancelled” transaction from the payment gateway and make any ‘business’ database alterations then.

Since yab_shop only supports PayPal at present, you need something that hooks into the PayPal loop. They use IPN which can be told to pass the transaction result (pass/fail) to a web link. Then, a plugin listening at that endpoint (in this case, I wrote smd_ipn to do the job) can intercept the call and take action to decrement the stock counter.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#905 2020-12-20 22:37:58

pexman
Member
Registered: 2016-02-27
Posts: 41

Re: yab_shop (simple textpattern shop with paypal support)

Okay, you are definitivly right. A never ending story, but for today it is enough, thank you Mister Bloke for your attention and intuition.

Offline

Board footer

Powered by FluxBB