Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/100.1.1 #6

Merged
merged 7 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

86 changes: 43 additions & 43 deletions app/code/community/Pimgento/Api/Model/Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
[
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => [
Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -1627,7 +1617,7 @@ public function getProductEntityTypeId()
}

/**
* Retrieve product entity type id
* Retrieve product default attribute set id
*
* @return int
*/
Expand All @@ -1638,4 +1628,14 @@ public function getProductDefaultAttributeSetId()

return $entitiesHelper->getProductDefaultAttributeSetId();
}

/**
* Retrieve excluded columns
*
* @return string[]
*/
public function getExcludedColumns()
{
return $this->excludedColumns;
}
}
26 changes: 21 additions & 5 deletions app/code/community/Pimgento/Api/Model/Resource/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -591,7 +609,7 @@ public function setValues(
continue;
}

if ($attribute['backend_type'] === 'static') {
if (empty($attribute['backend_type']) || $attribute['backend_type'] === 'static') {
continue;
}

Expand All @@ -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 */
Expand Down