diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d499a2..7dd52cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,6 @@ # PIMGento API change Log + +### 100.1.1 : +Fix price set to 0 if attribute price is empty + +Fix media import with wrong entity_type_id diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4873ee1..755834a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,5 +16,5 @@ Contributing policy **You can not commit directly on this repository.** -Fork the project, create a feature branch, and send a pull request. +Fork the project, create a feature branch, and send a pull request on the develop branch. diff --git a/app/code/community/Pimgento/Api/Model/Job/Product.php b/app/code/community/Pimgento/Api/Model/Job/Product.php index 825853e..9bbb7ce 100644 --- a/app/code/community/Pimgento/Api/Model/Job/Product.php +++ b/app/code/community/Pimgento/Api/Model/Job/Product.php @@ -49,6 +49,30 @@ class Pimgento_Api_Model_Job_Product extends Pimgento_Api_Model_Job_Abstract * @var string[] */ protected $allowedTypeId = ['simple', 'virtual']; + /** + * List of column to exclude from attribute value setting + * + * @var string[] + */ + protected $excludedColumns = [ + '_entity_id', + '_is_new', + '_status', + '_type_id', + '_options_container', + '_tax_class_id', + '_attribute_set_id', + '_visibility', + '_children', + '_axes', + 'code', + 'sku', + 'categories', + 'family', + 'groups', + 'parent', + 'enabled', + ]; /** * Pimgento_Api_Model_Job_Product constructor @@ -250,7 +274,7 @@ public function updateColumns($task) if ($connection->tableColumnExists($tmpTable, 'type_id')) { /** @var string $types */ - $types = $connection->quote($this->allowedTypeId); + $types = $connection->quote($this->getAllowedTypeId()); $connection->update( $tmpTable, [ @@ -543,25 +567,9 @@ public function updateOption($task) $columns = array_keys($connection->describeTable($tmpTable)); /** @var string[] $except */ $except = [ - '_entity_id', - '_is_new', - '_status', - '_type_id', - '_options_container', - '_tax_class_id', - '_attribute_set_id', - '_visibility', - '_children', - '_axes', - 'code', - 'sku', - 'categories', - 'family', - 'groups', - 'parent', 'url_key', - 'enabled', ]; + $except = array_merge($except, $this->getExcludedColumns()); /** @var string $column */ foreach ($columns as $column) { @@ -691,25 +699,6 @@ public function setValues($task) $stores = $storeHelper->getAllStores(); /** @var string[] $columns */ $columns = array_keys($connection->describeTable($tmpTable)); - /** @var string[] $except */ - $except = [ - '_entity_id', - '_is_new', - '_status', - '_type_id', - '_options_container', - '_tax_class_id', - '_attribute_set_id', - '_visibility', - '_children', - '_axes', - 'sku', - 'categories', - 'family', - 'groups', - 'parent', - 'enabled', - ]; /** @var mixed[] $values */ $values = [ 0 => [ @@ -725,7 +714,7 @@ public function setValues($task) /** @var string $column */ foreach ($columns as $column) { - if (in_array($column, $except) || preg_match('/-unit/', $column)) { + if (in_array($column, $this->getExcludedColumns()) || preg_match('/-unit/', $column)) { continue; } @@ -1350,10 +1339,11 @@ public function importMedia($task) } /** @var mixed[] $data */ $data = [ - 'attribute_id' => $column['attribute'], - 'store_id' => 0, - 'entity_id' => $row['entity_id'], - 'value' => $file, + 'attribute_id' => $column['attribute'], + 'store_id' => 0, + 'entity_id' => $row['entity_id'], + 'entity_type_id' => new Zend_Db_Expr($this->getProductEntityTypeId()), + 'value' => $file, ]; $connection->insertOnDuplicate($productImageTable, $data, array_keys($data)); } @@ -1627,7 +1617,7 @@ public function getProductEntityTypeId() } /** - * Retrieve product entity type id + * Retrieve product default attribute set id * * @return int */ @@ -1638,4 +1628,14 @@ public function getProductDefaultAttributeSetId() return $entitiesHelper->getProductDefaultAttributeSetId(); } + + /** + * Retrieve excluded columns + * + * @return string[] + */ + public function getExcludedColumns() + { + return $this->excludedColumns; + } } diff --git a/app/code/community/Pimgento/Api/Model/Resource/Entities.php b/app/code/community/Pimgento/Api/Model/Resource/Entities.php index a4e6bcd..4e1fea8 100644 --- a/app/code/community/Pimgento/Api/Model/Resource/Entities.php +++ b/app/code/community/Pimgento/Api/Model/Resource/Entities.php @@ -54,6 +54,14 @@ class Pimgento_Api_Model_Resource_Entities extends Mage_Core_Model_Resource_Db_A * @var string[] $columnNames */ protected $columnNames = []; + /** + * Product attributes to pass if empty value + * + * @var string[] $passIfEmpty + */ + protected $passIfEmpty = [ + 'price', + ]; /** * Resource initialization @@ -89,6 +97,16 @@ public function setEntityCode($entityCode) return $this; } + /** + * Retrieve attributes to pass if empty value + * + * @return string[] + */ + public function getPassIfEmpty() + { + return $this->passIfEmpty; + } + /** * Create pimgento_api/entities table * @@ -591,7 +609,7 @@ public function setValues( continue; } - if ($attribute['backend_type'] === 'static') { + if (empty($attribute['backend_type']) || $attribute['backend_type'] === 'static') { continue; } @@ -609,10 +627,8 @@ public function setValues( /** @var bool $columnExists */ $columnExists = $this->columnExists($tableName, $value); - /** @var int $productEntityTypeId */ - $productEntityTypeId = Mage::helper('pimgento_api/entities')->getProductEntityTypeId(); - if ($columnExists && $entityCode !== self::ENTITY_CODE_PRODUCT && $entityTypeId !== $productEntityTypeId) { - $select->where(sprintf('TRIM(`%s`) <> ?', $value), new Zend_Db_Expr('""')); + if ($columnExists && ($entityCode !== self::ENTITY_CODE_PRODUCT || in_array($code, $this->getPassIfEmpty()))) { + $select->where(sprintf('TRIM(`%s`) > ?', $value), new Zend_Db_Expr('""')); } /** @var string $backendType */