protected function mapModelToConnecResource($payment) { $payment_hash = array(); $paymentObj = $payment['paymentCC']; $cart = $payment['cart']; $payment_hash['type'] = 'CUSTOMER'; // Missing payment lines are considered as deleted by Connec! $payment_hash['opts'] = array('sparse' => false); // Map the Customer $customerMnoIdMap = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($cart->id_customer, 'CUSTOMERS'); $payment_hash['person_id'] = $customerMnoIdMap['mno_entity_guid']; // Load the Customer Data $customerInfo = $this->loadCustomerByID($cart->id_customer); // Load the Sales and Order ID $idsData = $this->getInvoiceOrderID($paymentObj->id, $paymentObj->order_reference); $payment_hash['payment_reference'] = $paymentObj->order_reference; ///////////////////// $payment_hash['private_note'] = 'Generated by Prestashop\\nPayment for order #' . $idsData['id_order'] . " (" . $customerInfo['firstname'] . " " . $customerInfo['lastname'] . ")"; $payment_hash['total_amount'] = $paymentObj->amount; //get Currecy Code $currecy_code = $this->getCurrencyCode($paymentObj->id_currency); $payment_hash['currency'] = $currecy_code['iso_code']; $payment_method = $this->payment_method_mapping_reverse[$paymentObj->payment_method]; $payment_hash['payment_method'] = array('code' => $payment_method); // Map the Invoice if ($idsData['id_order_invoice'] > 0) { $invoiceMnoIdMap = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($idsData['id_order_invoice'], 'INVOICE'); $linked_transaction = array('id' => $invoiceMnoIdMap['mno_entity_guid'], 'class' => 'Invoice'); } else { // Map the Sales Order $orderMnoIdMap = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($idsData['id_order'], 'SALESORDERS'); $linked_transaction = array('id' => $orderMnoIdMap['mno_entity_guid'], 'class' => 'SalesOrder'); } $payment_line = array('line_number' => 1, 'amount' => $paymentObj->amount, 'status' => 'ACTIVE', 'linked_transactions' => array(0 => $linked_transaction)); $payment_hash['payment_lines'] = array(0 => $payment_line); return $payment_hash; }
public static function mapTaxToConnecResource($product, &$product_hash) { $sql = "SELECT * FROM " . _DB_PREFIX_ . "tax_rule WHERE id_tax_rules_group = '" . pSQL($product->id_tax_rules_group) . "'"; if ($row = Db::getInstance()->getRow($sql)) { if ($row['id_tax'] > 0) { $mno_id_map = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($row['id_tax'], 'TAXRECORD'); if ($mno_id_map) { $product_hash['sale_tax_code_id'] = $mno_id_map['mno_entity_guid']; } } } }
protected function pushToConnec($model, $saveResult = false) { error_log("push entity to connec entity={$this->connec_entity_name}, local_id=" . $this->getId($model)); // Transform the Model into a Connec hash $resource_hash = $this->mapModelToConnecResource($model); $hash = array($this->connec_resource_name => $resource_hash); error_log("generated connec hash " . json_encode($hash)); // Find Connec resource id $local_id = $this->getId($model); $mno_id_map = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($local_id, $this->local_entity_name); if ($mno_id_map) { // Update resource $url = $this->connec_resource_endpoint . '/' . $mno_id_map['mno_entity_guid']; error_log("updating entity={$this->local_entity_name}, url={$url}, id={$local_id} hash=" . json_encode($hash)); $response = $this->_connec_client->put($url, $hash); } else { // Create resource $url = $this->connec_resource_endpoint; error_log("creating entity={$this->local_entity_name}, url={$url}, hash=" . json_encode($hash)); $response = $this->_connec_client->post($url, $hash); } // Process Connec response $code = $response['code']; $body = $response['body']; if ($code >= 300) { error_log("Cannot push to Connec! entity_name={$this->local_entity_name}, code={$code}, body={$body}"); return false; } else { error_log("Processing Connec! response code={$code}, body={$body}"); $result = json_decode($body, true); if ($saveResult) { // Save the complete response error_log("saving back entity_name={$this->local_entity_name}"); return $this->saveConnecResource($result[$this->connec_resource_name], true, $model); } else { // Map the Connec! ID with the local one error_log("mapping back entity_name={$this->local_entity_name}"); $this->findOrCreateIdMap($result[$this->connec_resource_name], $model); // Custom response processing error_log("processing back entity_name={$this->local_entity_name}"); $this->processConnecResponse($result[$this->connec_resource_name], $model); return $model; } } }
public static function mapTaxToConnecResource($product_id) { $sql = "SELECT t.id_tax FROM " . _DB_PREFIX_ . "product p INNER JOIN " . _DB_PREFIX_ . "tax_rule t ON p.id_tax_rules_group = t.id_tax_rules_group WHERE p.id_product = '" . pSQL($product_id) . "'"; if ($row = Db::getInstance()->getRow($sql)) { if ($row['id_tax'] > 0) { $mno_id_map = MnoIdMap::findMnoIdMapByLocalIdAndEntityName($row['id_tax'], 'TAXRECORD'); if ($mno_id_map) { return $mno_id_map['mno_entity_guid']; } } } }