Beispiel #1
0
 public function refreshTableData()
 {
     $refreshedCount = 0;
     $catInfo = $this->getItems(array("DetailLevel" => "ReturnAll"));
     $existCategoriesList = array();
     $res = CategoryTable::getList(array("select" => array("ID", "CATEGORY_ID")));
     while ($category = $res->fetch()) {
         $existCategoriesList[$category["CATEGORY_ID"]] = $category["ID"];
     }
     if (isset($catInfo["CategoryArray"]["Category"])) {
         $categories = Xml2Array::normalize($catInfo["CategoryArray"]["Category"]);
         foreach ($categories as $category) {
             $fields = array("CATEGORY_ID" => $category["CategoryID"], "LEVEL" => $category["CategoryLevel"], "NAME" => $category["CategoryName"], "PARENT_ID" => $category["CategoryParentID"]);
             if (array_key_exists($category["CategoryID"], $existCategoriesList)) {
                 $result = CategoryTable::update($existCategoriesList[$category["CategoryID"]], $fields);
             } else {
                 $result = CategoryTable::add($fields);
             }
             if ($result > 0) {
                 $refreshedCount++;
             }
         }
     }
     return $refreshedCount;
 }
Beispiel #2
0
 /**
  * @param int $type Policy::TYPE_RETURN||Policy::TYPE_PAYMENT||Policy::TYPE_SHIPPING
  * @return array
  */
 public function getPoliciesNames($type)
 {
     $policiesList = $this->getItemsList();
     if (empty($policiesList)) {
         return array();
     }
     if ($type == self::TYPE_RETURN) {
         $policyBranch = $policiesList["returnPolicyProfileList"]["ReturnPolicyProfile"];
     } elseif ($type == self::TYPE_PAYMENT) {
         $policyBranch = $policiesList["paymentProfileList"]["PaymentProfile"];
     } elseif ($type == self::TYPE_SHIPPING) {
         $policyBranch = $policiesList["shippingPolicyProfile"]["ShippingPolicyProfile"];
     } else {
         throw new ArgumentOutOfRangeException("type");
     }
     if (empty($policyBranch) || !is_array($policyBranch)) {
         return array();
     }
     $result = array();
     $policies = Xml2Array::normalize($policyBranch);
     foreach ($policies as $policy) {
         if (isset($policy["profileName"]) && strlen($policy["profileName"]) > 0 && isset($policy["profileId"]) && strlen($policy["profileId"]) > 0) {
             $result[$policy["profileId"]] = $policy["profileName"];
         }
     }
     return $result;
 }
Beispiel #3
0
 public function convert($data)
 {
     if (!isset($data["RESULT_ID"])) {
         throw new ArgumentNullException("data[\"RESULT_ID\"]");
     }
     if (!isset($data["CONTENT"])) {
         throw new ArgumentNullException("data[\"CONTENT\"]");
     }
     $result["ARRAY"] = \Bitrix\Sale\TradingPlatform\Xml2Array::convert($data["CONTENT"]);
     $result["RESULT_ID"] = $data["RESULT_ID"];
     $result["XML"] = $data["CONTENT"];
     return $result;
 }
Beispiel #4
0
 public function getListPayments()
 {
     static $result = null;
     if ($result === null) {
         $result = array();
         $data = $this->getData();
         if (isset($data["PaymentOptionDetails"]) && is_array($data["PaymentOptionDetails"])) {
             $data["PaymentOptionDetails"] = Xml2Array::normalize($data["PaymentOptionDetails"]);
             foreach ($data["PaymentOptionDetails"] as $payment) {
                 $result[$payment["PaymentOption"]] = $payment["Description"];
             }
         }
     }
     return $result;
 }
