Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
inventory.php
1<?php
2
4
6use \Bitrix\Main\SystemException;
7
9{
10 protected $maxProductQuantity = null;
11
12 public function __construct($params)
13 {
14 if(!isset($params["SITE_ID"]) || $params["SITE_ID"] == '')
15 throw new ArgumentNullException("SITE_ID");
16
17 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
18 $settings = $ebay->getSettings();
19
20 if(!empty($settings[$params["SITE_ID"]]['MAX_PRODUCT_QUANTITY']))
21 $this->maxProductQuantity = (float)$settings[$params["SITE_ID"]]['MAX_PRODUCT_QUANTITY'];
22 }
23
24 public function convert($data)
25 {
26 $result = "";
27
28 if(isset($data["OFFERS"]) && is_array($data["OFFERS"]) && !empty($data["OFFERS"]))
29 {
30 foreach($data["OFFERS"] as $offer)
31 $result .= $this->getItemData($offer, $data["IBLOCK_ID"]."_".$data["ID"]."_");
32 }
33 else
34 {
35 $result .= $this->getItemData($data, $data["IBLOCK_ID"]."_");
36 }
37
38 return $result;
39 }
40
41 protected function getItemData($data, $skuPrefix = "")
42 {
43 if(!isset($data["PRICES"]["MIN"]) || $data["PRICES"]["MIN"] <= 0)
44 throw new SystemException("Can't find the price for product id: ".$data["ID"]." ! ".__METHOD__);
45
46 if((float)$data["QUANTITY"] <= 0)
47 return '';
48
49 $quantity = (float)$data["QUANTITY"];
50
51 if($this->maxProductQuantity !== null && $quantity > $this->maxProductQuantity)
52 $quantity = $this->maxProductQuantity;
53
54 $result = "\t<Inventory>\n";
55 $result .= "\t\t<SKU>".$skuPrefix.$data["ID"]."</SKU>\n";
56 $result .= "\t\t<Price>".$data["PRICES"]["MIN"]."</Price>\n";
57 $result .= "\t\t<Quantity>".$quantity."</Quantity>\n";
58 $result .= "\t</Inventory>\n";
59
60 return $result;
61 }
62}