Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #118 from VirtoCommerce/dev
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
pushnitsa authored Oct 29, 2020
2 parents fb626d3 + 6bb5278 commit 819afd4
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 251 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
- name: Build
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' }}
uses: VirtoCommerce/vc-github-actions/build-theme@master
with:
versionSuffix: ${{ steps.image.outputs.suffix }}

- name: Publish
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' }}
Expand All @@ -76,4 +78,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.publish.outputs.artifactPath }}
asset_name: ${{ steps.publish.outputs.artifactName }}
asset_content_type: application/zip
asset_content_type: application/zip
92 changes: 84 additions & 8 deletions assets/js/account/account-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ angular.module('storefront.account')
$window.open(url, '_blank');
}

// $ctrl.reorder = function() {
// var productIdsQuery = $ctrl.order.items.map(item => {
// return 'productIds=' + item.productId;
// }).join("&");

// catalogService.getProducts(productIdsQuery).then(response => {
// if (response.data && response.data.length) {
// var configurationProducts = response.data.map(item => {
// return angular.extend(item, { quantity: _.findWhere($ctrl.order.items, {productId: item.id}).quantity });
// });
// var inventoryError = configurationProducts.some(product => {
// return product.availableQuantity < product.quantity;
// });
// var dialogData = toDialogDataModel(configurationProducts, null, inventoryError, null);
// dialogService.showDialog(dialogData, 'recentlyAddedCartItemDialogController', 'storefront.recently-added-cart-item-dialog.tpl', 'lg');
// if (!inventoryError) {
// var items = configurationProducts.map(product => {
// return { id: product.id, quantity: product.quantity };
// });
// cartService.addLineItems(items).then(res => {
// var result = res.data;
// if (result.isSuccess) {
// $rootScope.$broadcast('cartItemsChanged');
// }
// });
// }
// }
// });
// }

