|
|
Строка 6: |
Строка 6: |
| | | |
| == Пример == | | == Пример == |
| + | <source lang="php"> |
| + | /* @var iUmiHierarchyElement $product */ |
| + | $offerIdList = (array) $product->getValue('trade_offer_list'); |
| + | $tradeOfferFacade = UmiCms\Service::TradeOfferFacade(); |
| + | $collection = $tradeOfferFacade->mapCollectionWithRelations($tradeOfferFacade->getList($offerIdList)); |
| | | |
− | <div class="php" style="font-family:monospace; font-size:15px"> <span style="color: #666666; font-style: italic;">/* @var iUmiHierarchyElement $product */</span></br>
| + | /* Далее есть 2 варианта */ |
− | <span style="color: #000088;">$offerIdList</span> <span style="color: #339933;">=</span> <span style="color: #009900;">(</span><span style="color: #990000;">array</span><span style="color: #009900;">)</span> <span style="color: #000088;">$product</span><span style="color: #339933;">-></span><span style="color: #004000;">getValue</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'trade_offer_list'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></br>
| + | /* 1) Пройтись по результирующему масиву $collection */ |
− | <span style="color: #000088;">$tradeOfferFacade</span> <span style="color: #339933;">=</span> UmiCms\Service<span style="color: #339933;">::</span><span style="color: #004000;">TradeOfferFacade</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></br>
| + | $arrayOffersField_vendor_code = []; |
− | <span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tradeOfferFacade</span><span style="color: #339933;">-></span><span style="color: #004000;">mapCollectionWithRelations</span><span style="color: #009900;">(</span><span style="color: #000088;">$tradeOfferFacade</span><span style="color: #339933;">-></span><span style="color: #004000;">getList</span><span style="color: #009900;">(</span><span style="color: #000088;">$offerIdList</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></br>
| + | foreach($collection as $offer) { |
− | <span style="color: #666666; font-style: italic;">/* Далее есть 2 варианта */</span></br>
| + | $arrayOffersField_vendor_code[] = $offer->getVendorCode(); |
− | <span style="color: #666666; font-style: italic;">/* 1) Пройтись по результирующему масиву $collection */</span></br>
| + | } |
− | <span style="color: #000088;">$arrayOffersField_vendor_code</span> <span style="color: #339933;">=</span> <span style="color: #009900;">[</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span></br>
| + | |
− | <span style="color: #b1b100;">foreach</span><span style="color: #009900;">(</span><span style="color: #000088;">$collection</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$offer</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span></br>
| + | /* 2) Получить массив при помощи метода extractField */ |
− | <span style="color: #000088;"> $arrayOffersField_vendor_code</span><span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$offer</span><span style="color: #339933;">-></span><span style="color: #004000;">getVendorCode</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></br>
| + | $arrayOffersField_vendor_code = $collection->extractField('vendor_code'); |
− | <span style="color: #009900;">}</span></br>
| + | /* Пример результирующего массива: |
− | <span style="color: #666666; font-style: italic;">/* 2) Получить массив при помощи метода extractField */</span></br>
| + | Array |
− | <span style="color: #000088;">$arrayOffersField_vendor_code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$collection</span><span style="color: #339933;">-></span><span style="color: #004000;">extractField</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'vendor_code'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></br>
| + | ( |
− | <span style="color: #666666; font-style: italic;">/*
| + | [0] => 101-177 |
− | Пример результирующего массива:</br>
| + | [1] => 102-177 |
− | Array</br>
| + | [2] => 103-177 |
− | (</br>
| + | [3] => 104-177 |
− | [0] => 101-177</br>
| + | [4] => 105-177 |
− | [1] => 102-177</br>
| + | [5] => 106-177 |
− | [2] => 103-177</br>
| + | [6] => 107-177 |
− | [3] => 104-177</br>
| + | [7] => 108-177 |
− | [4] => 105-177</br>
| + | ) |
− | [5] => 106-177</br>
| + | */ |
− | [6] => 107-177</br>
| + | </source> |
− | [7] => 108-177</br>
| |
− | )</br>
| |
− | */</span></div>
| |
| | | |
| [[category:Верстка в PHP]] | | [[category:Верстка в PHP]] |