Beispiel #5
0
 public function processOrder($orderEbay)
 {
     Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING", $orderEbay["ExtendedOrderID"], print_r($orderEbay, true), $this->siteId);
     /*
      * only in this case order is completely ready for shipping
      */
     if ($orderEbay["OrderStatus"] != "Completed" || !isset($orderEbay["CheckoutStatus"]["eBayPaymentStatus"]) || $orderEbay["CheckoutStatus"]["eBayPaymentStatus"] != "NoPaymentFailure") {
         Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_SKIPPED", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
         return array();
     }
     $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
     $settings = $ebay->getSettings();
     if (!isset($settings[$this->siteId]["ORDER_PROPS"]) || !is_array($settings[$this->siteId]["ORDER_PROPS"])) {
         throw new SystemException("Can't get order props map");
     }
     $propsMap = $settings[$this->siteId]["ORDER_PROPS"];
     /*
     if(strtolower(SITE_CHARSET) != 'utf-8')
     	$orderEbay = \Bitrix\Main\Text\Encoding::convertEncodingArray($orderEbay, 'UTF-8', SITE_CHARSET);
     */
     $dbRes = OrderTable::getList(array("filter" => array("TRADING_PLATFORM_ID" => $ebay->getId(), "EXTERNAL_ORDER_ID" => $orderEbay["ExtendedOrderID"])));
     if ($orderCorrespondence = $dbRes->fetch()) {
         Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_ALREADY_EXIST", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED_EXIST", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
         return array();
     }
     /** @var \Bitrix\Sale\Order $order */
     $order = \Bitrix\Sale\Order::create($this->siteId);
     $order->setPersonTypeId($settings[$this->siteId]["PERSON_TYPE"]);
     $propsCollection = $order->getPropertyCollection();
     /** @var \Bitrix\Sale\PropertyValueCollection $propCollection */
     if (intval($propsMap["FIO"]) > 0) {
         $prop = $propsCollection->getItemByOrderPropertyId($propsMap["FIO"]);
         $prop->setValue($orderEbay["ShippingAddress"]["Name"]);
     }
     if (intval($propsMap["CITY"]) > 0) {
         $prop = $propsCollection->getItemByOrderPropertyId($propsMap["CITY"]);
         $prop->setValue($orderEbay["ShippingAddress"]["CityName"]);
     }
     if (intval($propsMap["PHONE"]) > 0) {
         $prop = $propsCollection->getItemByOrderPropertyId($propsMap["PHONE"]);
         $prop->setValue($orderEbay["ShippingAddress"]["Phone"]);
     }
     if (intval($propsMap["ZIP"]) > 0) {
         $prop = $propsCollection->getItemByOrderPropertyId($propsMap["ZIP"]);
         $prop->setValue($orderEbay["ShippingAddress"]["PostalCode"]);
     }
     if (intval($propsMap["ADDRESS"]) > 0) {
         $prop = $propsCollection->getItemByOrderPropertyId($propsMap["ADDRESS"]);
         $prop->setValue($orderEbay["ShippingAddress"]["CountryName"] . " " . $orderEbay["ShippingAddress"]["CityName"] . " " . $orderEbay["ShippingAddress"]["Street1"] . " " . (!empty($orderEbay["ShippingAddress"]["Street2"]) ? $orderEbay["ShippingAddress"]["Street2"] . " " : ""));
     }
     $basket = null;
     $bitrixOrderId = 0;
     $userId = 0;
     $orderLineItemsIds = array();
     $transactionsArray = $this->normalizeTransactionsArray($orderEbay["TransactionArray"]);
     foreach ($transactionsArray as $transaction) {
         //if we have more than one transaction let's create user from the first
         if ($userId <= 0) {
             if (intval($propsMap["EMAIL"]) > 0 && !empty($transaction["Buyer"]["Email"])) {
                 $prop = $propsCollection->getItemByOrderPropertyId($propsMap["EMAIL"]);
                 $prop->setValue($transaction["Buyer"]["Email"]);
                 $userId = $this->createUser($transaction["Buyer"]["Email"], array("NAME" => $transaction["Buyer"]["UserFirstName"], "LAST_NAME" => $transaction["Buyer"]["UserLastName"]));
             }
             if ($userId <= 0) {
                 $userId = \CSaleUser::GetAnonymousUserID();
             }
         }
         if (intval($userId > 0)) {
             $order->setFieldNoDemand("USER_ID", $userId);
         }
         $fUserId = null;
         if ($order->getUserId() > 0) {
             $fUserId = Fuser::getIdByUserId($order->getUserId());
         }
         /** @var \Bitrix\Sale\Basket $basket */
         if (!$basket) {
             $basket = \Bitrix\Sale\Basket::create($this->siteId);
             $basket->setFUserId($fUserId);
         }
         $items = array();
         $isVariation = false;
         if (!empty($transaction["Item"])) {
             $items = Xml2Array::normalize($transaction["Item"]);
         } elseif (!empty($transaction["Variation"])) {
             $items = Xml2Array::normalize($transaction["Variation"]);
             $isVariation = true;
         }
         if (empty($items)) {
             Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId);
             continue;
         }
         foreach ($items as $transactionItem) {
             $ebaySku = $isVariation ? $this->getSkuVariation($transactionItem["SKU"]) : $this->getSku($transactionItem["SKU"]);
             if (strlen($ebaySku) <= 0) {
                 Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_SKU_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId);
                 continue;
             }
             $item = $basket->createItem('catalog', $ebaySku);
             $item->setField("PRODUCT_PROVIDER_CLASS", "CCatalogProductProvider");
             $itemData = array("CUSTOM_PRICE" => "Y", "PRICE" => floatval($transaction["TransactionPrice"]), "QUANTITY" => floatval($transaction["QuantityPurchased"]), "NAME" => !empty($transactionItem["VariationTitle"]) ? $transactionItem["VariationTitle"] : $transactionItem["Title"], "CURRENCY" => SiteCurrencyTable::getSiteCurrency($this->siteId));
             $data = Provider::getProductData($basket);
             if (!empty($data[$item->getBasketCode()])) {
                 $itemData = array_merge($data[$item->getBasketCode()], $itemData);
             } else {
                 $item->delete();
                 $item = $basket->createItem('', $ebaySku);
             }
             $res = $item->setFields($itemData);
             if ($res->isSuccess()) {
                 $orderLineItemsIds[] = $transaction["OrderLineItemID"];
             } else {
                 foreach ($res->getErrors() as $error) {
                     Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_TRANSACTION_ITEM_CREATE_ERROR", $transaction["OrderLineItemID"], $error->getMessage(), $this->siteId);
                 }
             }
         }
     }
     $res = $order->setBasket($basket);
     if (!$res->isSuccess()) {
         foreach ($res->getErrors() as $error) {
             Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CREATE_ERROR_SET_BASKET", $orderEbay["ExtendedOrderID"], $error->getMessage(), $this->siteId);
         }
     }
     //payments
     if (intval($settings[$this->siteId]["MAPS"]["PAYMENT"]["PayPal"]) > 0) {
         $payments = $order->getPaymentCollection();
         /** @var \Bitrix\Sale\Payment $payment */
         if ($payments->count() > 0) {
             foreach ($payments as $payment) {
                 if ($payment->isPaid()) {
                     $payment->setPaid("N");
                 }
                 $payment->delete();
             }
         }
         $payment = $payments->createItem();
         $payment->setField('PAY_SYSTEM_ID', $settings[$this->siteId]["MAPS"]["PAYMENT"]["PayPal"]);
         $payment->setField('PAY_SYSTEM_NAME', "PayPal via Ebay");
         if ($orderEbay["CheckoutStatus"]["eBayPaymentStatus"] == "NoPaymentFailure" && $orderEbay["MonetaryDetails"]["Payments"]["Payment"]["PaymentStatus"] && $orderEbay["MonetaryDetails"]["Payments"]["Payment"]["PaymentAmount"] == $orderEbay["Total"]) {
             $payment->setField("SUM", $orderEbay["AmountPaid"]);
             $payment->setPaid("Y");
         }
     }
     //shipment
     if (intval($settings[$this->siteId]["MAPS"]["SHIPMENT"][$orderEbay["ShippingServiceSelected"]["ShippingService"]]) > 0) {
         $shipments = $order->getShipmentCollection();
         /** @var \Bitrix\Sale\Shipment $shipment */
         if ($shipments->count() > 0) {
             foreach ($shipments as $shipment) {
                 if (!$shipment->isSystem()) {
                     $shipment->delete();
                 }
             }
         }
         $shipment = $shipments->createItem();
         $shipment->setField('DELIVERY_ID', $settings[$this->siteId]["MAPS"]["SHIPMENT"][$orderEbay["ShippingServiceSelected"]["ShippingService"]]);
         $shipment->setField('CUSTOM_PRICE_DELIVERY', "Y");
         $shipment->setField('BASE_PRICE_DELIVERY', $orderEbay["ShippingServiceSelected"]["ShippingServiceCost"]);
         $basket = $order->getBasket();
         if ($basket) {
             $shipmentItemCollection = $shipment->getShipmentItemCollection();
             $basketItems = $basket->getBasketItems();
             foreach ($basketItems as $basketItem) {
                 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
                 $shipmentItem->setQuantity($basketItem->getField('QUANTITY'));
             }
         }
         // todo: delivery price changed. Probably bug.
         $shipment->setField('BASE_PRICE_DELIVERY', $orderEbay["ShippingServiceSelected"]["ShippingServiceCost"]);
     } else {
         Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_SHIPPING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_NOT_MAPPED_SHIPPING", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"], "#EBAY_SHIPPING#" => $orderEbay["ShippingServiceSelected"]["ShippingService"])), $this->siteId);
         return 0;
     }
     // order status
     if (strlen($settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]) > 0) {
         switch ($settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]) {
             /* flags */
             case "CANCELED":
                 if (!$order->setField("CANCELED", "Y")) {
                     Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CANCELING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_CANCEL_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
                 }
                 break;
             case "PAYED":
                 $payments = $order->getPaymentCollection();
                 foreach ($payments as $payment) {
                     $payment->setPaid("Y");
                 }
                 break;
             case "ALLOW_DELIVERY":
                 // we suggest that only one shipment exists
                 $shipments = $order->getShipmentCollection();
                 foreach ($shipments as $shipment) {
                     if (!$shipment->isSystem()) {
                         if (!$shipment->allowDelivery()) {
                             Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_ALLOW_DELIVERY_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_ALLOW_DELIVERY_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
                         }
                     }
                 }
                 break;
             case "DEDUCTED":
                 $shipments = $order->getShipmentCollection();
                 foreach ($shipments as $shipment) {
                     if (!$shipment->isSystem()) {
                         if (!$shipment->setField('DEDUCTED', 'Y')) {
                             Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_DEDUCTIOING_ERROR", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_DEDUCT_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
                         }
                     }
                 }
                 break;
                 /* statuses */
             /* statuses */
             default:
                 $res = $order->setField("STATUS_ID", $settings[$this->siteId]["STATUS_MAP"][$orderEbay["OrderStatus"]]);
                 /** @var \Bitrix\Sale\Result $res */
                 if (!$res->isSuccess()) {
                     Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_CHANGE_STATUS_ERROR", $orderEbay["OrderLineItemID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SET_STATUS_ERROR", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"], "#STATUS#" => $orderEbay["OrderStatus"])), $this->siteId);
                 }
         }
     }
     $order->setField("PRICE", $orderEbay["Total"]);
     $order->setField("XML_ID", Ebay::TRADING_PLATFORM_CODE . "_" . $orderEbay["ExtendedOrderID"]);
     $res = $order->save();
     if (!$res->isSuccess()) {
         foreach ($res->getErrors() as $error) {
             Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_SAVE_ERROR", $orderEbay["ExtendedOrderID"], print_r($error->getMessage(), true), $this->siteId);
         }
     } else {
         $bitrixOrderId = $order->getId();
         Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_CREATED", $bitrixOrderId, Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SAVED", array("#ORDER_ID#" => $bitrixOrderId)), $this->siteId);
         \CSaleMobileOrderPush::send("ORDER_CREATED", array("ORDER_ID" => $bitrixOrderId));
         $res = OrderTable::add(array("ORDER_ID" => $bitrixOrderId, "TRADING_PLATFORM_ID" => $ebay->getId(), "EXTERNAL_ORDER_ID" => $orderEbay["ExtendedOrderID"], "PARAMS" => array("ORDER_LINES" => $orderLineItemsIds, "ORDER_ID" => $orderEbay["OrderID"])));
         if (!$res->isSuccess()) {
             foreach ($res->getErrors() as $error) {
                 Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_DATA_PROCESSOR_ORDER_DELIVERY_SAVE_ERROR", $orderEbay["ExtendedOrderID"], $error->getMessage(), $this->siteId);
             }
         }
     }
     // send confirmation
     if ($bitrixOrderId > 0 && !empty($orderLineItemsIds)) {
         $ebayFeed = \Bitrix\Sale\TradingPlatform\Ebay\Feed\Manager::createFeed("ORDER_ACK", $this->siteId);
         $sourceData = array();
         foreach ($orderLineItemsIds as $id) {
             $sourceData[] = array("ORDER_ID" => $orderEbay["OrderID"], "ORDER_LINE_ITEM_ID" => $id);
         }
         $ebayFeed->setSourceData(array($sourceData));
         $ebayFeed->processData();
     }
     return $bitrixOrderId;
 }
