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 flagAsDeleted($model)
 {
     $local_id = $this->getId($model);
     error_log("flag as deleted entity={$this->connec_entity_name}, local_id={$local_id}");
     MnoIdMap::deleteMnoIdMap($local_id, $this->local_entity_name);
 }
 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'];
             }
         }
     }
 }
 protected function persistLocalModel($user, $resource_hash)
 {
     // Will be used to check if the user already exist locally
     $mno_id_map = MnoIdMap::findMnoIdMapByMnoIdAndEntityName($resource_hash['id'], 'APPUSER', 'USERS');
     $user->save("Users", false);
     // We make sure that the mnoIdMap is created before we start to parse the user's teams to bloc kany eventual recursive loop
     $this->findOrCreateIdMap($resource_hash, $user);
     // Add user to corresponding teams
     if (!$mno_id_map) {
         // User does not exist locally => we add him to its teams
         $mno_teams = $resource_hash['teams'];
         $team_mapper = new TeamMapper();
         for ($j = 0; $j < count($mno_teams); $j++) {
             $team_hash = $mno_teams[$j];
             // Retrieve the local group if exists or create it based on data from Connec! Entity::Team otherwise
             $group_model = $team_mapper->fetchConnecResource($team_hash['id']);
             $group_members = array_keys($group_model->getMembers()["Users"]);
             // At this stage, the user should exist (has been saved before), and have an id defined
             array_push($group_members, "Users:" . json_encode($user->id));
             $group_model->set('group_members', $group_members);
             // Will save the new users list for the team
             $team_mapper->persistLocalModel($group_model, null);
         }
     }
 }