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