Beispiel #6
0
        protected static function getUserInfo($siteId, array $ebaySettings)
        {
            if (strlen($siteId) <= 0 || empty($ebaySettings)) {
                return array();
            }
            if (empty($ebaySettings[$siteId]["API"]["AUTH_TOKEN"])) {
                return array();
            }
            $userId = self::getUserId($siteId, $ebaySettings);
            if (strlen($userId) <= 0) {
                return array();
            }
            $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
            $ttl = 86400;
            $cacheId = __FILE__ . ":USER_INFO";
            if (self::$useCache && $cacheManager->read($ttl, $cacheId)) {
                $result = $cacheManager->get($cacheId);
            } else {
                if (!self::$useCache) {
                    $cacheManager->clean($cacheId);
                }
                $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
                $settings = $ebay->getSettings();
                if (empty($settings[$siteId]["API"]["AUTH_TOKEN"])) {
                    return array();
                }
                $data = '<?xml version="1.0" encoding="utf-8"?>
					<GetUserRequest xmlns="urn:ebay:apis:eBLBaseComponents">
					<RequesterCredentials>
						<eBayAuthToken>' . $settings[$siteId]["API"]["AUTH_TOKEN"] . '</eBayAuthToken>
					</RequesterCredentials>
					<UserID>' . $userId . '</UserID>
					</GetUserRequest>';
                $caller = new Caller(array("URL" => \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getApiUrl()));
                $xmpRes = $caller->sendRequest("GetUser", $data);
                $result = Xml2Array::convert($xmpRes);
                $cacheManager->set($cacheId, $result);
            }
            return $result;
        }
