~magentoerpconnect-core-editors/magentoerpconnect/module-magento-trunk

« back to all changes in this revision

Viewing changes to Openlabs_OpenERPConnector-1.1.0/Openlabs/OpenERPConnector/Model/Sales/Order/Api.php

  • Committer: Mohammed.Nahhas at dacrydium
  • Date: 2011-06-08 13:35:25 UTC
  • Revision ID: mohammed.nahhas@dacrydium.fr-20110608133525-q7ghbp8l9rxfyzx9
[ADD] Missing files for previous revision (25th)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class Openlabs_OpenERPConnector_Model_Sales_Order_Api extends Mage_Sales_Model_Order_Api {
 
4
        
 
5
        public function retrieveOrders($data) {
 
6
                                
 
7
            $result = array();
 
8
                if(isset($data['imported'])) {
 
9
                        $billingAliasName = 'billing_o_a';
 
10
                $shippingAliasName = 'shipping_o_a';
 
11
                
 
12
                $collection = Mage::getModel("sales/order")->getCollection()
 
13
                    ->addAttributeToSelect('*')
 
14
                    ->addAttributeToFilter('imported', array('eq' => $data['imported']))
 
15
                    ->addAddressFields()
 
16
                    ->addExpressionFieldToSelect(
 
17
                        'billing_firstname', "{{billing_firstname}}", array('billing_firstname'=>"$billingAliasName.firstname")
 
18
                    )
 
19
                    ->addExpressionFieldToSelect(
 
20
                        'billing_lastname', "{{billing_lastname}}", array('billing_lastname'=>"$billingAliasName.lastname")
 
21
                    )
 
22
                    ->addExpressionFieldToSelect(
 
23
                        'shipping_firstname', "{{shipping_firstname}}", array('shipping_firstname'=>"$shippingAliasName.firstname")
 
24
                    )
 
25
                    ->addExpressionFieldToSelect(
 
26
                        'shipping_lastname', "{{shipping_lastname}}", array('shipping_lastname'=>"$shippingAliasName.lastname")
 
27
                    )
 
28
                    ->addExpressionFieldToSelect(
 
29
                            'billing_name',
 
30
                            "CONCAT({{billing_firstname}}, ' ', {{billing_lastname}})",
 
31
                            array('billing_firstname'=>"$billingAliasName.firstname", 'billing_lastname'=>"$billingAliasName.lastname")
 
32
                    )
 
33
                    ->addExpressionFieldToSelect(
 
34
                            'shipping_name',
 
35
                            'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
 
36
                            array('shipping_firstname'=>"$shippingAliasName.firstname", 'shipping_lastname'=>"$shippingAliasName.lastname")
 
37
                    );
 
38
                    
 
39
                if(isset($data['limit'])) {
 
40
                        $collection->setPageSize($data['limit']);
 
41
                        $collection->setOrder('entity_id', 'ASC');
 
42
                }
 
43
                
 
44
                if(isset($data['filters']) && is_array($data['filters'])) {
 
45
                        $filters = $data['filters'];
 
46
                        foreach($filters as $field => $value) {
 
47
                                $collection->addAttributeToFilter($field, $value);
 
48
                        }
 
49
                }
 
50
 
 
51
                foreach ($collection as $order) {
 
52
                    $result[] = $this->_getAttributes($order, 'order');
 
53
                }
 
54
                return $result;
 
55
                }else{
 
56
                        $this->_fault('data_invalid', "erreur, l'attribut 'imported' doit être spécifié");
 
57
                }
 
58
        }
 
59
        
 
60
        public function setFlagForOrder($incrementId) {
 
61
                $_order = $this->_initOrder($incrementId);
 
62
                $_order->setImported(1);
 
63
                try {
 
64
                        $_order->save();
 
65
                        return true;
 
66
                } catch (Mage_Core_Exception $e) {
 
67
            $this->_fault('data_invalid', $e->getMessage());
 
68
        }
 
69
        }
 
70
        
 
71
        /* Récupère l'increment_id de la commande fille créée, retourne un string exemple : 100004997-1 */
 
72
    public function getOrderChild($incrementId) {
 
73
        
 
74
        $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
 
75
        /**
 
76
          * Check order existing
 
77
          */
 
78
        if (!$order->getId()) {
 
79
             $this->_fault('order_not_exists');
 
80
        }
 
81
        
 
82
        if($order->getRelationChildId()) {
 
83
                return $order->getRelationChildRealId();
 
84
        }else{
 
85
                return false;
 
86
        }
 
87
    }
 
88
    
 
89
    /* Récupère l'increment_id de la commande mère annulée, retourne un string exemple : 100004997 */
 
90
    public function getOrderParent($incrementId) {
 
91
        
 
92
        $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
 
93
        /**
 
94
          * Check order existing
 
95
          */
 
96
        if (!$order->getId()) {
 
97
             $this->_fault('order_not_exists');
 
98
        }
 
99
        
 
100
        if($order->getRelationParentId()) {
 
101
                return $order->getRelationParentRealId();
 
102
        }else{
 
103
                return false;
 
104
        }
 
105
    }
 
106
}
 
 
b'\\ No newline at end of file'