Skip to content

Commit

Permalink
Initialize bundle from Excel Connector Bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux committed Aug 25, 2016
0 parents commit 4cd530f
Show file tree
Hide file tree
Showing 58 changed files with 2,583 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
vendor
composer.phar
composer.lock
/bin
26 changes: 26 additions & 0 deletions .travis.yml
@@ -0,0 +1,26 @@
language: php
sudo: false

php:
- 5.6
- 7.0

matrix:
allow_failures:
- php: 7.1

cache:
directories:
- $HOME/.composer/cache/files

before_install:
- echo "memory_limit=3G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- phpenv config-rm xdebug.ini
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

install:
- composer self-update --no-interaction
- composer update --no-interaction --no-scripts --prefer-dist

script:
- ./bin/phpspec run
7 changes: 7 additions & 0 deletions LICENCE.txt
@@ -0,0 +1,7 @@
Akeneo PIM

The Open Software License version 3.0

Copyright (c) 2014, Akeneo SAS.

Full license is at: http://opensource.org/licenses/OSL-3.0
68 changes: 68 additions & 0 deletions README.md
@@ -0,0 +1,68 @@
# Excel Installer Bundle

[![Build Status](https://travis-ci.org/akeneo/ExcelInitBundle.svg?branch=master)](https://travis-ci.org/akeneo/ExcelInitBundle)

![alt text](./src/Resources/doc/pictures/akeneo_excel.png "")

This bundle adds support of Excel XSLX files as a source for initializing catalog structure for [Akeneo PIM](https://github.com/akeneo/pim-community-standard).

**Note**: this bundle is not compatible with Excel 2003 xls files.

## Requirements

| ExcelInitBundle | Akeneo PIM Community Edition |
|:---------------:|:----------------------------:|
| v1.0.* | v1.6.* |

## Installation

From your application root:

```bash
php composer.phar require --prefer-dist akeneo/excel-installer-bundle:1.0.*
```

Enable the bundle in the `app/AppKernel.php` file in the `registerProjectBundles()` method:

```php
$bundles = [
// ...
new Pim\Bundle\ExcelInitBundle\PimExcelInitBundle(),
]
```

Now let's clean your cache and dump your assets:

```bash
php app/console cache:clear --env=prod
php app/console pim:installer:assets --env=prod
```

## Documentation

### Getting started

See [Resources/doc/Getting started](./Resources/doc/Getting-started.rst) for more details on how to set your catalog structure
using the [init.xslx](./Resources/fixtures/minimal/init.xlsx) file.

See [Resources/doc folder](./Resources/doc/Home.rst) for more details on how to set your catalog structure.

### Supported file

Input file must follow [init.xslx](./Resources/fixtures/minimal/init.xlsx) structure.
Note that the file must be opened with Excel.
LibreOffice/OpenOffice are not in compliance with validations data that are available in the spreadsheet.

### Importation job

This bundle allows you to import products files directly in the UI through Import > Import jobs.
Please note that the init.xlsx import is also available via the UI.
However, it should not be used as an import system for entities available within this file (families, categories, etc.) once the catalog structure has been set.

## Troubleshooting

###The import fails when importing families

Check that your channels names are correct in both family and channel tabs.
You might have a typo in the channels tab and not in the family tab.
You will have to remove the mispelled channel once you corrected this.
43 changes: 43 additions & 0 deletions composer.json
@@ -0,0 +1,43 @@
{
"name": "akeneo/excel-init-bundle",
"type": "symfony-bundle",
"description": "Akeneo PIM Excel initialization bundle",
"keywords": ["pim", "akeneo", "ecommerce", "e-commerce", "excel"],
"homepage": "http://www.akeneo.com",
"license": "OSL-3.0",
"authors": [
{
"name": "Akeneo",
"homepage": "http://www.akeneo.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/akeneo/pim-community-dev.git",
"branch": "master"
}
],
"require": {
"akeneo/pim-community-dev": "1.6.*@dev"
},
"require-dev": {
"phpspec/phpspec": "3.0.0",
"friendsofphp/php-cs-fixer": "@stable",
"squizlabs/php_codesniffer": "2.3.*",
"phpmd/phpmd": "2.3.*",
"henrikbjorn/phpspec-code-coverage": "3.0.1"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": { "Pim\\Bundle\\ExcelInitBundle\\": "src/" }
},
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
27 changes: 27 additions & 0 deletions spec/Pim/Bundle/ExcelInitBundle/Iterator/ArrayHelperSpec.php
@@ -0,0 +1,27 @@
<?php

namespace spec\Pim\Bundle\ExcelInitBundle\Iterator;

use PhpSpec\ObjectBehavior;

class ArrayHelperSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Pim\Bundle\ExcelInitBundle\Iterator\ArrayHelper');
}

function it_should_combine_arrays_with_less_keys_than_values()
{
$keys = array('key1', 'key2');
$values = array('value1', 'value2', 'value3');
$this->combineArrays($keys, $values)->shouldReturn(array('key1' => 'value1', 'key2' => 'value2'));
}

function it_should_combine_arrays_with_more_keys_than_values()
{
$keys = array('key1', 'key2', 'key3');
$values = array('value1', 'value2');
$this->combineArrays($keys, $values)->shouldReturn(array('key1' => 'value1', 'key2' => 'value2', 'key3' => ''));
}
}
@@ -0,0 +1,47 @@
<?php

namespace spec\Pim\Bundle\ExcelInitBundle\Iterator;

use PhpSpec\ObjectBehavior;
use Pim\Bundle\ExcelInitBundle\Mapper\AttributeTypeMapperInterface;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;

class InitAttributesFileIteratorSpec extends ObjectBehavior
{
public function let(AttributeTypeMapperInterface $attributeTypesMapper)
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy1.xlsx',
[
'header_key' => 'header1',
'include_worksheets' => ['/^Sheet4$/'],
'attribute_types_mapper' => $attributeTypesMapper,
]
);
}

public function it_must_have_a_mapper_as_option()
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy2.xlsx',
[
'header_key' => 'header1',
'include_worksheets' => ['/^Sheet4$/'],
]
);
$this->shouldThrow(MissingOptionsException::class)->duringInstantiation();
}

