Skip to content

Commit

Permalink
added onHand, onHold and sold into product detail, variants list and …
Browse files Browse the repository at this point in the history
…inventory list
  • Loading branch information
Tetragramat committed Jul 15, 2016
1 parent 7126baa commit d15bb37
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/WebBundle/Resources/public/js/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$(document).ready(function() {
$('.variant-table-toggle i.glyphicon').on('click', function(e) {
$(this).toggleClass('glyphicon-chevron-down glyphicon-chevron-up');
$(this).parent().parent().find('table tbody').toggle();
$(this).parents('table').find('tr[data-toggle-id="'+$(this).parent().data('id')+'"]').toggle();
});
$('.datepicker').datepicker({format: 'dd.mm.yyyy'});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ sylius:
shipping_category: Typ dopravy
sku: SKU
stock: Aktuálně skladem
on_hold: Rezervováno
sold: Prodáno
tabs:
categorization: Kategorizace
images: Obrázky
Expand Down Expand Up @@ -328,6 +330,10 @@ sylius:
name: Jméno
updated_at: Poslední aktualizace
zone: Oblast
stockable:
on_hand: Na skladě
on_hold: Rezervováno
sold: Prodáno
tax_category:
description: Popis
id: ID
Expand Down Expand Up @@ -362,6 +368,8 @@ sylius:
price: Cena
sku: SKU
stock: Aktuálně skladem
on_hold: Rezervováno
sold: Prodáno
"yes": true
zone:
index_header: Oblasti
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ sylius:
show_in_store: show in store
sku: SKU
stock: Current stock
on_hold: Reserved
sold: Sold
tabs:
categorization: Categorization
images: Images
Expand Down Expand Up @@ -775,6 +777,7 @@ sylius:
no_results: There are no inventory items to display.
on_hand: stock level
on_hold: on hold
sold: Sold
sku: sku
updated_at: last update
tax_category:
Expand Down Expand Up @@ -877,6 +880,8 @@ sylius:
price: Price
sku: SKU
stock: Current stock
on_hold: Reserved
sold: Sold
update_header: Editing variant
yes: yes
zone:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
<thead>
<tr>
<th>{{ sylius_resource_sort('id', '#id') }}</th>
<th>{{ sylius_resource_sort('sku', 'sylius.stockable.sku'|trans) }}</th>
<th></th>
<th>{{ sylius_resource_sort('name', 'sylius.product.name'|trans) }}</th>
<th>{{ 'sylius.variant.options'|trans }}</th>
<th>{{ sylius_resource_sort('onHand', 'sylius.stockable.on_hand'|trans) }}</th>
<th>{{ sylius_resource_sort('onHold', 'sylius.stockable.on_hold'|trans) }}</th>
<th>{{ 'sylius.stockable.sold'|trans }}</th>
<th></th>
</tr>
</thead>
Expand All @@ -22,26 +24,42 @@
<td>
{{ product.id }}
</td>
<td>
{{ product.sku }}
</td>
{% if product.variants.count %}
<td class="variant-table-toggle" data-id="variants{{ product.id }}"><i class="glyphicon glyphicon-chevron-down"></i></td>
{% else %}
<td></td>
{% endif %}
<td>
<a href="{{ path('sylius_backend_product_show', {'id': product.id}) }}" class="btn btn-link">
<strong>{{ product.name }}</strong>
</a>
</td>
<td>
{% if not product.hasOptions %}
<span class="label label-{{ product.masterVariant.isInStock ? 'success' : 'danger' }}">{{ product.masterVariant.onHand }}</span>
<ul>
{% for option in product.masterVariant.options %}
<li><strong>{{ option.name }}</strong>: {{ option.value }}</li>
{% endfor %}
</ul>
</td>
<td>
{% if product.variants.count %}
{{ product.getOnHand() }}
{% else %}
-
<span class="label label-{{ product.masterVariant.isInStock ? 'success' : 'danger' }}">{{ product.masterVariant.onHand }}</span>
{% endif %}
</td>
<td>
{% if not product.hasOptions %}
{% if product.variants.count %}
{{ product.getOnHold() }}
{% else %}
<span class="label label-{{ product.masterVariant.onHold ? 'warning' : 'success' }}">{{ product.masterVariant.onHold }}</span>
{% endif %}
</td>
<td>
{% if product.variants.count %}
{{ product.getSold() }}
{% else %}
-
<span class="label label-info">{{ product.masterVariant.sold }}</span>
{% endif %}
</td>
<td>
Expand All @@ -50,45 +68,31 @@
</div>
</td>
</tr>
{% if product.hasOptions %}
<tr class="sub-table">
<td class="variant-table-toggle"><i class="glyphicon glyphicon-chevron-down"></i></td>
<td colspan="4">
<table class="table">
<thead>
<tr>
<th>id</th>
<th>{{ 'sylius.variant.availability'|trans }}</th>
<th>{{ 'sylius.variant.options'|trans }}</th>
<th></th>
<th colspan="2"></th>
</tr>
</thead>
<tbody style="display: none">
{% for variant in product.variants %}
<tr>
<td>{{ variant.id }}</td>
<td><span class="label label-{{ variant.available ? 'success' : 'danger' }}">{{ variant.availableOn|date }}</span></td>
<td>
<ul>
{% for option in variant.options %}
<li><strong>{{ option.name }}</strong>: {{ option.value }}</li>
{% endfor %}
</ul>
</td>
<td><span class="label label-{{ variant.inStock ? 'success' : 'danger' }}">{{ variant.onHand }}</span></td>
<td><span class="label label-{{ variant.onHold ? 'warning' : 'success' }}">{{ variant.onHold }}</span></td>
<td>
<div class="pull-right">
{{ buttons.edit(path('sylius_backend_product_variant_update', {'productId': product.id, 'id': variant.id})) }}
</div>
</td>
</tr>
{% if product.variants.count %}
{% for variant in product.variants %}
<tr data-toggle-id="variants{{ product.id }}" style="display: none;">
<td>{{ variant.id }}</td>
<td></td>
<td>
{{ variant.presentation }}
</td>
<td>
<ul>
{% for option in variant.options %}
<li><strong>{{ option.name }}</strong>: {{ option.value }}</li>
{% endfor %}
</tbody>
</table>
</td>
</tr>
</ul>
</td>
<td><span class="label label-{{ variant.inStock ? 'success' : 'danger' }}">{{ variant.onHand }}</span></td>
<td><span class="label label-{{ variant.onHold ? 'warning' : 'success' }}">{{ variant.onHold }}</span></td>
<td><span class="label label-info">{{ variant.sold }}</span></td>
<td>
<div class="pull-right">
{{ buttons.edit(path('sylius_backend_product_variant_update', {'productId': product.id, 'id': variant.id})) }}
</div>
</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,33 @@
{% endif %}
<tr>
<td>{{ 'sylius.product.stock'|trans }}</td>
<td><span class="label label-{{ product.masterVariant.inStock ? 'success' : 'important' }}">{{ product.masterVariant.onHand }}</span></td>
<td>
{% if product.variants.count %}
{{ product.getOnHand() }}
{% else %}
<span class="label label-{{ product.masterVariant.isInStock ? 'success' : 'danger' }}">{{ product.masterVariant.onHand }}</span>
{% endif %}
</td>
</tr>
<tr>
<td>{{ 'sylius.product.on_hold'|trans }}</td>
<td>
{% if product.variants.count %}
{{ product.getOnHold() }}
{% else %}
<span class="label label-{{ product.masterVariant.onHold ? 'warning' : 'success' }}">{{ product.masterVariant.onHold }}</span>
{% endif %}
</td>
</tr>
<tr>
<td>{{ 'sylius.product.sold'|trans }}</td>
<td>
{% if product.variants.count %}
{{ product.getSold() }}
{% else %}
<span class="label label-info">{{ product.masterVariant.sold }}</span>
{% endif %}
</td>
</tr>
<tr>
<td>{{ 'sylius.product.price'|trans }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<th>{{ 'sylius.variant.options'|trans }}</th>
<th>{{ 'sylius.variant.available_on_demand'|trans }}</th>
<th>{{ 'sylius.variant.stock'|trans }}</th>
<th>{{ 'sylius.variant.on_hold'|trans }}</th>
<th>{{ 'sylius.variant.sold'|trans }}</th>
<th>{{ 'sylius.variant.price'|trans }}</th>
<th></th>
</tr>
Expand Down Expand Up @@ -52,6 +54,8 @@
</span>
</td>
<td><span class="label label-{{ variant.inStock ? 'success' : 'important' }}">{{ variant.onHand }}</span></td>
<td><span class="label label-{{ variant.onHold ? 'warning' : 'success' }}">{{ variant.onHold }}</span></td>
<td><span class="label label-info">{{ variant.sold }}</span></td>
<td>{{ variant.price|sylius_price }}</td>
<td>
<div class="pull-right">
Expand Down
51 changes: 51 additions & 0 deletions src/Sylius/Component/Core/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,57 @@ public function setShortDescription($shortDescription)
return $this;
}

/**
* {@inheritdoc}
*/
public function getOnHold()
{
if ($this->getVariants()) {
$onHold = 0;
foreach ($this->getVariants() as $variant) {
$onHold += $variant->getOnHold();
}

return $onHold;
} else {
return $this->getMasterVariant()->getOnHold();
}
}

/**
* {@inheritdoc}
*/
public function getOnHand()
{
if ($this->getVariants()) {
$onHand = 0;
foreach ($this->getVariants() as $variant) {
$onHand += $variant->getOnHand();
}

return $onHand;
} else {
return $this->getMasterVariant()->getOnHand();
}
}

/**
* {@inheritdoc}
*/
public function getSold()
{
if ($this->getVariants()) {
$sold = 0;
foreach ($this->getVariants() as $variant) {
$sold += $variant->getSold();
}

return $sold;
} else {
return $this->getMasterVariant()->getSold();
}
}

/**
* {@inheritdoc}
*/
Expand Down
21 changes: 21 additions & 0 deletions src/Sylius/Component/Core/Model/ProductInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ public function getShortDescription();
*/
public function setShortDescription($shortDescription);

/**
* Get sum of onHold from variants
*
* @return int
*/
public function getOnHold();

/**
* Get sum of onHand from variants
*
* @return int
*/
public function getOnHand();

/**
* Get sum of sold from variants
*
* @return int
*/
public function getSold();

/**
* Set taxation category.
*
Expand Down

0 comments on commit d15bb37

Please sign in to comment.