$ctrl.paymentMethodChanged = function () {
loader.wrapLoading(function() {
$ctrl.selectedPaymentMethod = _.find($ctrl.paymentMethods, function (pm) { return pm.code == $ctrl.selectedPaymentMethodCode; });
Expand Down Expand Up @@ -165,6 +195,11 @@ angular.module('storefront.account')
addProductToCartById(productId, quantity);
});

$scope.$on('configurationAdded', function (event, data) {
const {configuration} = data;
addConfigurationToCart(configuration);
});

var components = [];
$ctrl.addComponent = function (component) {
components.push(component);
Expand All @@ -188,25 +223,66 @@ angular.module('storefront.account')
};

function addProductToCartById(productId, quantity) {
catalogService.getProduct([productId]).then(function (response) {
catalogService.getProduct([productId]).then(response => {
if (response.data && response.data.length) {
var product = response.data[0];
addProductToCart(product, quantity);
}
});
}

function addProductToCart(product, quantity) {
var dialogData = toDialogDataModel(product, quantity);
dialogService.showDialog(dialogData, 'recentlyAddedCartItemDialogController', 'storefront.recently-added-cart-item-dialog.tpl');
cartService.addLineItem(product.id, quantity).then(function (response) {
$rootScope.$broadcast('cartItemsChanged');
function addConfigurationToCart(configuration) {
let productIdsQuery = configuration.items.map(item => {
return 'productIds=' + item.productId;
}).join("&");

catalogService.getProducts(productIdsQuery).then(response => {
if (response.data && response.data.length) {
let configurationProducts = response.data.map(item => {
return angular.extend(item, { quantity: _.findWhere(configuration.items, {productId: item.id}).quantity });
});
let inventoryError = configurationProducts.some(product => {
return product.availableQuantity < product.quantity;
});
let dialogData = toDialogDataModel(configurationProducts, configuration.quantity, inventoryError, configuration.productId);
dialogService.showDialog(dialogData, 'recentlyAddedCartItemDialogController', 'storefront.recently-added-cart-item-dialog.tpl', 'lg');
if (!inventoryError) {
let items = configurationProducts.map(product => {
return { id: product.id, quantity: product.quantity, configuredProductId: configuration.productId };
});
cartService.addLineItems(items).then(res => {
let result = res.data;
if (result.isSuccess) {
$rootScope.$broadcast('cartItemsChanged');
}
});
}
}
});
}

function toDialogDataModel(product, quantity) {
return { items: [angular.extend({ }, product, { quantity: quantity })] };
function addProductToCart(product, quantity) {
var inventoryError = product.availableQuantity < quantity;
angular.extend(product, { quantity });
var dialogData = toDialogDataModel([product], null, inventoryError, null);
dialogService.showDialog(dialogData, 'recentlyAddedCartItemDialogController', 'storefront.recently-added-cart-item-dialog.tpl', 'lg');
if (!inventoryError) {
cartService.addLineItem(product.id, quantity).then(() => {
$rootScope.$broadcast('cartItemsChanged');
});
}
}

function toDialogDataModel(products, configurationQty, inventoryError, configuredProductId) {
let productIds = products.map(product => {
return product.productId;
});
let items = products.map(product => {
return angular.extend({ }, product, { inventoryError: product.availableQuantity < product.quantity, configuredProductId: configuredProductId })
});
return { productIds, items, inventoryError, configuredProductId, configurationQty };
}

}]
})
.filter('orderToSummarizedStatusLabel', [function () {
Expand Down
10 changes: 4 additions & 6 deletions assets/js/account/account-orders.tpl.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="row">
<div class="col-md-12">
{% capture order_number %}{% raw %}{{$ctrl.orderNumber}}{% endraw %}{% endcapture %}
<h3>{{ 'customer.order.title' | t: order_number }}</h3>
<h3 class="my-3">{{ 'customer.order.title' | t: order_number }}</h3>
<div class="row">
<div class="col-md-4">
<p>{{ 'customer.orders.status' | t }}: <span ng-bind="$ctrl.order.status" class="info"></span></p>
Expand All @@ -98,11 +98,9 @@
</div>
</div>
</div>
<div class="panel-body panel-table">
<div class="row">
<div class="col-md-12">
<vc-line-items items="$ctrl.order.items"></vc-line-items>
</div>
<div class="row" ng-if="$ctrl.order">
<div class="col-md-12">
<vc-line-items order="$ctrl.order"></vc-line-items>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions assets/js/app/consts.js.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ angular.module('storefrontApp.consts', [])
.constant('sortAscending', 'asc')
.constant('sortDescending', 'desc')
.constant('orderStatuses', ['Unpaid','Paid','Completed'])
.constant('storeCurrency', {{ current_currency | json }})
.constant('itemResponseGroup', {
None: 0,
ItemInfo: 1,
Expand Down
9 changes: 4 additions & 5 deletions assets/js/checkout/checkout-configurable-line-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ storefrontApp.component('vcCheckoutConfigurableLineItem', {
bindings: {
item: '=',
onChangeQty: '&',
onRemove: '&',
cartItems: '<'
onRemove: '&'
},
controller: ['$scope', 'availablePaymentPlans', 'baseUrl', function ($scope, availablePaymentPlans, baseUrl) {
var ctrl = this;
Expand All @@ -28,12 +27,12 @@ storefrontApp.component('vcCheckoutConfigurableLineItem', {

this.changeQty = function () {
if (ctrl.onChangeQty) {
ctrl.onChangeQty({ item: ctrl.item.configuredLineItem });
ctrl.onChangeQty({ item: ctrl.item });
}
};

this.remove = function () {
ctrl.onRemove({ item: ctrl.item.configuredLineItem });
ctrl.onRemove({ item: ctrl.item });
}

this.validate = function () {
Expand All @@ -53,7 +52,7 @@ storefrontApp.component('vcCheckoutConfigurableLineItem', {

function getConfiguredLineItems(item) {
_.each(item.parts, function (part) {
part.items = [ctrl.cartItems.find(x => x.id === part.selectedItemId)];
part.items = [item.items.find(x => x.id === part.selectedItemId)];
});
}

Expand Down
28 changes: 14 additions & 14 deletions assets/js/checkout/checkout-configurable-line-item.tpl.html.liquid
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<div class="d-flex flex-column">
<div class="d-flex align-items-center">
<div class="col-xs-2 col-md-1 align-self-start">
<img class="img-responsive" alt="{% raw %}{{ $ctrl.item.configuredLineItem.name }}{% endraw %}" ng-src="{% raw %}{{ $ctrl.item.configuredLineItem.imageUrl }}{% endraw %}" fallback-src="{{ 'no-image.svg' | asset_url }}" />
<img class="img-responsive" alt="{% raw %}{{ $ctrl.item.product.name }}{% endraw %}" ng-src="{% raw %}{{ $ctrl.item.product.primaryImage.url }}{% endraw %}" fallback-src="{{ 'no-image.svg' | asset_url }}" />
</div>
<div class="col-xs-4 col-md-4">
<p><span ng-bind="$ctrl.item.configuredLineItem.name" class="text-bold"></span></p>
<p><span class="text-bold">Item</span> <span ng-bind="$ctrl.item.configuredLineItem.sku"></span></p>
<p><span ng-bind="$ctrl.item.product.name" class="text-bold"></span></p>
<p><span class="text-bold">Item</span> <span ng-bind="$ctrl.item.product.sku"></span></p>
<p>
<span class="text-bold">Price</span>
{% if settings.show_prices_with_taxes %}
<span ng-bind="$ctrl.item.configuredLineItem.placedPriceWithTax.formattedAmount" class="text-bold text-green"></span>
<span ng-bind="$ctrl.item.placedPriceWithTax.formattedAmount" class="text-bold text-green"></span>
{% else %}
<span ng-bind="$ctrl.item.configuredLineItem.placedPrice.formattedAmount" class="text-bold text-green"></span>
<span ng-bind="$ctrl.item.placedPrice.formattedAmount" class="text-bold text-green"></span>
{% endif %}
<span>/ each</span>
</p>
<p class="d-flex">
<img class="img-responsive" style="margin-right: 4px;" src="{{ 'customize.svg' | asset_url }}" />
<img class="img-responsive mr-2" src="{{ 'customize.svg' | asset_url }}" />
<a ng-bind="$ctrl.getToggleTitle()" ng-click="$ctrl.toggleConfiguration()" class="cursor-pointer"></a>
</p>
</div>
<div class="hidden-xs hidden-sm col-md-3" ng-init='$ctrl.loadPaymentPlan({{ settings.available_paymentPlans | json }}, "product", $ctrl.item.configuredLineItem.productId)'>
<vc-item-availability availability="$ctrl.item.configuredLineItem.availability"></vc-item-availability>
<vc-payment-plan available-payment-plans="$ctrl.availablePaymentPlans" payment-plan="$ctrl.item.configuredLineItem.paymentPlan"></vc-payment-plan>
<div class="hidden-xs hidden-sm col-md-3" ng-init='$ctrl.loadPaymentPlan({{ settings.available_paymentPlans | json }}, "product", $ctrl.item.productId)'>
<vc-item-availability availability="$ctrl.item.availability"></vc-item-availability>
<vc-payment-plan available-payment-plans="$ctrl.availablePaymentPlans" payment-plan="$ctrl.item.paymentPlan"></vc-payment-plan>
</div>
<div class="col-xs-3 col-md-2">
<div class="row nogap">
<div class="col-md-6 form-group">
<input class="form-control" type="text" ng-model="$ctrl.item.configuredLineItem.quantity" />
<input class="form-control" type="text" ng-model="$ctrl.item.quantity" />
</div>
<div class="col-md-6">
<a href="" ng-click="$ctrl.changeQty()">Update</a>
Expand All @@ -39,9 +39,9 @@
<p>
<span class="text-bold text-condensed">Total</span><br>
{% if settings.show_prices_with_taxes %}
<span ng-bind="$ctrl.item.configuredLineItem.extendedPriceWithTax.formattedAmount" class="text-green text-bold"></span>
<span ng-bind="$ctrl.item.extendedPriceWithTax.formattedAmount" class="text-green text-bold"></span>
{% else %}
<span ng-bind="$ctrl.item.configuredLineItem.extendedPrice.formattedAmount" class="text-green text-bold"></span>
<span ng-bind="$ctrl.item.extendedPrice.formattedAmount" class="text-green text-bold"></span>
{% endif %}
</p>
</div>
Expand Down Expand Up @@ -86,9 +86,9 @@
</td>
<td ng-bind="part.items[0].quantity" class="text-center"></td>
{% if settings.show_prices_with_taxes %}
<td ng-bind="part.items[0].extendedPriceWithTax.formattedAmount" class="text-bold text-green" style="text-align: right;"></td>
<td ng-bind="part.items[0].extendedPriceWithTax.formattedAmount" class="text-bold text-green text-right"></td>
{% else %}
<td ng-bind="part.items[0].extendedPrice.formattedAmount" class="text-bold text-green" style="text-align: right;"></td>
<td ng-bind="part.items[0].extendedPrice.formattedAmount" class="text-bold text-green text-right"></td>
{% endif %}
</tr>
</tbody>
Expand Down
17 changes: 1 addition & 16 deletions assets/js/checkout/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ angular.module(moduleName, ['credit-cards', 'angular.filter'])
$scope.checkout.cart = cart;

if (!$scope.checkout.productIds) {
$scope.checkout.productIds = cart.items.map(lineItem => lineItem.productId);
$scope.checkout.productIds = cart.usualItems.map(lineItem => lineItem.productId);
}

if (cart.coupon) {
Expand All @@ -189,21 +189,6 @@ angular.module(moduleName, ['credit-cards', 'angular.filter'])
$scope.checkout.coupon.code = null;
}

if (cart.configuredItems && cart.configuredItems.length) {
$scope.configuredItemsIds = [];
_.each($scope.checkout.cart.configuredItems, function (item) {
_.each(item.parts, function (part) {
$scope.configuredItemsIds.push(part.selectedItemId);
});
});
$scope.configuredItemsIds = _.uniq($scope.configuredItemsIds);
$scope.regularLineItems = _.filter($scope.checkout.cart.items, function(item) {
return $scope.configuredItemsIds.indexOf(item.id) === -1;
});
} else {
$scope.regularLineItems = $scope.checkout.cart.items;
}

if (cart.payments.length) {
$scope.checkout.payment = cart.payments[0];
$scope.checkout.paymentMethod.code = $scope.checkout.payment.paymentGatewayCode;
Expand Down
36 changes: 33 additions & 3 deletions assets/js/common-components/lineItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,43 @@
storefrontApp.component('vcLineItems', {
templateUrl: "themes/assets/js/common-components/lineItems.tpl.liquid",
bindings: {
items: '='
order: '='
},
controller: ['$scope', function ($scope) {
controller: ['$scope', 'baseUrl', function ($scope, baseUrl) {
var $ctrl = this;
$scope.baseUrl = baseUrl;
$scope.regex = new RegExp(/^\/+/);

$scope.addProductToCart = function (productId, quantity) {
$ctrl.addProductToCart = function (productId, quantity) {
$scope.$emit('lineItemAdded', {productId, quantity});
}

$ctrl.addConfigurationToCart = function (configuration) {
$scope.$emit('configurationAdded', {configuration});
}

$ctrl.getToggleTitle = function (group) {
return group.showConfiguration === false ? 'Show configuration' : 'Hide configuration';
};

$ctrl.toggleConfiguration = function(group) {
group.showConfiguration = !group.showConfiguration;
};

$ctrl.getProductLink = function(productId) {
return `product/${productId}`.replace($scope.regex, $scope.baseUrl);
};

function getConfiguredLineItems(groups) {
_.each(groups, group => {
angular.extend(group, { showConfiguration: false });
_.each(group.parts, part => {
part.items = [group.items.find(x => x.id === part.selectedItemId)];
});
});
}

getConfiguredLineItems($ctrl.order.configuredGroups);

}]
});
Loading

0 comments on commit 819afd4

Please sign in to comment.