public function it_can_get_the_mapper($attributeTypesMapper)
{
$this->getAttributeTypesMapper()->shouldReturn($attributeTypesMapper);
}

private function getPath()
{
return __DIR__ . DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'fixtures';
}
}
120 changes: 120 additions & 0 deletions spec/Pim/Bundle/ExcelInitBundle/Iterator/InitFileIteratorSpec.php
@@ -0,0 +1,120 @@
<?php

namespace spec\Pim\Bundle\ExcelInitBundle\Iterator;

use PhpSpec\ObjectBehavior;

class InitFileIteratorSpec extends ObjectBehavior
{
public function it_can_read_multiple_tabs()
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy1.xlsx',
[
'header_key' => 'header1',
'include_worksheets' => ['/^Sheet1$/', '/^Sheet2$/'],
]
);
$this->rewind();
$values = [
['header1', 'header2', 'header3', 'header4', 'header5',],
['Value-1-1-1', 'Value-1-1-2', 'Value-1-1-3', 'Value-1-1-4', 'Value-1-1-5',],
['Value-1-2-1', 'Value-1-2-2', 'Value-1-2-3', 'Value-1-2-4', 'Value-1-2-5',],
['Value-1-3-1', 'Value-1-3-2', 'Value-1-3-3', 'Value-1-3-4', 'Value-1-3-5',],
['Value-1-4-1', 'Value-1-4-2', 'Value-1-4-3', 'Value-1-4-4', 'Value-1-4-5',],
['Value-1-5-1', 'Value-1-5-2', 'Value-1-5-3', 'Value-1-5-4', 'Value-1-5-5',],
['Value-2-1-1', 'Value-2-1-2', 'Value-2-1-3', 'Value-2-1-4', 'Value-2-1-5',],
['Value-2-2-1', 'Value-2-2-2', 'Value-2-2-3', 'Value-2-2-4', 'Value-2-2-5',],
['Value-2-3-1', 'Value-2-3-2', 'Value-2-3-3', 'Value-2-3-4', 'Value-2-3-5',],
['Value-2-4-1', 'Value-2-4-2', 'Value-2-4-3', 'Value-2-4-4', 'Value-2-4-5',],
['Value-2-5-1', 'Value-2-5-2', 'Value-2-5-3', 'Value-2-5-4', 'Value-2-5-5',],
];
foreach ($values as $row) {
$this->current()->shouldReturn($row);
$this->next();
}
$this->valid()->shouldReturn(false);
}

