css
1 year ago
img
1 year ago
js
1 year ago
partials
1 year ago
class-email.php
1 year ago
class-eqw-advance.php
1 year ago
class-eqw-enquiry-cart.php
1 year ago
class-eqw-enquiry-shortcode.php
1 year ago
class-eqw-product.php
1 year ago
class-eqw-save-enquiry.php
1 year ago
class-pisol-enquiry-quotation-woocommerce-public.php
1 year ago
class-pisol-form.php
1 year ago
class-webhook.php
1 year ago
index.php
1 year ago
class-eqw-save-enquiry.php
141 lines
| 1 | <?php |
| 2 | |
| 3 | class class_eqw_save_enquiry{ |
| 4 | |
| 5 | public $items; |
| 6 | public $products; |
| 7 | public $title; |
| 8 | public $name; |
| 9 | public $email; |
| 10 | public $phone; |
| 11 | public $subject; |
| 12 | public $message; |
| 13 | public $enquiry_id; |
| 14 | |
| 15 | function __construct($items){ |
| 16 | $this->items = $items; |
| 17 | $this->products = class_eqw_enquiry_cart::getProductsInEnquirySession(); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | function getOrderTitle(){ |
| 22 | $this->title = isset($_POST['pi_name']) ? sanitize_text_field($_POST['pi_name']) : __('Order'); |
| 23 | return $this->title; |
| 24 | } |
| 25 | |
| 26 | function getName(){ |
| 27 | $this->name = isset($_POST['pi_name']) ? sanitize_text_field($_POST['pi_name']) : ""; |
| 28 | return $this->name; |
| 29 | } |
| 30 | |
| 31 | function getEmail(){ |
| 32 | $this->email = isset($_POST['pi_email']) ? sanitize_email($_POST['pi_email']) : ""; |
| 33 | return $this->email; |
| 34 | } |
| 35 | |
| 36 | function getPhone(){ |
| 37 | $this->phone = isset($_POST['pi_phone']) ? sanitize_text_field($_POST['pi_phone']) : ""; |
| 38 | return $this->phone; |
| 39 | } |
| 40 | |
| 41 | function getSubject(){ |
| 42 | $this->subject = isset($_POST['pi_subject']) ? sanitize_text_field($_POST['pi_subject']) : ""; |
| 43 | return $this->subject; |
| 44 | } |
| 45 | |
| 46 | function getMessage(){ |
| 47 | $this->message = isset($_POST['pi_message']) ? sanitize_text_field($_POST['pi_message']) : ""; |
| 48 | return $this->message; |
| 49 | } |
| 50 | |
| 51 | function createEnquiry(){ |
| 52 | $products_info = $this->staticProducts(); |
| 53 | |
| 54 | if(!is_serialized($products_info)) return false; |
| 55 | |
| 56 | $arg = $this->newOrderArgument(); |
| 57 | $return = wp_insert_post($arg); |
| 58 | if($return == 0 || is_wp_error($return) ){ |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | update_post_meta($return, 'pi_products_info', wp_slash($products_info)); |
| 64 | |
| 65 | $products_id = $this->products_array(); |
| 66 | update_post_meta($return, 'pi_products_id', $products_id); |
| 67 | $this->enquiry_id = $return; |
| 68 | |
| 69 | do_action('pisol_eqw_enquiry_saved', $return); |
| 70 | |
| 71 | return $return; |
| 72 | } |
| 73 | |
| 74 | function newOrderArgument(){ |
| 75 | $arg = array( |
| 76 | 'post_title' => $this->getOrderTitle(), |
| 77 | 'post_type'=>'pisol_enquiry', |
| 78 | 'post_status' => 'publish', |
| 79 | 'meta_input' => array( |
| 80 | 'pi_name' => $this->getName(), |
| 81 | 'pi_email' => $this->getEmail(), |
| 82 | 'pi_phone'=> $this->getPhone(), |
| 83 | 'pi_subject'=> $this->getSubject(), |
| 84 | 'pi_message'=> $this->getMessage() |
| 85 | ) |
| 86 | ); |
| 87 | return $arg; |
| 88 | } |
| 89 | |
| 90 | function staticProducts(){ |
| 91 | $static_products = array(); |
| 92 | foreach($this->products as $product){ |
| 93 | $static_products[] = $this->staticProduct($product); |
| 94 | } |
| 95 | return serialize($static_products); |
| 96 | } |
| 97 | |
| 98 | function products_array(){ |
| 99 | $products_id = array(); |
| 100 | foreach($this->products as $product){ |
| 101 | $products_id[] = $product['id']; |
| 102 | } |
| 103 | return $products_id; |
| 104 | } |
| 105 | |
| 106 | function staticProduct($product){ |
| 107 | $product_obj = wc_get_product($product['id']); |
| 108 | $product_permalink = $product_obj->get_permalink(); |
| 109 | $image_id = $product_obj->get_image_id(); |
| 110 | $img = wp_get_attachment_thumb_url($image_id); |
| 111 | $price = strip_tags(wc_price(class_eqw_enquiry_shortcode::get_price_simple_variation($product_obj, $product['variation']))); |
| 112 | $variation_id = ($product['variation'] != false ? (int)$product['variation'] : false); |
| 113 | $variation_detail = $this->variation_detail($product_obj, $product['variation_detail']); |
| 114 | $return = array( |
| 115 | 'name' => $product_obj->get_name(), |
| 116 | 'img' => $img, |
| 117 | 'link'=> $product_permalink, |
| 118 | 'price'=> $price, |
| 119 | 'variation'=> $variation_id, |
| 120 | 'variation_detail'=> $variation_detail, |
| 121 | 'quantity' => $product['quantity'], |
| 122 | 'message' => strip_tags($product['message']) |
| 123 | ); |
| 124 | return ($return); |
| 125 | } |
| 126 | |
| 127 | function variation_detail($product_obj, $product_variation_detail){ |
| 128 | $variations_label = class_eqw_enquiry_shortcode::get_variations($product_obj, $product_variation_detail); |
| 129 | $return = ""; |
| 130 | if(is_array($variations_label)){ |
| 131 | foreach ($variations_label as $key => $value){ |
| 132 | $return .= esc_html($key).'|'.esc_html($value).','; |
| 133 | } |
| 134 | } |
| 135 | return $return; |
| 136 | } |
| 137 | |
| 138 | function save(){ |
| 139 | return $this->createEnquiry(); |
| 140 | } |
| 141 | } |