Skip to content

Commit

Permalink
Better blank spec check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Sides committed Aug 17, 2020
1 parent 88794ec commit fcac120
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "pyxl/fillauer-product-importer",
"description": "WordPress plugin not for creating popups",
"type": "wordpress-plugin",
"version": "1.7.9"
"version": "1.8"
}
35 changes: 21 additions & 14 deletions dist/scripts/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scripts/fields.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/scripts/filters.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions dist/scripts/products.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/scripts/rest.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/scripts/utils.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fillauer-product-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Fillauer Product Importer
* Description: Import a CSV file to update products on the database
* Version: 1.7.9
* Version: 1.8
*/


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "product-importer",
"version": "1.7.9",
"version": "1.8",
"description": "Parse CSV for importing products",
"license": "(ISC OR GPL-3.0)",
"repository": "https://bitbucket.org/pyxlinc/pyxl",
Expand Down
24 changes: 17 additions & 7 deletions src/scripts/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { f } from './fields';

function combineUnitSpecs(parent) {
const combos = {};
console.log(parent);
Object.keys(parent.specs).forEach(specLabel => {
const lastBracket = specLabel.lastIndexOf(')');
if (-1 !== lastBracket) {
Expand All @@ -12,7 +11,6 @@ function combineUnitSpecs(parent) {
const unit = specLabel.substr(firstBracket, lastBracket);
if (!combos[base]) combos[base] = {};
combos[base][unit] = parent.specs[specLabel];
console.log(parent.specs[specLabel]);
// combos[base][unit].val += unit;
}
});
Expand Down Expand Up @@ -277,15 +275,27 @@ function combineVariationSpecs(parent) {

function fillBlankVariations(product) {
const totalSpecs = product.variations.labels.length;
// An array of false, set to true once seen used
// in a variation after all the optimization.
const specUsage = product.variations.labels.map(val => false);

// Figure out which specs are never usage (transformed into another spec)
product.variations.varies[0].forEach((variation, varyInd) => {
specUsage.forEach((used, ind) => {
if ('' !== variation.specs[ind]) {
specUsage[ind] = true;
}
});
});

// Skipping varies pagination that never got used
product.variations.varies[0].forEach((variation, varyInd) => {
// For each spec inside each variation, assign empty string if non-existent.
for (let i = 0; i < totalSpecs; i++) {
if (!variation.specs[i]) {
product.variations.varies[0][varyInd].specs[i] = ' ';
};
};
specUsage.forEach((used, ind) => {
if (used && !variation.specs[ind]) {
product.variations.varies[0][varyInd].specs[ind] = ' ';
}
});
});

return product;
Expand Down

0 comments on commit fcac120

Please sign in to comment.