Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
integration:craftcms [2014/08/10 08:22] – [Set up templates] adamintegration:craftcms [2019/01/22 14:14] (current) – [Webhooks] adam
Line 94: Line 94:
 Now navigate to 'Settings > Sections', and create a new section. Give it a name of "Product", handle of "products" and a section type of "Channel". Also set the Entry URL Format to "store/{slug}" and the Entry Template to "store/_product". Now navigate to 'Settings > Sections', and create a new section. Give it a name of "Product", handle of "products" and a section type of "Channel". Also set the Entry URL Format to "store/{slug}" and the Entry Template to "store/_product".
  
-Once that is created, click on the 'Edit entry type' that appears next to it's listing in the "Sections" page and then the "Product" option that appears. Uncheck the "Show title fields" checkbox and enter "{heading}" in the Title Format text box that appears. Down the bottom, create two tabs in the "Design your field layout" section. Name the first tab 'Default' and place in there the "Heading" and "Body" fields. Then name the second tab "Product" and add in any product fields you created in the previous step - making the "Name", "Price" and "Code" fields required by clicking on the cog icon next to their labels.+Once that is created, click on the 'Edit entry type' that appears next to it's listing in the "Sections" page and then the "Product" option that appears. Uncheck the "Show title fields" checkbox and enter "{heading}" in the Title Format text box that appears. Down the bottom, create two tabs in the "Design your field layout" section. Name the first tab 'Default' and place in there the "Heading" and "Body" fields. Then name the second tab "Product" and add in any product fields you created in the previous step - making the "Heading", "Name", "Price" and "Code" fields required by clicking on the cog icon next to their labels.
  
 Save those changes. Save those changes.
Line 124: Line 124:
  
 === _product.html === === _product.html ===
- 
-Make sure you replace the store domain in the add to cart form in this code. 
  
 <code html>{% extends "_layout" %} <code html>{% extends "_layout" %}
Line 179: Line 177:
 ===== Simple as that! ===== ===== Simple as that! =====
  
-{{ :integration:craft_site.jpg?400|}}  +{{ :integration:craft_site2.jpg?400|}}  
-Getting FoxyCart integrated into CraftCMS is as simple as that - and thanks to the flexibility and power of Craft, you can very quickly and easily set up products that match exactly the structure your products need. You can also display them however you need, with complete control over the templates for Craft, as well as the templates for your FoxyCart store.+ 
 +Getting FoxyCart integrated into Craft CMS is as simple as that - and thanks to the flexibility and power of Craft, you can very quickly and easily set up products that match exactly the structure your products need. You can also display them however you need, with complete control over the templates for Craft, as well as the templates for your FoxyCart store.
  
 Obviously you'll need to apply some styling love to the templates - this should at least give you a great starting point to getting a FoxyCart powered store into your Craft website. Obviously you'll need to apply some styling love to the templates - this should at least give you a great starting point to getting a FoxyCart powered store into your Craft website.
Line 186: Line 185:
 ===== Other Plugin Features ===== ===== Other Plugin Features =====
  
-==== HMAC Encryption ====+==== Link/Form Validation ====
  
-If you'd like to make use of our [[static:redirect:price_validation|link and form encryption]] to prevent possible tampering, you simply need to wrap your links and forms, or the whole page, within ''{% hmac %}'' and ''{% endhmac %}'' tags. Note that you also need to enable this option on the 'advanced' settings page of your store's FoxyCart administration. Taking the ''_product.html'' template from before:+If you'd like to make use of our [[static:redirect:price_validation|link and form validation]] to prevent possible tampering, you simply need to wrap your links and forms, or the whole page, within ''{% hmac %}'' and ''{% endhmac %}'' tags. Note that you also need to enable this option on the 'advanced' settings page of your store's FoxyCart administration. Taking the ''_product.html'' template from before:
    
 <code html>{% extends "_layout" %} <code html>{% extends "_layout" %}
  
 {% block content %} {% block content %}
- {% set image = entry.image.first() %}+    {% set image = entry.image.first() %}
  