Beispiel #7
0
 public function convert($data)
 {
     $result = Xml2Array::convert($data, false);
     return Xml2Array::normalize($result["Order"]);
 }
Beispiel #8
0
                        }
                    }
                }
            }
        }
        if (strpos($results[$smallFeedType]["RESULTS"], "<Warnings>") !== false) {
            if (strlen($feedResMess) > 0) {
                $feedResMess .= ", ";
            }
            $feedResMess .= '<span style="color: orange; font-weight: bold;">' . Loc::getMessage("SALE_EBAY_RES_WARNING") . '</span>';
            $feedResErrDescr .= "<br>\n";
            if (isset($tmp["ProductResult"])) {
                $productResults = Xml2Array::normalize($tmp["ProductResult"]);
                foreach ($productResults as $productResult) {
                    if (isset($productResult["Warnings"]["Warning"])) {
                        $warnings = Xml2Array::normalize($productResult["Warnings"]["Warning"]);
                        foreach ($warnings as $warning) {
                            $feedResErrDescr .= Loc::getMessage("SALE_EBAY_CODE") . Loc::getMessage("SALE_EBAY_WARNING") . ": " . $warning["Message"] . " " . Loc::getMessage("SALE_EBAY_CODE") . ": " . $warning["Code"] . "<br>\n";
                        }
                    }
                }
            }
        }
    }
    if ($feedResMess == "") {
        $feedResMess = '<span style="color: green; font-weight: bold;">' . Loc::getMessage("SALE_EBAY_RES_SUCCESS") . '</span>';
    }
    echo $feedResMess;
    ?>

			</td>