View source
<?php
namespace Drupal\Tests\commerce_feeds\Kernel\Target;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\Tests\commerce_feeds\Kernel\CommerceFeedsKernelTestBase;
class PriceTest extends CommerceFeedsKernelTestBase {
protected $feedType;
public function setUp() {
parent::setUp();
$this->feedType = $this
->createFeedTypeForCsv([
'sku' => 'sku',
'title' => 'title',
'price' => 'price',
], [
'processor' => 'entity:commerce_product_variation',
'processor_configuration' => [
'authorize' => FALSE,
'values' => [
'type' => 'default',
],
],
'mappings' => [
[
'target' => 'sku',
'map' => [
'value' => 'sku',
],
'unique' => [
'value' => TRUE,
],
],
[
'target' => 'title',
'map' => [
'value' => 'title',
],
],
],
]);
}
public function testImportSellPrice() {
$this->feedType
->addMapping([
'target' => 'price',
'map' => [
'number' => 'price',
],
'settings' => [
'currency_code' => 'USD',
],
]);
$this->feedType
->save();
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/product_variations.csv',
]);
$feed
->import();
$variations = ProductVariation::loadMultiple();
$this
->assertCount(3, $variations);
$expected = [
1 => 100,
2 => 24.52,
3 => 0,
];
foreach ($expected as $id => $value) {
$price = $variations[$id]
->getPrice();
$this
->assertEquals($value, $price
->getNumber());
$this
->assertEquals('USD', $price
->getCurrencyCode());
}
}
}