PluginProbe
MBE eShip / trunk
MBE eShip vtrunk
2.8.1 trunk 1.0.0 1.1.0 1.1.3 1.2.1 1.2.2 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.2.1 All 37 releases
mail-boxes-etc / lib / Model / CsvPackage.php

CsvPackage.php in MBE eShip trunk, at lib/Model/CsvPackage.php

123 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Mbe_Shipping_Model_Csv_Package implements Mbe_Shipping_Entity_Model_Interface
4 {
5 use \Traits\Mbe_Entity_Model_Trait {
6 insertRow as protected traitInserRow;
7 truncate as protected traitTruncate;
8 tableExists as protected traitTableExists;
9 insertRow as protected traitInsertRow;
10 updateRow as protected traitUpdateRow;
11 }
12
13 protected $packagesProductModel;
14
15 public function __construct() {
16 $this->packagesProductModel = new Mbe_Shipping_Model_Csv_Package_Product();
17 }
18
19 public function tableExists() {
20 return $this->traitTableExists($this->getTableName());
21 }
22
23 public function truncate() {
24 return $this->traitTruncate($this->getTableName());
25 }
26
27 public function insertRow($row ) {
28 return $this->traitInserRow($this->getTableName(), $row);
29 }
30
31 public function updateRow($id, $row ) {
32 return $this->traitUpdateRow($this->getTableName(), $id, $row);
33 }
34
35 public function getTableName() {
36 global $wpdb;
37 return $wpdb->prefix . Mbe_Shipping_Helper_Data::MBE_CSV_PACKAGES_TABLE_NAME;
38 }
39
40 public function getSqlCreate() {
41 global $wpdb;
42 $charset = $wpdb->get_charset_collate();
43
44 return "CREATE TABLE " . $this->getTableName() . " (
45 max_weight decimal(12,4) default 0 not null,
46 length decimal(12,4) default 0 not null,
47 width decimal(12,4) default 0 not null,
48 height decimal(12,4) default 0 not null,
49 package_label varchar(255) not null,
50 package_code varchar(55) not null,
51 id int(10) unsigned auto_increment,
52 primary key (id),
53 unique key wp_mbe_shipping_standard_packages_package_code_uindex (package_code)
54 ) $charset;";
55 }
56
57 public function getPackageInfobyProduct( $productSku ) {
58 global $wpdb;
59 $main_table = $this->getTableName();
60 $packagesProduct = $this->packagesProductModel->getTableName();
61
62 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
63 return $wpdb->get_results( $wpdb->prepare(
64 "SELECT $main_table.*," .
65 " $packagesProduct.id as id_product, $packagesProduct.single_parcel, $packagesProduct.custom_package " .
66 " FROM $main_table " .
67 " LEFT JOIN $packagesProduct ON " .
68 " $main_table.package_code = $packagesProduct.package_code " .
69 " WHERE $packagesProduct.product_sku = %s"
70 , $productSku
71 ), ARRAY_A );
72 }
73
74 public function getStandardPackages() {
75 global $wpdb;
76 $main_table = $this->getTableName();
77 $join_table = $this->packagesProductModel->getTableName();
78
79 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
80 return $wpdb->get_results(
81 "SELECT $main_table.package_label, $main_table.id FROM $main_table" .
82 " LEFT JOIN $join_table ON " .
83 " $main_table.package_code = $join_table.package_code " .
84 " WHERE $join_table.custom_package <> true OR $join_table.custom_package is null"
85 , ARRAY_A );
86 }
87
88 public function getStandardPackagesFullData() {
89 global $wpdb;
90 $main_table = $this->getTableName();
91 $join_table = $this->packagesProductModel->getTableName();
92
93 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
94 return $wpdb->get_results(
95 "SELECT $main_table.* FROM $main_table" .
96 " LEFT JOIN $join_table ON " .
97 " $main_table.package_code = $join_table.package_code " .
98 " WHERE $join_table.custom_package <> true OR $join_table.custom_package is null"
99 , ARRAY_A );
100 }
101
102 public function getCsvPackages() {
103 global $wpdb;
104 $main_table = $this->getTableName();
105
106 return $wpdb->get_results($wpdb->prepare("SELECT * FROM %i ", $main_table), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
107
108 }
109
110 public function getPackageInfobyId( $packageId ) {
111 global $wpdb;
112 $main_table = $this->getTableName();
113
114 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
115 $a = $wpdb->get_results( $wpdb->prepare(
116 "SELECT *, 0 as single_parcel, 0 as custom_package FROM $main_table " .
117 " WHERE id = %d"
118 , $packageId )
119 , ARRAY_A );
120 return $a;
121 }
122
123 }