- <article> +    <article> 
- <h2>{{ entry.title }}</h2> +        <h2>{{ entry.title }}</h2> 
- <h3>${{ entry.price }}</h3> +        <h3>${{ entry.price }}</h3> 
- {% if image %} +        {% if image %} 
- <img src="{{ image.url }}" alt="{{ entry.title }}" /> +            <img src="{{ image.url }}" alt="{{ entry.title }}" /> 
- {% endif %} +        {% endif %} 
- {{ entry.body }} +        {{ entry.body }} 
- {% hmac %} +        {% hmac %} 
- <form action="https://{{ craft.foxyCart.storedomain }}/cart" method="post" accept-charset="utf-8"> +        <form action="https://{{ craft.foxyCart.storedomain }}/cart" method="post" accept-charset="utf-8"> 
- <input type="hidden" name="name" value="{{ entry.product_name }}" /> +            <input type="hidden" name="name" value="{{ entry.product_name }}" /> 
- <input type="hidden" name="price" value="{{ entry.price }}" /> +            <input type="hidden" name="price" value="{{ entry.price }}" /> 
- <input type="hidden" name="category" value="{{ entry.foxycart_category }}" /> +            <input type="hidden" name="code" value="{{ entry.code }}" /> 
- {% if image %} +            <input type="hidden" name="category" value="{{ entry.foxycart_category }}" /> 
- <input type="hidden" name="image" value="{{ image.url }}" /> +            {% if image %} 
- {% endif %} +                <input type="hidden" name="image" value="{{ image.url }}" /> 
- <label for="quantity">Quantity</label> +            {% endif %} 
- <input type="number" id="quantity" name="quantity" value="1" /> +            <label for="quantity">Quantity</label> 
- <input type="submit" value="Add to cart" class="submit" /> +            <input type="number" id="quantity" name="quantity" value="1" /> 
- </form> +            {% if entry.colour | length %} 
- {% endhmac %} +                <label for="colour">Colour</label> 
- </article>+                <select name="colour" id="colour"> 
 +                    {% for row in entry.colour %} 
 +                        <option value="{{ row.value }}" {% if row.default %}selected{% endif %}>{{ row.label }}</option> 
 +                    {% endfor %} 
 +                </select> 
 +            {% endif %} 
 +            <input type="submit" value="Add to cart" class="submit" /> 
 +        </form> 
 +        {% endhmac %} 
 +    </article>
 {% endblock %} {% endblock %}
 </code> </code>
Line 223: Line 231:
 Navigate to the FoxyCart Craft plugin's settings page and copy the webhooks action URL from the lower section of the page, and set that within the 'advanced' settings section of your store's FoxyCart administration. Navigate to the FoxyCart Craft plugin's settings page and copy the webhooks action URL from the lower section of the page, and set that within the 'advanced' settings section of your store's FoxyCart administration.
  
-If you need to perform custom actions with that data (for example, you may need to subscribe a customer to a mailing list), you can make use of the ''foxyCart.onProcessWebhook'' event. The event contains two parameters, ''xml'' which contains the decrypted XML from the webhook payload and ''feedType'' which will either be ''transaction'' or ''subscription'' dependant on the type of webhook that has been triggered. If you don't have an existing custom plugin for your custom Craft code, we recommend utilising the [[https://github.com/lindseydiloreto/craft-businesslogic|Business Logic plugin]].+If you need to perform custom actions with that data (for example, you may need to subscribe a customer to a mailing list), you can make use of the ''foxyCart.onProcessWebhook'' event. The event contains two parameters, ''xml'' which contains the decrypted XML from the webhook payload and ''type'' which will either be ''transaction'' or ''subscription'' dependant on the type of webhook that has been triggered. If you don't have an existing custom plugin for your custom Craft code, we recommend utilising the [[https://github.com/lindseydiloreto/craft-businesslogic|Business Logic plugin]]. 
 + 
 +<code php> 
 +craft()->on('foxyCart.onProcessWebhook', function(Event $event) { 
 +    $xml = $event->params['xml']; // The decrypted XML payload 
 +    $feedType = $event->params['type']; // "transaction" or "subscription" 
 +     
 +    // .. your code 
 +}); 
 +</code>
  
 +For an example of the payload you'll receive, you can review those on their respective wiki pages - [[v:2.0:transaction_xml_datafeed|transaction datafeed]] and [[v:2.0:subscription_xml_datafeed|subscription datafeed]].
 ==== Single Sign-On ==== ==== Single Sign-On ====
  

Site Tools