settingGetChanges($lastChange + 1); if ($changes->Success) { update_option('hesabix_business_expired', 0); foreach ($changes->Result as $item) { if (!$item->API) { switch ($item->ObjectType) { case 'Invoice': if ($item->Action == 123) { $wpFa1 = $wpFaService->getWpFaByHesabixId('order', $item->Extra2); if ($wpFa1) { $wpFaService->delete($wpFa1); HesabixLogService::writeLogStr("The invoice link with the order deleted. Invoice number: " . $item->Extra2 . ", Order id: " . $wpFa1->idWp); } } $this->invoicesObjectId[] = $item->ObjectId; foreach (explode(',', $item->Extra) as $invoiceItem) { if ($invoiceItem != '') { $this->invoiceItemsCode[] = $invoiceItem; } } break; case 'WarehouseReceipt': if ($item->Action == 261) { global $wpdb; $hesabixApi = new Hesabix_Api(); $receipt = $hesabixApi->getWarehouseReceipt($item->ObjectId); foreach ($receipt->Result->Items as $receiptItem) { $wpFa = $wpFaService->getWpFaByHesabixId('product', $receiptItem->ItemCode); $wpdb->insert($wpdb->prefix . 'hesabix', array( 'id_hesabix' => (int) $item->ObjectId, 'obj_type' => "receiptItems", 'id_ps' => $wpFa->idWp, 'id_ps_attribute' => $wpFa->idWpAttribute )); } if (get_option('hesabix_item_update_quantity', 'no') == 'no') { HesabixLogService::writeLogStr("Sync Products Quantity is Off"); } } if ($item->Action == 263) { global $wpdb; $rows = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_hesabix` = $item->ObjectId"); $receiptID = $item->ObjectId; foreach ($rows as $row) { $post_id = ($row->id_ps_attribute && $row->id_ps_attribute > 0) ? $row->id_ps_attribute : $row->id_ps; if (get_option('hesabix_item_update_quantity', 'no') == 'no') { HesabixLogService::writeLogStr("Sync Products Quantity is Off"); } $productId = $row->id_ps; $attributeId = $row->id_ps_attribute; if (get_option('hesabix_item_update_quantity', 'no') == 'yes') update_post_meta($attributeId, '_manage_stock', 'yes'); if ($productId == $attributeId) $attributeId = 0; $result = array(); $wpFaService = new HesabixWpFaService(); $wpFa = $wpFaService->getWpFa('product', $productId, $attributeId); if ($wpFa) { $api = new Hesabix_Api(); // $warehouse = get_option('hesabix_item_update_quantity_based_on', "-1"); // if ($warehouse == "-1") // $response = $api->itemGet($wpFa->idHesabix); // else { // $response = $api->itemGetQuantity($warehouse, array($wpFa->idHesabix)); // } $response = $api->itemGet($wpFa->idHesabix); if ($response->Success) { // $item = $warehouse == "-1" ? $response->Result : $response->Result[0]; $item = $response->Result; $newProps = Hesabix_Admin_Functions::setItemChanges($item); } else { HesabixLogService::writeLogStr("Product is not defined in Hesabix"); } } } $wpdb->delete($wpdb->prefix . 'hesabix', array('id_hesabix' => $receiptID)); break; } $this->warehouseReceiptsObjectId[] = $item->ObjectId; break; case 'Product': if ($item->Action == 53) { $wpFa = $wpFaService->getWpFaByHesabixId('product', $item->Extra); if ($wpFa) { global $wpdb; $wpdb->delete($wpdb->prefix . 'hesabix', array('id' => $wpFa->id)); } break; } $this->itemsObjectId[] = $item->ObjectId; break; case 'Contact': if ($item->Action == 33) { $id_obj = $wpFaService->getWpFaIdByHesabixId('customer', $item->Extra); global $wpdb; $wpdb->delete($wpdb->prefix . 'hesabix', array('id' => $id_obj)); break; } $this->contactsObjectId[] = $item->ObjectId; break; } } } $this->invoiceItemsCode = array_unique($this->invoiceItemsCode); $this->contactsObjectId = array_unique($this->contactsObjectId); $this->itemsObjectId = array_unique($this->itemsObjectId); $this->invoicesObjectId = array_unique($this->invoicesObjectId); $this->setChanges(); $lastChange = end($changes->Result); if (is_object($lastChange)) update_option('hesabix_last_log_check_id', $lastChange->Id); else if ($changes->LastId) update_option('hesabix_last_log_check_id', $changes->LastId); } else { HesabixLogService::log(array("hesabix - Cannot check last changes. Error Message: " . (string) $changes->ErrorMessage . ". Error Code: " . (string) $changes->ErrorCode)); if ($changes->ErrorCode == 108) { update_option('hesabix_business_expired', 1); add_action('admin_notices', array(__CLASS__, 'hesabix_business_expired_notice')); } return false; } return true; } public function hesabix_business_expired_notice() { echo '
' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . '