Changeset 2062929
- Timestamp:
- 04/04/2019 11:19:09 AM (7 years ago)
- Location:
- altoshift-woocommerce/trunk
- Files:
-
- 3 edited
-
AltoshiftWoocommercePlugin.php (modified) (1 diff)
-
includes/classes/Feed/Feed.php (modified) (6 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
altoshift-woocommerce/trunk/AltoshiftWoocommercePlugin.php
r2053142 r2062929 4 4 Plugin Name: Altoshift Woocommerce Plugin 5 5 Description: Plugin for Altoshift search integration into your Woocommerce shop 6 Version: 1.0. 06 Version: 1.0.1 7 7 Author: Altoshift 8 8 License: GPL2 -
altoshift-woocommerce/trunk/includes/classes/Feed/Feed.php
r2053142 r2062929 15 15 public $products = []; 16 16 public $categories = []; 17 18 public static $predefinedFields = array( 19 "id" 20 ); 21 22 public $allFields = array(); 17 23 18 24 public static function registerUrls() … … 78 84 $this->createElement($headerName, $headerValue); 79 85 } 86 87 echo '<allFields>'; 88 foreach($this->allFields as $field) 89 { 90 $this->createElement('field', $field); 91 } 92 echo '</allFields>'; 80 93 81 94 foreach($this->categories as $category) … … 93 106 echo '<item>'; 94 107 foreach ($product as $field => $value) { 95 if ($field == 'categor ies' || $field === 'categoriesTree') {108 if ($field == 'categoryIds' || $field === 'categoryTree') { 96 109 $this->renderProductCategories($value, $field); 97 110 continue; … … 108 121 } 109 122 110 private function renderProductCategories($categories, $element = 'categor ies')123 private function renderProductCategories($categories, $element = 'categoryIds') 111 124 { 112 125 echo '<'.$element.'>'; … … 196 209 } 197 210 211 $moreFields = array(); 212 if (isset($_GET['more_fields']) && !empty($_GET['more_fields'])) { 213 try { 214 $moreFields = explode(",", $_GET['more_fields']); 215 } catch(Exception $e) { 216 $moreFields = array(); 217 } 218 } 219 198 220 $query = new \WP_Query($args); 199 221 200 222 foreach ($query->posts as $post) { 201 223 $product = WC()->product_factory->get_product($post->ID); 202 $imageId = get_post_thumbnail_id($post->ID); 203 $imageLinks = wp_get_attachment_image_src($imageId, 'full'); 204 205 $productCategoriesTree = $this->getProductCategoryTree($post->ID); 206 $productCategories = $this->getProductCategories($post->ID); 207 208 $this->products[] = array( 209 'id' => $post->ID, 210 'link' => get_permalink($post), 211 'title' => $product->name, 212 'description' => $product->description, 213 'image_link' => is_array($imageLinks) && count($imageLinks) ? $imageLinks[0] : '', 214 'availability' => $product->is_purchasable() && $product->is_in_stock() ? 'in stock' : 'out of stock', 215 'price' => $product->regular_price, 216 'sale_price' => $product->sale_price, 217 'categoriesTree' => $productCategoriesTree, 218 'categories' => $productCategories, 219 ); 224 225 $productData = $this->productToArray($post, $product); 226 try { 227 if (!count($this->allFields)) { 228 $this->allFields = $this->getAdditionalFields($productData); 229 } 230 } catch (Exception $e) { 231 232 } 233 234 $productItem = array( 235 'id' => $productData['id'], 236 ); 237 238 foreach($moreFields as $field) { 239 if (!isset($productData[$field])) { 240 continue; 241 } 242 $productItem[$field] = $productData[$field]; 243 } 244 245 $this->products[] = $productItem; 220 246 } 221 247 } … … 260 286 echo "<![CDATA[$value]]>"; 261 287 } 288 289 private function productToArray($post, $product) { 290 $imageId = get_post_thumbnail_id($post->ID); 291 $imageLinks = wp_get_attachment_image_src($imageId, 'full'); 292 $productCategoriesTree = $this->getProductCategoryTree($post->ID); 293 $productCategories = $this->getProductCategories($post->ID); 294 295 $data = $this->accessProtected($product, "data"); 296 $data = array_merge($data, array( 297 'id' => $post->ID, 298 'link' => get_permalink($post), 299 'title' => $product->name, 300 'description' => $product->description, 301 'image_link' => is_array($imageLinks) && count($imageLinks) ? $imageLinks[0] : '', 302 'availability' => $product->is_purchasable() && $product->is_in_stock() ? 'in stock' : 'out of stock', 303 'price' => $product->regular_price, 304 'sale_price' => $product->sale_price, 305 'categoryTree' => $productCategoriesTree, 306 'categoryIds' => $productCategories, 307 )); 308 309 unset($data['name']); 310 unset($data['regular_price']); 311 312 return $data; 313 } 314 315 private function accessProtected($obj, $prop) { 316 $reflection = new \ReflectionClass($obj); 317 $property = $reflection->getProperty($prop); 318 $property->setAccessible(true); 319 return $property->getValue($obj); 320 } 321 322 private function getAdditionalFields($productData) { 323 $productFields = array_keys($productData); 324 return array_diff($productFields, self::$predefinedFields); 325 } 262 326 } -
altoshift-woocommerce/trunk/readme.txt
r2053357 r2062929 82 82 83 83 == Changelog == 84 = 1.0.1 = 85 * Add new Feed parser for new feature 84 86 85 87 = 1.0 =
Note: See TracChangeset
for help on using the changeset viewer.