Last active
June 29, 2020 08:59
-
-
Save jackbillstrom/0c71c099ec83e3eddd7f0f932801cbc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// /product-options-for-woocommerce/Model/Option.php | |
public function saveOptions($productId, $options) { | |
$productId = (int)$productId; | |
// Här kommer alla värden samlas upp efter loopen | |
// tänk på att loopen svarar RAD FÖR RAD | |
$lens_options = array(); | |
foreach ($options as $option) { | |
$optionId = (int)$option['option_id']; | |
if (isset($option['is_delete']) && $option['is_delete'] == 1) { | |
$this->deleteOption($optionId); | |
continue; | |
} | |
$title = esc_sql($option['title']); | |
$type = esc_sql($option['type']); | |
$required = isset($option['required']) && $option['required'] == 1 ? 1 : 0; | |
$sortOrder = (int)$option['sort_order']; | |
$price = isset($option['price']) ? (float)$option['price'] : 0; | |
if ($optionId > 0) { | |
$this->_wpdb->query("UPDATE {$this->_mainTable} SET title = '{$title}', type = '{$type}', required = {$required}, sort_order = {$sortOrder}, price = {$price} WHERE option_id = {$optionId}"); | |
} else { | |
// Motsvarar en rad i ur tabeller 'wp_pofw_product_option' | |
$lens_option[] = array('title' => $title, 'type' => $type, 'required' => $required, 'sort_order' => $sortOrder, 'values' => $option['values']); | |
// Pushar till den stora arrayen, en gång per option | |
array_push($lens_options, $lens_option); | |
//$this->_wpdb->query("INSERT INTO {$this->_mainTable} SET product_id = {$productId}, title = '{$title}', type = '{$type}', required = {$required}, sort_order = {$sortOrder}, price = {$price}"); | |
//$optionId = $this->_wpdb->insert_id; | |
} | |
//if (isset($option['values'])){ | |
//$this->_value->saveValues($productId, $optionId, $option['values']); | |
//} | |
} | |
// osäker om $this funkar utanför scope't forEach... | |
$this->_wpdb->query("INSERT INTO {$this}_posts SET lens_field = {$lens_options} WHERE ID = {$productId}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment