Advertisement
Guest User

carlos

a guest
Apr 24th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.76 KB | None | 0 0
  1.     public function findByShopId($shopId, $categoryId, $orderBy, $page, $limit)
  2.     {
  3.         $rsm = $this->buildResultSetMapping(array(
  4.             'offerId' => 'offerId',
  5.             'productId' => 'productId'
  6.         ));
  7.  
  8.         $query = $this->getDoctrine()
  9.             ->getManager('legacy')
  10.             ->createNativeQuery('\Shopbot\ShoppingBundle\Doctrine\Entity\Shopsearchindexsf', $rsm);
  11.  
  12.         $sql = '
  13. SELECT
  14.    offer.refshopcodeid, offer.refproduct
  15. FROM
  16.    webshop.dbo.shopsearchindexsf AS offer
  17. LEFT JOIN
  18.    shopenginesf AS product
  19. ON
  20.    product.refproduct = offer.refproduct
  21.    AND product.countryCode = offer.countryCode
  22.    AND product.result_type = :typeProduct
  23. WHERE
  24.    offer.countryCode = :country
  25.    AND offer.refshop = :shopId
  26.        ';
  27.  
  28.         if (!is_null($categoryId)) {
  29.             $sql .= ' AND offer.reflevel2 = :categoryId';
  30.             $query
  31.                 ->setParameter('categoryId', $categoryId);
  32.         }
  33.  
  34.         switch ($orderBy) {
  35.             case ShopController::OFFERS_SORT_POPULARITY:
  36.                 $sql .= ' ORDER BY offer.popularity DESC, offer.price ASC';
  37.                 break;
  38.             case ShopController::OFFERS_SORT_DATE:
  39.                 $sql .= ' ORDER BY offer.refshopcodeid';
  40.                 break;
  41.             case ShopController::OFFERS_SORT_PRICE:
  42.                 $sql .= ' ORDER BY offer.price ASC, offer.popularity DESC';
  43.                 break;
  44.             case ShopController::OFFERS_SORT_NAME:
  45.                 $sql .= ' ORDER BY offer.productname ASC, offer.popularity DESC';
  46.                 break;
  47.         }
  48.  
  49.         $query
  50.             ->setSQL($sql)
  51.             ->setParameter('country', $this->country)
  52.             ->setParameter('typeProduct', Shopenginesf::RESULTTYPE_PRODUCT)
  53.             ->setParameter('shopId', $shopId);
  54.  
  55. //        $query = $this->getDoctrine()
  56. //            ->getManager('legacy')
  57. //            ->createQueryBuilder()
  58. //            ->select('offer')
  59. //            ->addSelect('offer.shopId')
  60. //            ->addSelect('offer.shopName')
  61. //            ->addSelect('offer.offerId')
  62. //            ->addSelect('offer.name')
  63. //            ->addSelect('offer.slug')
  64. //            ->addSelect('offer.productId')
  65. //            ->addSelect('offer.universeId')
  66. //            ->addSelect('offer.universeName')
  67. //            ->addSelect('offer.level1Id')
  68. //            ->addSelect('offer.level1Name')
  69. //            ->addSelect('offer.level2Id')
  70. //            ->addSelect('offer.level2Name')
  71. //            ->addSelect('offer.level2Url')
  72. //            ->addSelect('offer.platformId')
  73. //            ->addSelect('offer.platformName')
  74. //            ->addSelect('offer.popularity')
  75. //            ->addSelect('offer.redirectionUrl')
  76. //            ->addSelect('offer.photo90')
  77. //            ->addSelect('offer.minPrice')
  78. //            ->addSelect('offer.regularPrice')
  79. //            ->addSelect('product.shopCount')
  80. //            ->from('\Shopbot\ShoppingBundle\Doctrine\Entity\Shopsearchindexsf', 'offer')
  81. //            ->leftJoin('Shopbot\ShoppingBundle\Doctrine\Entity\Shopenginesf', 'product', 'WITH', 'product.productId = offer.productId AND product.countryCode = offer.countryCode AND product.resultType = :typeProduct')
  82. //            ->where('offer.countryCode = :country')
  83. //            ->andWhere('offer.shopId = :shopId')
  84. //            ->setParameter('country', $this->country)
  85. //            ->setParameter('typeProduct', Shopenginesf::RESULTTYPE_PRODUCT)
  86. //            ->setParameter('shopId', $shopId);
  87. //
  88. //        if (!is_null($categoryId)) {
  89. //            $query
  90. //                ->andWhere('offer.level2Id = :categoryId')
  91. //                ->setParameter('categoryId', $categoryId);
  92. //        }
  93. //
  94. //        switch ($orderBy) {
  95. //            case ShopController::OFFERS_SORT_POPULARITY:
  96. //                $query
  97. //                    ->orderBy('offer.popularity', 'DESC')
  98. //                    ->addOrderBy('offer.minPrice', 'ASC');
  99. //
  100. //                break;
  101. //
  102. //            case ShopController::OFFERS_SORT_DATE:
  103. //                $query->orderBy('offer.offerId', 'DESC');
  104. //
  105. //                break;
  106. //
  107. //            case ShopController::OFFERS_SORT_PRICE:
  108. //                $query
  109. //                    ->orderBy('offer.minPrice', 'ASC')
  110. //                    ->addOrderBy('offer.popularity', 'DESC');
  111. //
  112. //                break;
  113. //
  114. //            case ShopController::OFFERS_SORT_NAME:
  115. //                $query
  116. //                    ->orderBy('offer.name', 'ASC')
  117. //                    ->addOrderBy('offer.popularity', 'DESC');
  118. //
  119. //                break;
  120. //        }
  121.  
  122.         return $this->getPagination(
  123.                 $query
  124.                     ->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY), $page, $limit
  125.         );
  126.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement