Skip to content

StockField

StockField is the representative implementation of AbstractField for stock information.

The stockNumeric information must be either an int or a float.

A new StockField can be created using the following data:

1
2
3
4
use Silversolutions\Bundle\EshopBundle\Content\Fields\StockField;

// Usage: 
$stockField = new StockField(array('stockNumeric' => 15));

StockField rendering

The StockField can be rendered with the ses_render_stock Twig helper.

This method renders the StockField from a central template:

Silversolutions/Bundle/EshopBundle/Resources/views/Fieldtypes/StockField.html.twig

The availability is displayed depending on the given parameters. If the StockField is not defined (e.g. ERP is not responding), no availability information for this product is displayed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{% set field = line.remoteDataMap.stock is defined ? line.remoteDataMap.stock : null %}
    {{ ses_render_stock(field, {
                        'outputStock': {
                        'numeric': false,
                        'cssClass': 'availability'
                         },
                        'quantity' : line.quantity
     }) }}

{% set field = catalogElement.stock is defined ? catalogElement.stock : null %}
    {{ ses_render_stock(field, {
        'outputStock': {
        'numeric': true,
        'cssClass': 'availability'
        }
        })
    }}