diff --git a/src/Console/Command/CustomersExport.php b/src/Console/Command/CustomersExport.php
index ceb538d..1f5cc00 100644
--- a/src/Console/Command/CustomersExport.php
+++ b/src/Console/Command/CustomersExport.php
@@ -59,7 +59,7 @@ class CustomersExport extends Command
*
* @throws \Exception
*
- * @return boolean
+ * @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -89,7 +89,7 @@ class CustomersExport extends Command
if (empty($customers)) {
$output->writeln('Customers not found');
- return false;
+ return 0;
}
/** @var \Magento\Customer\Model\Customer $customer */
@@ -112,6 +112,6 @@ class CustomersExport extends Command
$output->writeln('Uploading customers finished');
- return true;
+ return 0;
}
}
diff --git a/src/Console/Command/IcmlGenerate.php b/src/Console/Command/IcmlGenerate.php
new file mode 100644
index 0000000..7f76278
--- /dev/null
+++ b/src/Console/Command/IcmlGenerate.php
@@ -0,0 +1,79 @@
+icml = $icml;
+ $this->storeManager = $storeManager;
+ $this->appState = $appState;
+
+ parent::__construct();
+ }
+
+ protected function configure()
+ {
+ $this->setName('retailcrm:icml:generate')
+ ->setDescription('Generating ICML catalog in root directory')
+ ->addArgument('website', InputArgument::OPTIONAL, 'Website id');
+
+ parent::configure();
+ }
+
+ /**
+ * Generate ICML catalog
+ *
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws \Exception
+ *
+ * @return int
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
+
+ $arguments = $input->getArguments();
+ $websites = [];
+
+ if (isset($arguments['website'])) {
+ $websites[] = $this->storeManager->getWebsite($arguments['website']);
+ } else {
+ $websites = $this->storeManager->getWebsites();
+ }
+
+ if (!$websites) {
+ $output->writeln('Websites not found');
+
+ return 0;
+ }
+
+ foreach ($websites as $website) {
+ try {
+ $this->icml->generate($website);
+ } catch (\Exception $exception) {
+ $output->writeln('' . $exception->getMessage() . '');
+
+ return 1;
+ }
+
+ }
+
+ return 0;
+ }
+}
diff --git a/src/Model/Icml/Icml.php b/src/Model/Icml/Icml.php
index 3acf1c9..7cb770e 100644
--- a/src/Model/Icml/Icml.php
+++ b/src/Model/Icml/Icml.php
@@ -20,6 +20,8 @@ class Icml
private $searchCriteriaBuilder;
private $productRepository;
+ const DIMENSION_FIELDS = ['height', 'length', 'width'];
+
public function __construct(
\Magento\Store\Model\StoreManagerInterface $manager,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
@@ -217,6 +219,20 @@ class Icml
);
}
+ if (!empty($offer['dimensions'])) {
+ $e->appendChild($this->dd->createElement('dimensions'))
+ ->appendChild(
+ $this->dd->createTextNode($offer['dimensions'])
+ );
+ }
+
+ if (!empty($offer['weight'])) {
+ $e->appendChild($this->dd->createElement('weight'))
+ ->appendChild(
+ $this->dd->createTextNode($offer['weight'])
+ );
+ }
+
if (!empty($offer['params'])) {
foreach ($offer['params'] as $param) {
$paramNode = $this->dd->createElement('param');
@@ -309,8 +325,16 @@ class Icml
$offer['vendor'] = $associatedProduct === null
? $product->getAttributeText('manufacturer')
: $associatedProduct->getAttributeText('manufacturer');
+ $offer['weight'] = $associatedProduct === null
+ ? $product->getWeight()
+ : $associatedProduct->getWeight();
- $offer['params'] = $this->getOfferParams($product, $customAdditionalAttributes, $associatedProduct);
+ $params = $this->getOfferParams($product, $customAdditionalAttributes, $associatedProduct);
+
+ $offer['params'] = $params['params'];
+ $offer['dimensions'] = $params['dimensions'];
+
+ unset($params);
return $offer;
}
@@ -333,8 +357,16 @@ class Icml
}
$attributes = explode(',', $customAdditionalAttributes);
+ $dimensionsAttrs = [];
+ $dimensions = '';
foreach ($attributes as $attributeCode) {
+ if ($this->checkDimension($attributeCode) !== false) {
+ $dimensionsAttrs += $this->checkDimension($attributeCode);
+
+ continue;
+ }
+
$attribute = $this->resourceModelProduct->getAttribute($attributeCode);
$attributeValue = $associatedProduct
? $associatedProduct->getData($attributeCode)
@@ -350,7 +382,28 @@ class Icml
}
}
- return $params;
+ if ($dimensionsAttrs && count($dimensionsAttrs) == 3) {
+ $length = $associatedProduct
+ ? $associatedProduct->getData($dimensionsAttrs['length'])
+ : $product->getData($dimensionsAttrs['length']);
+ $width = $associatedProduct
+ ? $associatedProduct->getData($dimensionsAttrs['width'])
+ : $product->getData($dimensionsAttrs['width']);
+ $height = $associatedProduct
+ ? $associatedProduct->getData($dimensionsAttrs['height'])
+ : $product->getData($dimensionsAttrs['height']);
+
+ if ($length && $width && $height) {
+ $dimensions = sprintf(
+ '%s/%s/%s',
+ $length,
+ $width,
+ $height
+ );
+ }
+ }
+
+ return ['params' => $params, 'dimensions' => $dimensions];
}
/**
@@ -383,4 +436,20 @@ class Icml
return $quantity;
}
+
+ /**
+ * @param string $attrCode
+ *
+ * @return mixed
+ */
+ private function checkDimension($attrCode)
+ {
+ foreach (self::DIMENSION_FIELDS as $dimensionField) {
+ if (mb_strpos($attrCode, $dimensionField) !== false) {
+ return [$dimensionField => $attrCode];
+ }
+ }
+
+ return false;
+ }
}
diff --git a/src/Model/Setting/Attribute.php b/src/Model/Setting/Attribute.php
index de7ea42..b0a8ed5 100644
--- a/src/Model/Setting/Attribute.php
+++ b/src/Model/Setting/Attribute.php
@@ -24,6 +24,7 @@ class Attribute implements \Magento\Framework\Option\ArrayInterface
'select',
'price'
];
+
$attributes = $this->entityType->loadByCode('catalog_product')->getAttributeCollection();
$attributes->addFieldToFilter('frontend_input', $types);
diff --git a/src/etc/di.xml b/src/etc/di.xml
index b317515..cb1a3c2 100644
--- a/src/etc/di.xml
+++ b/src/etc/di.xml
@@ -13,6 +13,7 @@
- Retailcrm\Retailcrm\Console\Command\OrdersExport
- Retailcrm\Retailcrm\Console\Command\CustomersExport
+ - Retailcrm\Retailcrm\Console\Command\IcmlGenerate