Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IsStockItemSalableConditionChain.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $conditions = [];
23 
27  private $resourceConnection;
28 
35  public function __construct(
36  ResourceConnection $resourceConnection,
37  array $conditions = []
38  ) {
39  foreach ($conditions as $getIsSalableCondition) {
40  if (!$getIsSalableCondition instanceof GetIsStockItemSalableConditionInterface) {
41  throw new LocalizedException(
42  __('Condition must implement %1', GetIsStockItemSalableConditionInterface::class)
43  );
44  }
45  }
46  $this->resourceConnection = $resourceConnection;
47  $this->conditions = $conditions;
48  }
49 
54  public function execute(Select $select): string
55  {
56  if (empty($this->conditions)) {
57  return '1';
58  }
59 
60  $conditionStrings = [];
61  foreach ($this->conditions as $condition) {
62  $conditionString = $condition->execute($select);
63  if ('' !== trim($conditionString)) {
64  $conditionStrings[] = $conditionString;
65  }
66  }
67 
68  $isSalableString = '(' . implode($conditionStrings, ') OR (') . ')';
69  return (string)$this->resourceConnection->getConnection()->getCheckSql($isSalableString, 1, 0);
70  }
71 }
__()
Definition: __.php:13