Skip to content

Commit

Permalink
release 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-bigbridge committed Nov 13, 2020
1 parent 236d66e commit 7164c29
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 109 deletions.
4 changes: 2 additions & 2 deletions Api/Data/BundleProductSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(string $sku, bool $isDefault, int $priceType, string
$this->sku = trim($sku);
$this->isDefault = $isDefault;
$this->priceType = $priceType;
$this->priceValue = Decimal::format($priceValue);
$this->priceValue = Decimal::formatPrice($priceValue);
$this->quantity = Decimal::format($quantity);
$this->canChangeQuantity = $canChangeQuantity;
}
Expand Down Expand Up @@ -111,4 +111,4 @@ public function setProductId(int $productId)
{
$this->productId = $productId;
}
}
}
4 changes: 2 additions & 2 deletions Api/Data/CustomOptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CustomOptionValue

public function __construct(string $price, string $priceType, string $title)
{
$this->price = Decimal::format($price);
$this->price = Decimal::formatPrice($price);
$this->priceType = trim($priceType);
$this->title = trim($title);
}
Expand Down Expand Up @@ -48,4 +48,4 @@ public function getTitle(): string
{
return $this->title;
}
}
}
6 changes: 3 additions & 3 deletions Api/Data/ProductStoreView.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public function setMetaKeywords(string $metaKeywords = null)
}

