-
Notifications
You must be signed in to change notification settings - Fork 82
/
PriceListAdditionalProductPriceReader.php
87 lines (72 loc) · 2.64 KB
/
PriceListAdditionalProductPriceReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Oro\Bundle\PricingBundle\ImportExport\Reader;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Oro\Bundle\ImportExportBundle\Context\ContextInterface;
use Oro\Bundle\ImportExportBundle\Context\ContextRegistry;
use Oro\Bundle\ImportExportBundle\Reader\IteratorBasedReader;
use Oro\Bundle\PricingBundle\Entity\PriceList;
use Oro\Bundle\PricingBundle\Entity\Repository\PriceListToProductRepository;
use Oro\Bundle\PricingBundle\ImportExport\Reader\Iterator\AdditionalProductPricesIterator;
use Oro\Bundle\PricingBundle\Sharding\ShardManager;
class PriceListAdditionalProductPriceReader extends IteratorBasedReader
{
/**
* @var ShardManager
*/
protected $shardManager;
/**
* @var int
*/
protected $priceListId;
/**
* @var ManagerRegistry
*/
protected $registry;
/**
* @param ContextRegistry $contextRegistry
* @param ManagerRegistry $registry
* @param ShardManager $shardManager
*/
public function __construct(
ContextRegistry $contextRegistry,
ManagerRegistry $registry,
ShardManager $shardManager
) {
parent::__construct($contextRegistry);
$this->registry = $registry;
$this->shardManager = $shardManager;
}
/**
* {@inheritdoc}
*/
protected function initializeFromContext(ContextInterface $context)
{
$this->priceListId = (int)$context->getOption('price_list_id');
$this->setSourceIterator($this->createIterator());
$configuration = $this->stepExecution->getJobExecution()->getJobInstance()->getRawConfiguration();
$configuration['export']['firstLineIsHeader'] = false;
$this->stepExecution->getJobExecution()->getJobInstance()->setRawConfiguration($configuration);
parent::initializeFromContext($context);
}
/**
* @return \Iterator
*/
protected function createIterator()
{
if ($this->priceListId) {
/** @var EntityManager $em */
$em = $this->registry->getManagerForClass('OroPricingBundle:PriceListToProduct');
/** @var PriceListToProductRepository $repository */
$repository = $em->getRepository('OroPricingBundle:PriceListToProduct');
/** @var PriceList $priceList */
$priceList = $em->getReference('OroPricingBundle:PriceList', $this->priceListId);
return new AdditionalProductPricesIterator(
$repository->getProductsWithoutPrices($this->shardManager, $priceList),
$priceList
);
} else {
return new \ArrayIterator();
}
}
}