11<?php
2- /**
3- * Copyright (c) 2019 Landofcoder
4- *
5- * Permission is hereby granted, free of charge, to any person obtaining a copy
6- * of this software and associated documentation files (the "Software"), to deal
7- * in the Software without restriction, including without limitation the rights
8- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9- * copies of the Software, and to permit persons to whom the Software is
10- * furnished to do so, subject to the following conditions:
11- *
12- * The above copyright notice and this permission notice shall be included in all
13- * copies or substantial portions of the Software.
14- *
15- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21- * SOFTWARE.
22- */
23-
242namespace Lof \ProductTags \Model \ResourceModel ;
253
264class Tag extends \Magento \Framework \Model \ResourceModel \Db \AbstractDb
275{
28-
29- protected $ _tagProductTable ;
30- /**
31- * Define resource model
32- *
33- * @return void
34- */
356 protected function _construct ()
367 {
378 $ this ->_init ('lof_producttags_tag ' , 'tag_id ' );
389 }
39- /**
40- * Category product table name getter
41- *
42- * @return string
43- */
44- public function getTagProductTable ()
45- {
46- if (!$ this ->_tagProductTable ) {
47- $ this ->_tagProductTable = $ this ->getTable ('lof_producttags_product ' );
48- }
49- return $ this ->_tagProductTable ;
50- }
51- /**
52- * Get positions of associated to category products
53- *
54- * @param \Lof\ProductTags\Model\Tag $tag
55- * @return array
56- */
57- public function getProductsPosition ($ tag )
58- {
59- $ select = $ this ->getConnection ()->select ()->from (
60- $ this ->getTagProductTable (),
61- ['product_id ' , 'position ' ]
62- )->where (
63- "{$ this ->getTable ('lof_producttags_product ' )}.tag_id = ? " ,
64- $ tag ->getId ()
65- );
66- $ bind = ['tag_id ' => (int )$ tag ->getId ()];
67-
68- return $ this ->getConnection ()->fetchPairs ($ select , $ bind );
69- }
70- }
10+ }
0 commit comments