/**
* @param string|null $price A 12.4 decimal field
* @param string|null $price A 12.4 / 20.6 decimal field
*/
public function setPrice(string $price = null)
{
$this->attributes[self::ATTR_PRICE] = Decimal::format($price);
$this->attributes[self::ATTR_PRICE] = Decimal::formatPrice($price);
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ public function setWeight(string $weight = null)
*/
public function setSpecialPrice(string $specialPrice = null)
{
$this->attributes[self::ATTR_SPECIAL_PRICE] = Decimal::format($specialPrice);
$this->attributes[self::ATTR_SPECIAL_PRICE] = Decimal::formatPrice($specialPrice);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Api/Data/TierPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TierPrice
public function __construct(string $quantity, string $value, string $customerGroupName = null, string $websiteCode = null, string $percentageValue = null)
{
$this->quantity = Decimal::format($quantity);
$this->value = Decimal::format($value);
$this->value = Decimal::formatPrice($value);
$this->customerGroupName = $customerGroupName;
$this->websiteCode = $websiteCode;
$this->percentageValue = $percentageValue !== null ? Decimal::format($percentageValue) : null;
Expand Down Expand Up @@ -111,4 +111,4 @@ public function setCustomerGroupId(int $customerGroupId)
{
$this->customerGroupId = $customerGroupId;
}
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.5.2 : Support for Magento 2.4

Support for 20.6 price decimal format.

Fixed import of tier prices in M2.4

## 1.5.1 : Fix XSD for multiple store views

The XSD that validates the product import XML did not allow multiple store views.
Expand Down
34 changes: 33 additions & 1 deletion Helper/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class Decimal
const DECIMAL_PATTERN = '/^-?(\d{0,12}\.\d{0,4}|\d{1,12})$/';
const DECIMAL_FORMAT = "%.4f";

const DECIMAL_20_6_PATTERN = '/^-?(\d{0,20}\.\d{0,6}|\d{1,20})$/';
const DECIMAL_20_6_FORMAT = "%.6f";

public static $decimalPricePattern = self::DECIMAL_PATTERN;
public static $decimalPriceFormat = self::DECIMAL_FORMAT;

public static $decimalEavPattern = self::DECIMAL_PATTERN;
public static $decimalEavFormat = self::DECIMAL_FORMAT;

/**
* Formats $in with 4 decimals.
* If $in is not a number, it is left unchanged.
Expand All @@ -32,4 +41,27 @@ public static function format(string $in = null)
}
}
}
}

/**
* Formats $in with 4 / 6 decimals.
* If $in is not a number, it is left unchanged.
*
* @param string|null $in
* @return string|null
*/
public static function formatPrice(string $in = null)
{
if ($in === null) {
return $in;
} else {

$in = trim($in);

if (!preg_match(self::$decimalPricePattern, $in)) {
return $in;
} else {
return sprintf(self::$decimalPriceFormat, $in);
}
}
}
}
4 changes: 2 additions & 2 deletions Model/Data/CustomOptionPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomOptionPrice
public function __construct(CustomOption $customOption, string $price, string $priceType)
{
$this->customOption = $customOption;
$this->price = Decimal::format($price);
$this->price = Decimal::formatPrice($price);
$this->priceType = trim($priceType);
}

Expand Down Expand Up @@ -50,4 +50,4 @@ public function getCustomOption(): CustomOption
return $this->customOption;
}

}
}
4 changes: 2 additions & 2 deletions Model/Data/DownloadLinkInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(DownloadLink $downloadLink, string $title, string $p
{
$this->downloadLink = $downloadLink;
$this->title = trim($title);
$this->price = Decimal::format($price);
$this->price = Decimal::formatPrice($price);
}

/**
Expand All @@ -49,4 +49,4 @@ public function getPrice(): string
{
return $this->price;
}
}
}
32 changes: 23 additions & 9 deletions Model/Resource/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BigBridge\ProductImport\Api\Data\Product;
use BigBridge\ProductImport\Api\Data\ProductStoreView;
use BigBridge\ProductImport\Helper\Decimal;
use BigBridge\ProductImport\Model\Data\EavAttributeInfo;
use BigBridge\ProductImport\Model\Data\LinkInfo;
use BigBridge\ProductImport\Model\Persistence\Magento2DbConnection;
Expand Down Expand Up @@ -393,6 +394,10 @@ public function reloadCache()
if (version_compare($this->magentoVersion, "2.3.0") >= 0) {
$this->sourceCodeMap = $this->getSourceCodeMap();
}

if (version_compare($this->magentoVersion, "2.4.0") >= 0) {
$this->setNewPriceDecimals();
}
}

/**
Expand Down Expand Up @@ -421,6 +426,15 @@ protected function detectMagentoVersion()
return $magentoVersion;
}

protected function setNewPriceDecimals()
{
Decimal::$decimalPriceFormat = Decimal::DECIMAL_20_6_FORMAT;
Decimal::$decimalPricePattern = Decimal::DECIMAL_20_6_PATTERN;

Decimal::$decimalEavFormat = Decimal::DECIMAL_20_6_FORMAT;
Decimal::$decimalEavPattern = Decimal::DECIMAL_20_6_PATTERN;
}

protected function getValueSerializer()
{
if (version_compare($this->magentoVersion, '2.2.0') >= 0) {
Expand Down Expand Up @@ -589,7 +603,7 @@ protected function getCategoryAttributeMap()
protected function getProductEavAttributeInfo()
{
$rows = $this->db->fetchAllAssoc("
SELECT A.`attribute_id`, A.`attribute_code`, A.`is_required`, A.`backend_type`, A.`frontend_input`, C.`is_global`
SELECT A.`attribute_id`, A.`attribute_code`, A.`is_required`, A.`backend_type`, A.`frontend_input`, C.`is_global`
FROM {$this->attributeTable} A
INNER JOIN {$this->catalogAttributeTable} C ON C.`attribute_id` = A.`attribute_id`
WHERE A.`entity_type_id` = ? AND A.backend_type != 'static'
Expand Down Expand Up @@ -643,8 +657,8 @@ protected function getMediaGalleryAttributeId()
$attributeTable = $this->db->getFullTableName(self::ATTRIBUTE_TABLE);

return $this->db->fetchSingleCell("
SELECT `attribute_id`
FROM {$attributeTable}
SELECT `attribute_id`
FROM {$attributeTable}
WHERE `entity_type_id` = ? AND attribute_code = 'media_gallery'
", [
$this->productEntityTypeId
Expand Down Expand Up @@ -672,9 +686,9 @@ protected function getProductUrlSuffixes()
// note: IFNULL will not do, because the suffix value may actually be null
$suffixes = $this->db->fetchMap("
SELECT
s.`store_id`,
IF(cs.scope = 'stores', cs.value,
IF(cw.scope = 'websites', cw.value,
s.`store_id`,
IF(cs.scope = 'stores', cs.value,
IF(cw.scope = 'websites', cw.value,
IF(cd.scope = 'default', cd.value, ?))) AS suffix
FROM `store` s
LEFT JOIN `{$this->configDataTable}` cd ON cd.path = 'catalog/seo/product_url_suffix' AND cd.scope = 'default'
Expand Down Expand Up @@ -705,9 +719,9 @@ protected function getCategoryUrlSuffixes()
// note: IFNULL will not do, because the suffix value may actually be null
$suffixes = $this->db->fetchMap("
SELECT
s.`store_id`,
IF(cs.scope = 'stores', cs.value,
IF(cw.scope = 'websites', cw.value,
s.`store_id`,
IF(cs.scope = 'stores', cs.value,
IF(cw.scope = 'websites', cw.value,
IF(cd.scope = 'default', cd.value, ?))) AS suffix
FROM `store` s
LEFT JOIN `{$this->configDataTable}` cd ON cd.path = 'catalog/seo/category_url_suffix' AND cd.scope = 'default'
Expand Down
17 changes: 14 additions & 3 deletions Model/Resource/Storage/TierPriceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BigBridge\ProductImport\Model\Resource\Storage;

use BigBridge\ProductImport\Api\Data\Product;
use BigBridge\ProductImport\Helper\Decimal;
use BigBridge\ProductImport\Model\Persistence\Magento2DbConnection;
use BigBridge\ProductImport\Model\Resource\MetaData;

Expand Down Expand Up @@ -142,12 +143,22 @@ protected function removeOutdatedStoredTierPrices(array $products)

// collect tier prices that are stored in the database
$storedTierPriceData = $this->db->fetchAllAssoc("
SELECT `value_id`, `entity_id`, `all_groups`, `customer_group_id`, `qty`, `value`, `website_id`,
CONCAT_WS(' ', `entity_id`, `all_groups`, `customer_group_id`, `qty`, `value`, `website_id`) as serialized
SELECT `value_id`, `entity_id`, `all_groups`, `customer_group_id`, `qty`, `value`, `website_id`
FROM `{$this->metaData->tierPriceTable}`
WHERE `entity_id` IN (" . $this->db->getMarks($productIds) . ")
", $productIds);

foreach ($storedTierPriceData as &$storedTierPriceDatum) {
$storedTierPriceDatum['serialized'] = sprintf("%s %s %s %s %s %s",
$storedTierPriceDatum['entity_id'],
(int)$storedTierPriceDatum['all_groups'],
(int)$storedTierPriceDatum['customer_group_id'],
Decimal::format($storedTierPriceDatum['qty']),
Decimal::formatPrice($storedTierPriceDatum['value']),
(int)$storedTierPriceDatum['website_id']
);
}

// serialize current tier prices
$activeTierPriceData = [];
foreach ($products as $product) {
Expand Down Expand Up @@ -178,4 +189,4 @@ protected function removeOutdatedStoredTierPrices(array $products)
// remove the outdated tier prices
$this->db->deleteMultiple($this->metaData->tierPriceTable, 'value_id', $removableValueIds);
}
}
}
2 changes: 1 addition & 1 deletion Model/Resource/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function validate(Product $product)
}
break;
case EavAttributeInfo::TYPE_DECIMAL:
if (!preg_match(Decimal::DECIMAL_PATTERN, $value)) {
if (!preg_match(Decimal::$decimalEavPattern, $value)) {
$product->addError($eavAttribute . " is not a decimal number with dot (" . $value . ")");
} elseif ($value < 0.00) {
if (in_array($eavAttribute, [ProductStoreView::ATTR_PRICE, ProductStoreView::ATTR_SPECIAL_PRICE, ProductStoreView::ATTR_COST, ProductStoreView::ATTR_WEIGHT, ProductStoreView::ATTR_MSRP])) {
Expand Down
4 changes: 2 additions & 2 deletions Test/ApiFunctional/RestApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RestApiTest extends \PHPUnit\Framework\TestCase
const TEST_ADMIN_USER_USERNAME = 'admin';//\Magento\TestFramework\Bootstrap::ADMIN_NAME;
const TEST_ADMIN_USER_PASSWORD = 'admin123';//\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
// include Magento
require_once __DIR__ . '/../../../../../index.php';
Expand Down Expand Up @@ -69,4 +69,4 @@ public function testRestApi()
$this->assertEquals("false", $xml->error_occurred);
$this->assertEquals(1, preg_match('/Dry run/', $xml->output));
}
}
}
4 changes: 2 additions & 2 deletions Test/Benchmark/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MemoryTest extends \Magento\TestFramework\TestCase\AbstractController
/** @var ImporterFactory */
private static $factory;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

Expand Down Expand Up @@ -203,4 +203,4 @@ public function updateProducts($skus, $categories, Importer $importer)

$importer->flush();
}
}
}
4 changes: 2 additions & 2 deletions Test/Integration/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConfigTest extends \Magento\TestFramework\TestCase\AbstractController
/** @var ImporterFactory */
private static $factory;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

Expand Down Expand Up @@ -78,4 +78,4 @@ public function testConfig()
$this->assertEquals(null, $config->dryRun);

}
}
}
4 changes: 2 additions & 2 deletions Test/Integration/IdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IdTest extends \Magento\TestFramework\TestCase\AbstractController
/** @var Metadata */
protected static $metadata;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

Expand Down Expand Up @@ -98,4 +98,4 @@ public function testUpdateById()

$this->assertEquals(['Id does not belong to existing product: -1'], $errors);
}
}
}
Loading

0 comments on commit 7164c29

Please sign in to comment.