Changeset 1730148
- Timestamp:
- 09/14/2017 08:31:06 PM (9 years ago)
- Location:
- fastdee/trunk/includes/core
- Files:
-
- 2 edited
-
class-fd-base.php (modified) (1 diff)
-
class-fd-util.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
fastdee/trunk/includes/core/class-fd-base.php
r1727829 r1730148 164 164 return null; 165 165 } 166 167 /** 168 * Gets fdid and return store and offer ids 169 * 170 * @param $fastdeeId 171 * 172 * @return array 173 */ 174 public static function parseFdId( $fastdeeId ) { 175 if ( ! $fastdeeId ) { 176 return array( 'store_id' => null, 'offer_id' => null ); 177 } 178 179 $strLimite = strrchr( $fastdeeId, '_' ); 180 $limite = strpos( $fastdeeId, $strLimite ); 181 182 $store_id = (int) substr( $fastdeeId, $limite + 1 ); 183 $offer_id = substr( $fastdeeId, 0, $limite ); 184 185 return array( 'store_id' => $store_id, 'offer_id' => $offer_id ); 186 } 187 188 189 /** 190 * searches for post and gets its fdid 191 * 192 * @param bool $post_id 193 * @param bool $limit 194 * @param bool $offset 195 * 196 * @return array|null|object 197 */ 198 public static function get_posts_with_fastdee_id( $post_id = false, $limit = false, $offset = false ) { 199 $by_post_id = ''; 200 if ( $post_id ) { 201 $by_post_id = " wp_posts.ID = $post_id AND "; 202 } 203 204 $_limit = ''; 205 if ( $limit !== false ) { 206 $_limit = " LIMIT $limit "; 207 } 208 209 $_offset = ''; 210 if ( $offset !== false ) { 211 $_offset = " OFFSET $offset "; 212 } 213 214 $queryString = " 215 SELECT 216 wp_posts.ID as post_id, 217 mt_offer_id.meta_value as _fd_offer_fastdee_id 218 FROM wp_posts 219 LEFT JOIN wp_postmeta AS mt_offer_id ON ( wp_posts.ID = mt_offer_id.post_id ) 220 WHERE 221 " . $by_post_id . " 222 wp_posts.post_type = 'product' 223 AND ( 224 wp_posts.post_status = 'publish' 225 OR wp_posts.post_status = 'future' 226 OR wp_posts.post_status = 'draft' 227 OR wp_posts.post_status = 'pending' 228 OR wp_posts.post_status = 'private' 229 ) 230 AND mt_offer_id.post_id IS NOT NULL 231 AND mt_offer_id.meta_key = '_fd_offer_fastdee_id' 232 " . $_limit . " 233 " . $_offset . ";"; 234 235 global $wpdb; 236 237 return $wpdb->get_results( $queryString, OBJECT ); 238 } 166 239 } -
fastdee/trunk/includes/core/class-fd-util.php
r1727829 r1730148 152 152 } 153 153 } 154 155 public static function fd_get_product_by_wp_post_id( $post_id ) { 156 $product = FD_Base::get_posts_with_fastdee_id( $post_id ); 157 158 if ( ! isset( $product[0] ) || ! $product[0]->_fd_offer_fastdee_id ) { 159 return false; 160 } 161 162 $fastdee_id = Fd_Base::parseFdId( $product[0]->_fd_offer_fastdee_id ); 163 164 $options = get_option( 'fd_settings' ); 165 $alv = new alv2( '1494725687402ae01f8f5', $options['fd_sourceID'] ); 166 $offer = $alv->getOfertaByStoreIdAndSKU( $fastdee_id['offer_id'], $fastdee_id['store_id'] ); 167 168 if ( isset( $offer[0] ) && property_exists( $offer[0], 'product' ) ) { 169 return $offer[0]->product; 170 } 171 172 return false; 173 } 154 174 }
Note: See TracChangeset
for help on using the changeset viewer.