public function __construct($identifiant = null, $enseigne = null, $addresse = null)
 {
     parent::__construct();
     $this->childIdentifiant($identifiant);
     $this->childEnseigne($enseigne);
     $this->childAdresse($addresse);
 }
 public function __construct($produits = array())
 {
     parent::__construct("<list nbproduit='0'></list>");
     foreach ($produits as $produit) {
         $this->addProduit($produit);
     }
 }
 public function __construct(array $params = array())
 {
     parent::__construct();
     foreach ($params as $key => $value) {
         $funcname = "child{$key}";
         $this->{$funcname}($value);
     }
 }
 public function __construct($type = "", $nom = "", $rapidite = "", $pointrelais = array())
 {
     parent::__construct();
     $this->childType($type);
     $this->childNom($nom);
     $this->childRapidite($rapidite);
     $this->childPointrelais($pointrelais);
 }
 public function __construct($siteid, $refid, $montant, $ip, $timestamp, $devise = "EUR")
 {
     parent::__construct();
     $this->childSiteid($siteid, array());
     $this->childRefid($refid, array());
     $this->childMontant($montant, array('devise' => $devise));
     $this->childIp($ip, array('timestamp' => $timestamp));
 }
 public function __call($name, array $params)
 {
     //fonction returnItem : retourne la valeur de l'attribute Item si existant, null sinon
     if (preg_match('#^return.+$#', $name)) {
         $elementname = strtolower(preg_replace('#^return(.+)$#', '$1', $name));
         return array_key_exists($elementname, $this->getAttributes()) ? $this->getAttribute($elementname) : null;
     }
     return parent::__call($name, $params);
 }
 public function __construct($type = null, $nom = null, $bin = null, $numcb = null, $dateval = null, $bin4 = null, $bin42 = null)
 {
     parent::__construct();
     $this->childType($type);
     $this->childNom($nom);
     $this->childBin($bin);
     $this->childNumcb($numcb);
     $this->childDateval($dateval);
     $this->childBin4($bin4);
     $this->childBin42($bin42);
 }
 public function __construct($type = null, $civility = null, $lastname = null, $firstname = null, $society = null, $phone_home = null, $phone_mobile = null, $phone_fax = null, $email_address = null)
 {
     parent::__construct();
     if (!is_null($type)) {
         $this->addAttribute("type", $type);
     }
     $this->addAttribute("qualite", self::TYPE_PARTICULIER);
     $this->childNom($lastname, array('titre' => $civility));
     $this->childPrenom($firstname);
     $this->childSociete($society);
     $this->childTelhome($phone_home);
     $this->childTelmobile($phone_mobile);
     $this->childFax($phone_fax);
     $this->childEmail($email_address);
 }
 public function __construct($type = null, $rue1 = null, $rue2 = null, $cpostal = null, $ville = null, $pays = null, XMLElement $appartement = null)
 {
     parent::__construct();
     if (!is_null($type)) {
         $this->addAttribute('type', $type);
     }
     $this->addAttribute('format', self::FORMAT);
     $this->childRue1($rue1);
     $this->childRue2($rue2);
     $this->childCpostal($cpostal);
     $this->childVille($ville);
     $this->childPays($pays);
     if (!is_null($appartement)) {
         $this->childAppartement($appartement);
     }
 }
 private function buildXMLOrder($id_order)
 {
     CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, 'construction du flux pour order ' . $id_order);
     $order = new Order($id_order);
     //gets back the delivery address
     $address_delivery = new Address((int) $order->id_address_delivery);
     //gets back the invoice address
     $address_invoice = new Address((int) $order->id_address_invoice);
     //gets back the customer
     $customer = new Customer((int) $order->id_customer);
     //initializatino of the XML root: <control>
     $xml_element_control = new CertissimControl();
     //gets the lang used in the order
     $id_lang = $order->id_lang;
     //sets the gender, depends on PS version
     if (_PS_VERSION_ < '1.5') {
         $gender = $customer->id_gender == 2 ? $this->l('Ms.') : $this->l('Mr.');
     } else {
         $customer_gender = new Gender($customer->id_gender);
         $lang_id = Language::getIdByIso('en');
         if (empty($lang_id)) {
             $lang_id = Language::getIdByIso('fr');
         }
         CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "id_gender = " . $customer->id_gender . ", gender name =" . $customer_gender->name[$lang_id]);
         $gender = $this->l($customer_gender->name[$lang_id]);
     }
     //initialization of the element <utilisateur type='facturation'...>
     $xml_element_invoice_customer = new CertissimUtilisateur('facturation', $gender, $address_invoice->lastname, $address_invoice->firstname, $address_invoice->company, $address_invoice->phone, $address_invoice->phone_mobile, null, $customer->email);
     //gets customer stats
     $customer_stats = $customer->getStats();
     //gets already existing orders for the customer
     $all_orders = Order::getCustomerOrders((int) $customer->id);
     //initialization of the element <siteconso>
     $xml_element_invoice_customer_stats = new CertissimSiteconso($customer_stats['total_orders'], $customer_stats['nb_orders'], $all_orders[count($all_orders) - 1]['date_add'], count($all_orders) > 1 ? $all_orders[1]['date_add'] : null);
     //gets back the invoice country
     $country = new Country((int) $address_invoice->id_country);
     //initialization of the element <adresse type="facturation" ...>
     $xml_element_invoice_address = new CertissimAdresse('facturation', $address_invoice->address1, $address_invoice->address2, $address_invoice->postcode, $address_invoice->city, $country->name[$id_lang]);
     //gets back the carrier used for this order
     $carrier = new Carrier((int) $order->id_carrier);
     //gets the carrier certissim type
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop);
     } else {
         $carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE');
     }
     //if the order is to be delivered at home: element <utilisateur type="livraison"...> has to be added
     if ($carrier_type == 4) {
         //initialization of the element <utilisateur type="livraison" ...>
         $xml_element_delivery_customer = new CertissimUtilisateur('livraison', $customer->id_gender == 2 ? $this->l('Miss') : $this->l('Mister'), $address_delivery->lastname, $address_delivery->firstname, $address_delivery->company, $address_delivery->phone, $address_delivery->phone_mobile, null, $customer->email);
         //gets back the delivery country
         $country = new Country((int) $address_delivery->id_country);
         //initialization of the element <adresse type="livraison" ...>
         $xml_element_delivery_address = new CertissimAdresse('livraison', $address_delivery->address1, $address_delivery->address2, $address_delivery->postcode, $address_delivery->city, $country->name[$id_lang], null);
     }
     //gets the used currency
     $currency = new Currency((int) $order->id_currency);
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $siteid = Configuration::get('CERTISSIM_SITEID', null, null, $order->id_shop);
     } else {
         $siteid = Configuration::get('CERTISSIM_SITEID');
     }
     //initialize the element <infocommande>
     $xml_element_order_details = new CertissimInfocommande($siteid, $order->id, (string) $order->total_paid, self::getIpByOrder((int) $order->id), date('Y-m-d H:i:s'), $currency->iso_code);
     //gets the order products
     $products = $order->getProducts();
     //define the default product type (depends on PS version)
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE', null, null, $order->id_shop);
     } else {
         $default_product_type = Configuration::get('CERTISSIM_DEFAULT_PRODUCT_TYPE');
     }
     //initialization of the element <list ...>
     $xml_element_products_list = new CertissimProductList();
     //initialize the boolean that says if all the products in the order are downloadables
     $alldownloadables = true;
     foreach ($products as $product) {
         //check if the visited product is downloadable and update the boolean value
         $alldownloadables = $alldownloadables && strlen($product['download_hash']) > 0;
         //gets the main product category
         $product_categories = Product::getProductCategories((int) $product['product_id']);
         $product_category = array_pop($product_categories);
         //initilization of the element <produit ...>
         $xml_element_product = new CertissimXMLElement("<produit></produit>");
         //gets the product certissim category (depends on PS version)
         if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
             $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop);
         } else {
             $product_type = Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE');
         }
         //if a certissim category is set: the type attribute takes the product certissim type value
         if ($product_type) {
             $xml_element_product->addAttribute('type', Configuration::get('CERTISSIM' . $product_category . '_PRODUCT_TYPE', null, null, $order->id_shop));
         } else {
             //if certissim category not set: the type attribute takes the default value
             $xml_element_product->addAttribute('type', $default_product_type);
         }
         //sets the product reference that will be inserted into the XML stream
         //uses the product name by default
         $product_ref = $product['product_name'];
         //prefers ean13 if defined
         if (!empty($product['product_ean13'])) {
             $product_ref = $product['product_ean13'];
         }
         //prefers local reference if defined
         if (!empty($product['product_reference'])) {
             $product_ref = $product['product_reference'];
         }
         //adds attributes ref, nb, prixunit, and sets the value of the element <product> with the product name
         $xml_element_product->addAttribute('ref', CertissimTools::normalizeString($product_ref));
         $xml_element_product->addAttribute('nb', $product['product_quantity']);
         $xml_element_product->addAttribute('prixunit', $product['total_price']);
         $xml_element_product->setValue($product['product_name']);
         //adds the element <product> to the element <list>
         $xml_element_products_list->addProduit($xml_element_product);
     }
     if ($alldownloadables) {
         $real_carrier_type = '5';
     } elseif (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         //if selected carrier fianet type is defined, the type used will be the one got in the Configuration
         if (in_array(Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop), array_keys($this->_carrier_types))) {
             $real_carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE', null, null, $order->id_shop);
             $real_carrier_speed = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_SPEED', null, null, $order->id_shop);
         } else {
             $real_carrier_type = Configuration::get('CERTISSIM_DEFAULT_CARRIER_TYPE', null, null, $order->id_shop);
             $real_carrier_speed = Configuration::get('CERTISSIM_DEFAULT_CARRIER_SPEED', null, null, $order->id_shop);
         }
     } elseif (in_array(Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE'), array_keys($this->_carrier_types))) {
         $real_carrier_type = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_TYPE');
         $real_carrier_speed = Configuration::get('CERTISSIM_' . (string) $carrier->id . '_CARRIER_SPEED');
     } else {
         $real_carrier_type = Configuration::get('CERTISSIM_DEFAULT_CARRIER_TYPE');
         $real_carrier_speed = Configuration::get('CERTISSIM_DEFAULT_CARRIER_SPEED');
     }
     //initialization of the element <transport>
     $xml_element_carrier = new CertissimTransport($real_carrier_type, $alldownloadables ? 'Téléchargement' : Tools::htmlentitiesUTF8($carrier->name), $alldownloadables ? '1' : $real_carrier_speed, null);
     //find the id of the payment module used (depends on the PS version)
     if (_PS_VERSION_ >= '1.5') {
         $id_payment_module = PaymentModule::getModuleIdByName($order->module);
     } else {
         $payment_module = Module::getInstanceByName($order->module);
         $id_payment_module = $payment_module->id;
     }
     //initialization of the element <paiement>
     if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) {
         $payment_type = $this->_payment_types[Configuration::get('CERTISSIM_' . $id_payment_module . '_PAYMENT_TYPE', null, null, $order->id_shop)];
     } else {
         $payment_type = $this->_payment_types[Configuration::get('CERTISSIM_' . $id_payment_module . '_PAYMENT_TYPE')];
     }
     $xml_element_payment = new CertissimPaiement($payment_type);
     //initialization of the element <stack>
     $stack = new CertissimXMLElement("<stack></stack>");
     //agregates each elements in a main stream
     $xml_element_invoice_customer->childSiteconso($xml_element_invoice_customer_stats);
     $xml_element_control->childUtilisateur($xml_element_invoice_customer);
     $xml_element_control->childAdresse($xml_element_invoice_address);
     if (isset($xml_element_delivery_customer)) {
         $xml_element_control->childUtilisateur($xml_element_delivery_customer);
     }
     if (isset($xml_element_delivery_address)) {
         $xml_element_control->childAdresse($xml_element_delivery_address);
     }
     $xml_element_order_details->childTransport($xml_element_carrier);
     $xml_element_order_details->childList($xml_element_products_list);
     $xml_element_control->childInfocommande($xml_element_order_details);
     $xml_element_control->childPaiement($xml_element_payment);
     //add CDATA sections to protect against encoding issues
     $xml_element_control->addCdataSections();
     //add the <control> element into <stack>
     $stack->childControl($xml_element_control);
     CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "---- flux généré pour commande {$id_order} ----");
     CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, $xml_element_control->getXML());
     CertissimLogger::insertLog(__METHOD__ . ' : ' . __LINE__, "---------------------------------------");
     return $stack;
 }
 public function __construct()
 {
     parent::__construct("<control fianetmodule='api_prestashop_certissim' version='3.0' certissimmodule='3.6'></control>");
 }
	 * @return bool 
	 */
    public function isEmpty()
    {
        return ($this->getValue() == "" || is_null($this->getValue())) && $this->countChildren() == 0;
    }
    /**
	 * returns the current object child count
	 *
	 * @return int
	 */
    public function countChildren()
    {
        return count($this->children);
    }
    /**
	 * returns the current object as a SimpleXMLElement object
	 * 
	 * @param boolean $recursive allow to add children into the result
	 * @return SimpleXMLElement 
	 */
    public function toSimpleXMLElement($recursive = false)
    {
        $simplexlmelementobject = new SimpleXMLElement('<' . $this->getName() . '>' . $this->getValue() . '</' . $this->getName() . '>');
        foreach ($this->getAttributes() as $name => $value) {
            $simplexlmelementobject->addAttribute($name, $value);
        }
        if ($recursive) {
            $this->attachChildren($simplexlmelementobject);
        }
        return $simplexlmelementobject;
    }
    /**
	 * attaches all the children and their children of the current object to the object given in parameter
	 * 
	 * @param SimpleXMLElement $simplexmlelement
	 */
    public function attachChildren($simplexmlelement)
    {
        foreach ($this->getChildren() as $child) {
            $simplexmlelement_child = $simplexmlelement->addChild($child->getName(), $child->getValue());
            foreach ($child->getAttributes() as $name => $value) {
                $simplexmlelement_child->addAttribute($name, $value);
            }
            $child->attachChildren($simplexmlelement_child);
        }
    }
    /**
 /**
  * sends a stack of transactions to Certissim stackfast.cgi WS
  *
  * @param XMLElement $stack
  * @return string script response
  */
 public function sendStackfast(CertissimXMLElement $stack)
 {
     $data = array('siteid' => $this->getSiteId(), 'controlcallback' => $stack->getXML());
     $con = new CertissimFianetSocket($this->getUrlstacking(), 'POST', $data);
     return new CertissimXMLElement($con->send());
 }