@@ 32-47 (lines=16) @@ | ||
29 | /** {@inheritdoc} */ |
|
30 | public $queryClass = SaleQuery::class; |
|
31 | ||
32 | public function findId(SaleInterface $sale) |
|
33 | { |
|
34 | if ($sale->hasId()) { |
|
35 | return $sale->getId(); |
|
36 | } |
|
37 | $hstore = new HstoreExpression(array_filter([ |
|
38 | 'buyer' => $sale->getCustomer()->getLogin(), |
|
39 | 'buyer_id' => $sale->getCustomer()->getId(), |
|
40 | 'object_id' => $sale->getTarget()->getId(), |
|
41 | 'tariff_id' => $sale->getPlan()->getId(), |
|
42 | ])); |
|
43 | $call = new CallExpression('sale_id', [$hstore]); |
|
44 | $command = (new Query())->select($call); |
|
45 | ||
46 | return $command->scalar($this->db); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @param OrderInterface $order |
|
@@ 116-127 (lines=12) @@ | ||
113 | /** |
|
114 | * @param SaleInterface $sale |
|
115 | */ |
|
116 | public function save(SaleInterface $sale) |
|
117 | { |
|
118 | $hstore = new HstoreExpression([ |
|
119 | 'object_id' => $sale->getTarget()->getId(), |
|
120 | 'contact_id' => $sale->getCustomer()->getId(), |
|
121 | 'tariff_id' => $sale->getPlan() ? $sale->getPlan()->getId() : null, |
|
122 | 'time' => $sale->getTime()->format('c'), |
|
123 | ]); |
|
124 | $call = new CallExpression('sale_object', [$hstore]); |
|
125 | $command = (new Query())->select($call); |
|
126 | $sale->setId($command->scalar($this->db)); |
|
127 | } |
|
128 | } |
|
129 |