public function it_can_filter_excluded_tabs()
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy1.xlsx',
[
'header_key' => 'header1',
'exclude_worksheets' => ['/^Sheet[134]$/'],
]
);
$this->rewind();
$values = [
['header1', 'header2', 'header3', 'header4', 'header5',],
['Value-2-1-1', 'Value-2-1-2', 'Value-2-1-3', 'Value-2-1-4', 'Value-2-1-5',],
['Value-2-2-1', 'Value-2-2-2', 'Value-2-2-3', 'Value-2-2-4', 'Value-2-2-5',],
['Value-2-3-1', 'Value-2-3-2', 'Value-2-3-3', 'Value-2-3-4', 'Value-2-3-5',],
['Value-2-4-1', 'Value-2-4-2', 'Value-2-4-3', 'Value-2-4-4', 'Value-2-4-5',],
['Value-2-5-1', 'Value-2-5-2', 'Value-2-5-3', 'Value-2-5-4', 'Value-2-5-5',],
];
foreach ($values as $row) {
$this->current()->shouldReturn($row);
$this->next();
}
$this->valid()->shouldReturn(false);
}

public function it_can_filter_included_and_excluded_tabs()
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy1.xlsx',
[
'header_key' => 'header1',
'include_worksheets' => ['/^Sheet1$/', '/^Sheet2$/'],
'exclude_worksheets' => ['/^Sheet1$/'],
]
);
$this->rewind();
$values = [
['header1', 'header2', 'header3', 'header4', 'header5',],
['Value-2-1-1', 'Value-2-1-2', 'Value-2-1-3', 'Value-2-1-4', 'Value-2-1-5',],
['Value-2-2-1', 'Value-2-2-2', 'Value-2-2-3', 'Value-2-2-4', 'Value-2-2-5',],
['Value-2-3-1', 'Value-2-3-2', 'Value-2-3-3', 'Value-2-3-4', 'Value-2-3-5',],
['Value-2-4-1', 'Value-2-4-2', 'Value-2-4-3', 'Value-2-4-4', 'Value-2-4-5',],
['Value-2-5-1', 'Value-2-5-2', 'Value-2-5-3', 'Value-2-5-4', 'Value-2-5-5',],
];
}

public function it_can_use_a_different_valdata_range()
{
$this->beConstructedWith(
'xlsx',
$this->getPath() . DIRECTORY_SEPARATOR . 'dummy1.xlsx',
[
'header_key' => 'header1',
'include_worksheets' => ['/^Sheet3$/'],
]
);
$this->rewind();
$values = [
['header1', 'header2', 'header3', 'header4', 'header5',],
['Value-3-1-1', 'Value-3-1-2', 'Value-3-1-3', 'Value-3-1-4', 'Value-3-1-5',],
['Value-3-2-1', 'Value-3-2-2', 'Value-3-2-3', 'Value-3-2-4', 'Value-3-2-5',],
['Value-3-3-1', 'Value-3-3-2', 'Value-3-3-3', 'Value-3-3-4', 'Value-3-3-5',],
['Value-3-4-1', 'Value-3-4-2', 'Value-3-4-3', 'Value-3-4-4', 'Value-3-4-5',],
['Value-3-5-1', 'Value-3-5-2', 'Value-3-5-3', 'Value-3-5-4', 'Value-3-5-5',],
];
foreach ($values as $row) {
$this->current()->shouldReturn($row);
$this->next();
}
$this->valid()->shouldReturn(false);
}


private function getPath()
{
return __DIR__ . DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'fixtures';
}
}
30 changes: 30 additions & 0 deletions spec/Pim/Bundle/ExcelInitBundle/Mapper/AttributeTypeMapperSpec.php
@@ -0,0 +1,30 @@
<?php

namespace spec\Pim\Bundle\ExcelInitBundle\Mapper;

use PhpSpec\ObjectBehavior;

class AttributeTypeMapperSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldImplement('Pim\Bundle\ExcelInitBundle\Mapper\AttributeTypeMapperInterface');
}

function it_should_get_mapped_attribute_types()
{
$this->addAttributeTypeMapping('label1', 'type1');
$this->addAttributeTypeMapping('label2', 'type2');

$this->getMappedValue('label1')->shouldReturn('type1');
$this->getMappedValue('label2')->shouldReturn('type2');
}

function it_should_return_null_for_non_mapped_attribute_types()
{
$this->addAttributeTypeMapping('label1', 'type1');
$this->addAttributeTypeMapping('label2', 'type2');

$this->getMappedValue('label3')->shouldReturn(null);
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 4cd530f

Please sign in to comment.