コード例 #1
0
function doPostSynch($wsName, $dateFrom, $dateTo)
{
    global $dao, $postOSIReq, $CONF_LastrequestLbl, $isOkResponses, $nbChildrenProducts, $nbResponse200, $nbResponseError, $nbResponse409, $nbNoReference;
    /* Check if allow to get this request */
    $isAllow = Scheduler::isAllowedToRequest($wsName);
    if (!ForceRequest::isForcedRequest() && !$isAllow) {
        return;
    }
    switch ($wsName) {
        /*
         * WSO-P005
         * POST /article
         */
        case "WSO-P005":
            Log::write("###### Do request " . $wsName . " - action=create_article ######", "info");
            $offset = 0;
            $limit = 1000;
            do {
                $newProducts = $dao->getLastCreateProducts($dateFrom, $dateTo, GlobalConfig::getDefaultLangId(), GlobalConfig::getDefaultCountryId(), $offset, $limit);
                $isOkResponses = true;
                $nbMainProducts = 0;
                $nbChildrenProducts = 0;
                $nbResponse200 = 0;
                $nbResponseError = 0;
                $nbResponse409 = 0;
                $nbNoReference = 0;
                if ($newProducts) {
                    $nbMainProducts = count($newProducts);
                    foreach ($newProducts as $product) {
                        /*
                         * Create main product
                         * @param $product => array
                         * @param create child products
                         * @param send publication
                         */
                        createMainProduct($product, true, true);
                    }
                    Log::write("Nb total main products = " . $nbMainProducts, "info");
                    Log::write("Nb total children products = " . $nbChildrenProducts, "info");
                    Log::write("Nb without reference = " . $nbNoReference, "info");
                    Log::write("Nb sent products = " . ($nbMainProducts + $nbChildrenProducts - $nbNoReference), "info");
                    Log::write("Nb response 200 (ok) = " . $nbResponse200, "info");
                    Log::write("Nb response 409 (duplicate) = " . $nbResponse409, "info");
                    Log::write("Nb response error = " . $nbResponseError, "info");
                } else {
                    Log::write("No request to send", "info");
                }
                $offset += $limit;
            } while (count($newProducts) == $limit);
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P006
             * POST /article/$reference$
             */
        /*
         * WSO-P006
         * POST /article/$reference$
         */
        case "WSO-P006":
            Log::write("###### Do request " . $wsName . " - action=update_article ######", "info");
            $offset = 0;
            $limit = 1000;
            do {
                $updateProducts = $dao->getLastUpdateProducts($dateFrom, $dateTo, GlobalConfig::getDefaultLangId(), GlobalConfig::getDefaultCountryId(), $offset, $limit);
                $isOkResponses = true;
                $nbMainProducts = 0;
                $nbChildrenProducts = 0;
                $nbResponse200 = 0;
                $nbResponseError = 0;
                $nbResponse409 = 0;
                $nbNoReference = 0;
                if ($updateProducts) {
                    $nbMainProducts = count($updateProducts);
                    foreach ($updateProducts as $product) {
                        updateMainProduct($product);
                    }
                    Log::write("Nb total main products = " . $nbMainProducts, "info");
                    Log::write("Nb total children products = " . $nbChildrenProducts, "info");
                    Log::write("Nb without reference = " . $nbNoReference, "info");
                    Log::write("Nb sent products = " . ($nbMainProducts + $nbChildrenProducts - $nbNoReference), "info");
                    Log::write("Nb response 200 (ok) = " . $nbResponse200, "info");
                    Log::write("Nb response 409 (duplicate) = " . $nbResponse409, "info");
                    Log::write("Nb response error = " . $nbResponseError, "info");
                } else {
                    Log::write("No request to send", "info");
                }
                $offset += $limit;
            } while (count($updateProducts) == $limit);
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P010
             * POST /client/web
             */
        /*
         * WSO-P010
         * POST /client/web
         */
        case "WSO-P010":
            Log::write("###### Do request " . $wsName . " - action=create_client_web ######", "info");
            $newCustomers = $dao->getLastCustomers($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($newCustomers) {
                foreach ($newCustomers as $customer) {
                    $xmlCustomer = XML::createCustomerXml($customer);
                    Log::write("Send request for login =  "******" - ", "info");
                    $response = $postOSIReq->wso_p010($xmlCustomer);
                    if (!isOkPostResult($response->getCode())) {
                        $isOkResponses = false;
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P011
             * POST /affaire/commande/web
             */
        /*
         * WSO-P011
         * POST /affaire/commande/web
         */
        case "WSO-P011":
            Log::write("###### Do request " . $wsName . " - action=create_commande_web ######", "info");
            /* Check if So Colissimo is installed */
            $tableSoColissimo = $dao->socolissimo_exists(_DB_NAME_);
            if ($tableSoColissimo > 0) {
                /* So Colissimo is installed */
                $orders = $dao->getLastOrdersSoColissimo($dateFrom, $dateTo, GlobalConfig::getDefaultCountryId());
            } else {
                /* So Colissimo is not installed */
                $orders = $dao->getLastOrders($dateFrom, $dateTo, GlobalConfig::getDefaultCountryId());
            }
            $giftTax = $dao->getGiftTax();
            $isOkResponses = true;
            if ($giftTax != null) {
                $giftTax = floatval($giftTax);
            } else {
                $giftTax = 0;
            }
            if ($orders) {
                foreach ($orders as $order) {
                    $orderDetails = $dao->getOrderDetails($order['id_order'], GlobalConfig::getDefaultLangId());
                    if ($orderDetails) {
                        /* Add virtual article for gift */
                        if ($order['gift'] == "1") {
                            $virtualArticle['reference'] = '_EMB';
                            $virtualArticle['product_name'] = 'Emballage cadeau';
                            $virtualArticle['product_quantity'] = 1;
                            $virtualArticle['tax_rate'] = $giftTax;
                            $virtualArticle['Remise_Pourc'] = 0;
                            $virtualArticle['id_order'] = $order['id_order'];
                            $virtualArticle['product_price'] = $order['total_wrapping'] / (1 + floatval($giftTax) / 100);
                            $orderDetails[] = $virtualArticle;
                        }
                        $xmlProduct = XML::createOrderXml($order, $orderDetails);
                        $orderNumber = $order['id_order'];
                        Log::write("Send request for order = " . $orderNumber . " - ", "info");
                        $response = $postOSIReq->wso_p011($xmlProduct, $reference);
                        if (!isOkPostResult($response->getCode())) {
                            $isOkResponses = false;
                        } else {
                            $now = date('Y-m-d H:i:s');
                            Db::getInstance()->Execute('
								INSERT INTO `' . _DB_PREFIX_ . 'opensi_order` (id_order, date_order_synchro, transaction, date_transaction, paid, date_paid)
								VALUES ("' . $order['id_order'] . '", "' . $now . '", 0, 0, 0, 0);
							');
                        }
                    } else {
                        Log::write("ERROR - Order ID " . $order['id_order'] . " - Error during synchronisation of the order : No products found for this order !", "ERROR");
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            /* Update OSI_LASTREQUEST_WSO-P011 value */
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P015
             * POST /affaire/commande/web/transaction
             */
        /*
         * WSO-P015
         * POST /affaire/commande/web/transaction
         */
        case "WSO-P015":
            Log::write("###### Do request " . $wsName . " - action=create_transaction_bancaire ######", "info");
            $orders = $dao->getLastCreateOrUpdateOrders($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($orders) {
                foreach ($orders as $order) {
                    if ($order['valid'] == 1 && $order['total_paid_real'] != 0) {
                        $xmlTransaction = XML::createTransactionWebXml($order);
                        $idOrder = $order['id_order'];
                        Log::write("Send request for order =  " . $idOrder . " - ", "info");
                        $response = $postOSIReq->wso_p015($xmlTransaction);
                        if (!isOkPostResult($response->getCode())) {
                            $isOkResponses = false;
                            Log::write("...PROBLEME AVEC " . $idOrder . "...", "ERROR");
                        } else {
                            $now = date('Y-m-d H:i:s');
                            Db::getInstance()->Execute('
								UPDATE `' . _DB_PREFIX_ . 'opensi_order` set transaction = "1", date_transaction = "' . $now . '" WHERE id_order = "' . $idOrder . '";
							');
                        }
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P025
             * POST /client/web/$code_site_web$/$login$
             */
        /*
         * WSO-P025
         * POST /client/web/$code_site_web$/$login$
         */
        case "WSO-P025":
            Log::write("###### Do request " . $wsName . " - action=update_client_web ######", "info");
            $editCustomers = $dao->getLastUpdateCustomers($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($editCustomers) {
                foreach ($editCustomers as $customer) {
                    $xmlCustomer = XML::createCustomerXml($customer);
                    $login = $customer["id_customer"];
                    Log::write("Send request for login =  "******" - ", "info");
                    $response = $postOSIReq->wso_p025($xmlCustomer, $login);
                    if (!isOkPostResult($response->getCode())) {
                        $isOkResponses = false;
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
    }
}