mapping
7 years ago
angular-chosen.directive.js
7 years ago
attributes.service.js
7 years ago
autodetect.directive.js
7 years ago
cascade.directive.js
7 years ago
contenteditable.directive.js
7 years ago
currency.service.js
7 years ago
droppable.directive.js
7 years ago
export.service.js
7 years ago
focusMeWhenEnabled.directive.js
7 years ago
googleCategoriesService.js
7 years ago
main.controller.js
7 years ago
styledInput.directive.js
7 years ago
template.service.js
7 years ago
tipsy.directive.js
7 years ago
wpHttp.service.js
7 years ago
main.controller.js
219 lines
| 1 | GoogleMerchants.controller('mainController', ['$scope', '$timeout', '$window', '$document', '$location', 'templateService', 'exportService', 'currencyService', 'attributesService', 'wpHttp', function ($scope, $timeout, $window, $document, $location, templateService, exportService, currencyService, attributesService, wpHttp) { |
| 2 | |
| 3 | var defaultMappings = [{mapFrom : '', mapTo: ''}]; |
| 4 | |
| 5 | $scope.merchantsFeedData = { |
| 6 | |
| 7 | basicInformation: { |
| 8 | open: true, |
| 9 | itemTitle: "productTitle", |
| 10 | hasVariations: true, |
| 11 | useParentTitleForVariableProducts: true, |
| 12 | additionalImageLink: "productImages", |
| 13 | itemDescription: "productDescription", |
| 14 | itemImageLink: "useProductFeaturedImage", |
| 15 | itemLink: "productLink", |
| 16 | condition: 'new', |
| 17 | conditionMappings: defaultMappings, |
| 18 | userVariationDescriptionForVariableProducts: true, |
| 19 | addVariationAttributesToProductUrl: true, |
| 20 | useVariationImage: true, |
| 21 | useFeaturedImageIfThereIsNoVariationImage: true, |
| 22 | useParentDescirptionIfThereIsNoVariationDescirption: true |
| 23 | }, |
| 24 | detailedInformation: { |
| 25 | open: false, |
| 26 | color: 'selectFromWooCommerceProductAttributes', |
| 27 | size: 'selectFromWooCommerceProductAttributes', |
| 28 | gender: 'selectFromWooCommerceProductAttributes', |
| 29 | setTheGroupId: 'automatically', |
| 30 | mappings: defaultMappings, |
| 31 | ageGroup: 'selectFromWooCommerceProductAttributes', |
| 32 | material: 'selectFromWooCommerceProductAttributes', |
| 33 | pattern: 'selectFromWooCommerceProductAttributes', |
| 34 | genderAutodetect: 'keepBlank', |
| 35 | sizeSystem: '', |
| 36 | adjustPrice: false, |
| 37 | adjustSalePrice: false |
| 38 | |
| 39 | }, |
| 40 | availabilityPrice: { |
| 41 | open: false, |
| 42 | price: 'useProductPrice', |
| 43 | salePrice: 'useProductSalePrice', |
| 44 | availability: 'useWooCommerceStockValues', |
| 45 | adjustPriceValue: '', |
| 46 | adjustPriceType: '%', |
| 47 | adjustSalePriceType: '%', |
| 48 | adjustSalePriceValue: '', |
| 49 | currency: null |
| 50 | }, |
| 51 | productCategories: { |
| 52 | open: false, |
| 53 | productType: 'useWooCommerceProductCategories', |
| 54 | productCategories: 'mapProductCategories' |
| 55 | }, |
| 56 | uniqueIdentifiers: { |
| 57 | open: false, |
| 58 | identifierExists: 1 |
| 59 | }, |
| 60 | shipping: { |
| 61 | dimensions: 'useWooCommerceProductValues', |
| 62 | convertTo: 'cm', |
| 63 | adjustPriceType: '%' |
| 64 | }, |
| 65 | template: { |
| 66 | save: false, |
| 67 | name: '' |
| 68 | }, |
| 69 | advancedAttributes: { |
| 70 | adult: 'no', |
| 71 | unitPricingBaseMeasureUnit: 'kg', |
| 72 | excludedDestination: 'no', |
| 73 | customLabel0Mappings: defaultMappings, |
| 74 | customLabel1Mappings: defaultMappings, |
| 75 | customLabel2Mappings: defaultMappings, |
| 76 | customLabel3Mappings: defaultMappings, |
| 77 | customLabel4Mappings: defaultMappings, |
| 78 | energyEfficiencyClassMappings: defaultMappings, |
| 79 | promotionIdMappings: defaultMappings |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | function getParameterByName(name, url) { |
| 84 | if (!url) { |
| 85 | url = window.location.href; |
| 86 | } |
| 87 | name = name.replace(/[\[\]]/g, "\\$&"); |
| 88 | var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), |
| 89 | results = regex.exec(url); |
| 90 | if (!results) return null; |
| 91 | if (!results[2]) return ''; |
| 92 | return decodeURIComponent(results[2].replace(/\+/g, " ")); |
| 93 | } |
| 94 | |
| 95 | function setCategoriesToCustomDataIfProductsNotCategorized() { |
| 96 | |
| 97 | if (!$scope.merchantsFeedData.productCategories.cats.children.length) { |
| 98 | $scope.merchantsFeedData.productCategories.productCategories = 'customValue'; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | $scope.init = function (currencySymbol, currencyCode) { |
| 103 | |
| 104 | attributesService.setAttributes(wpae_product_attributes); |
| 105 | |
| 106 | $scope.isGoogleMerchantExport = false; |
| 107 | |
| 108 | currencyService.setCurrency(currencySymbol, currencyCode); |
| 109 | }; |
| 110 | |
| 111 | $scope.selectGoogleMerchantsInitially = function() { |
| 112 | $scope.selectGoogleMerchants(); |
| 113 | }; |
| 114 | |
| 115 | $scope.selectGoogleMerchants = function () { |
| 116 | |
| 117 | jQuery('.wpallexport-element-label').parent().parent().slideUp(); |
| 118 | $scope.isGoogleMerchantExport = true; |
| 119 | |
| 120 | var id = getParameterByName('id'); |
| 121 | |
| 122 | exportService.getExport(id).then(function (exportData) { |
| 123 | if (angular.isObject(exportData)) { |
| 124 | |
| 125 | exportData.template = { |
| 126 | save: false, |
| 127 | name: '' |
| 128 | }; |
| 129 | |
| 130 | |
| 131 | $scope.merchantsFeedData = exportData; |
| 132 | |
| 133 | setCategoriesToCustomDataIfProductsNotCategorized(); |
| 134 | |
| 135 | } else { |
| 136 | wpHttp.get('categories/index').then(function (data) { |
| 137 | |
| 138 | $scope.merchantsFeedData.productCategories.cats = data; |
| 139 | $scope.merchantsFeedData.detailedInformation.genderCats = data; |
| 140 | $scope.merchantsFeedData.detailedInformation.ageGroupCats = data; |
| 141 | |
| 142 | setCategoriesToCustomDataIfProductsNotCategorized(); |
| 143 | |
| 144 | }, function () { |
| 145 | $log.error('There was a problem loading the WordPress categories'); |
| 146 | }); |
| 147 | } |
| 148 | }); |
| 149 | |
| 150 | if($scope.merchantsFeedData.availabilityPrice.currency == null) { |
| 151 | $scope.merchantsFeedData.availabilityPrice.currency = currencyService.getCurrencyCode(); |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | $scope.$on('googleMerchantsSelected', function (event, hasVariations) { |
| 156 | |
| 157 | $scope.selectGoogleMerchants(); |
| 158 | $scope.merchantsFeedData.basicInformation.hasVariations = hasVariations; |
| 159 | |
| 160 | // Hide "All $element" lis |
| 161 | jQuery('.wpallexport-element-label').parent().parent().slideUp(); |
| 162 | |
| 163 | $timeout(function () { |
| 164 | $scope.isGoogleMerchantExport = true; |
| 165 | }); |
| 166 | }); |
| 167 | |
| 168 | $scope.$on('googleMerchantsDeselected', function () { |
| 169 | |
| 170 | jQuery('.wpallexport-element-label').parent().parent().slideDown(); |
| 171 | |
| 172 | $timeout(function () { |
| 173 | $scope.isGoogleMerchantExport = false; |
| 174 | }); |
| 175 | }); |
| 176 | |
| 177 | $scope.$on('googleMerchantsSubmitted', function (event, data) { |
| 178 | $scope.merchantsFeedData.template.name = data.templateName; |
| 179 | $scope.process(); |
| 180 | }); |
| 181 | |
| 182 | $scope.$on('templateShouldBeSaved', function (event, name) { |
| 183 | $scope.merchantsFeedData.template.save = true; |
| 184 | $scope.merchantsFeedData.template.name = name; |
| 185 | }); |
| 186 | |
| 187 | $scope.$on('templateShouldNotBeSaved', function () { |
| 188 | $scope.merchantsFeedData.template.save = false; |
| 189 | }); |
| 190 | |
| 191 | $scope.$on('selectedTemplate', function (event, templateId) { |
| 192 | templateService.getTemplate(templateId).then(function (template) { |
| 193 | $scope.merchantsFeedData = template.google_merchants_post_data; |
| 194 | }); |
| 195 | }); |
| 196 | |
| 197 | |
| 198 | $scope.process = function () { |
| 199 | |
| 200 | $scope.merchantsFeedData.extraData = jQuery('#templateForm').serialize(); |
| 201 | |
| 202 | var id = getParameterByName('id'); |
| 203 | |
| 204 | if(id) { |
| 205 | $scope.merchantsFeedData.exportId = id; |
| 206 | $scope.merchantsFeedData.update = true; |
| 207 | } |
| 208 | |
| 209 | exportService.saveExport($scope.merchantsFeedData).then(function (response) { |
| 210 | |
| 211 | if(response.redirect) { |
| 212 | $window.location.href = response.redirect; |
| 213 | } else { |
| 214 | $window.location.href = 'admin.php?page=pmxe-admin-export&action=options'; |
| 215 | } |
| 216 | |
| 217 | }); |
| 218 | }; |
| 219 | }]); |