CASE WHEN p.post_parent>0 THEN ' . $values['variation'] . " WHEN EXISTS(SELECT 1 FROM `#__posts` as pa WHERE pa.post_parent=p.ID AND pa.post_type='product_variation' LIMIT 1) THEN " . $values['variable'] . ' ELSE ' . $values['single'] . ' END' . ' FROM ' . ( $tempTable ? $tempTable : ' `#__posts` ' ) . ' as p' . ' WHERE ' . ( $tempTable ? '1=1' : " p.post_type IN ('product','product_variation') AND p.post_status IN('publish', 'private')" ) . ( empty($productId) ? '' : ' AND p.id=' . $productId ); if (!DbWpf::query($query)) { $this->pushError(DbWpf::getError()); return false; } return true; } public function afterCalcMeta_stock_status( $productId, $keyData, $tempTable ) { $groupedTerm = get_term_by('name', 'grouped', 'product_type', ARRAY_A); if ($groupedTerm && !empty( $groupedTerm['term_id'])) { $grId = $groupedTerm['term_id']; $keyId = $keyData['id']; $instockId = $this->valsModel->getMetaValueId($keyId, 'instock'); $outofstockId = $this->valsModel->getMetaValueId($keyId, 'outofstock'); $query = 'SELECT 1 FROM @__meta_data WHERE key_id=' . $keyId . ' AND val_id!=' . $outofstockId . ' AND product_id IN '; $updateO = 'UPDATE @__meta_data SET val_id=' . $outofstockId . ' WHERE key_id=' . $keyId . ' AND val_id!=' . $outofstockId . ' AND product_id IN '; $updateI = 'UPDATE @__meta_data SET val_id=' . $instockId . ' WHERE key_id=' . $keyId . ' AND val_id!=' . $instockId . ' AND product_id IN '; $controlBundle = FrameWpf::_()->getModule('options')->getModel()->get('index_group_bundle') == 1; $limit = 500; $offset = 0; $limitQuery = ' SELECT p.id, m.meta_id, m.meta_value' . ' FROM ' . ( $tempTable ? $tempTable : ' `#__posts` ' ) . ' as p' . ' INNER JOIN `#__term_relationships` AS tr ON (tr.`object_id`=p.ID AND tr.`term_taxonomy_id`=' . $grId . ') '. " INNER JOIN `#__postmeta` as m ON (m.post_id=p.ID AND m.meta_key='_children' AND m.meta_value!='')" . ' ORDER BY meta_id LIMIT '; do { $q = $limitQuery . $offset . ',' . $limit; $data = DbWpf::get($q,0); if (false === $data) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } $listIdsO = ''; $listIdsI = ''; foreach ($data as $k => $values) { $valuesArr = @unserialize($values['meta_value']); if (is_array($valuesArr)) { if ($controlBundle) { $vars = array(); foreach ($valuesArr as $vId) { $child = wc_get_product($vId); if ($child->get_type() != 'bundle') { $vars[] = $vId; } } } else { $vars = $valuesArr; } if (empty($vars)) { continue; } $q = $query . '(' . implode(',', UtilsWpf::controlNumericValues($vars, 'id')) . ') LIMIT 1'; $exist = DbWpf::get($q, 'one'); if (false === $exist) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } if (is_null($exist)) { $listIdsO .= $values['id'] . ','; } else { $listIdsI .= $values['id'] . ','; } } } if (!empty($listIdsO)) { $q = $updateO . '(' . substr($listIdsO, 0, -1) . ')'; if (!DbWpf::query($q)) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } } if (!empty($listIdsI)) { $q = $updateI . '(' . substr($listIdsI, 0, -1) . ')'; if (!DbWpf::query($q)) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } } $offset += $limit; } while ( !empty($data) && ( count($data) >= $limit ) ); } return true; } public function optimizeMetaTables() { $optimizeTables = array( 'meta_data', 'meta_values', 'meta_values_bk' ); foreach ( $optimizeTables as $table ) { if (!DbWpf::query('OPTIMIZE TABLE `@__' . $table . '`')) { $this->pushError(DbWpf::getError()); return false; } } return true; } public function addCompatibilities( $productId, $tempTable ) { if (class_exists( 'WC_Measurement_Price_Calculator' )) { $keysModel = FrameWpf::_()->getModule('meta')->getModel('meta_keys'); $keyData = $keysModel->getKeyData('_price', false); $keyPrice = empty($keyData) ? false : $keyData['id']; $keyData = $keysModel->getKeyData('_sale_price', false); $keySalePrice = empty($keyData) ? false : $keyData['id']; if (!$keyPrice || !$keySalePrice) { return true; } $isOne = false; if ($tempTable) { $ids = DbWpf::get( 'SELECT id FROM ' . $tempTable, 'col'); } else { $product = wc_get_product($productId); if (!$product) { return true; } $ids = array($productId); if ($product->get_type() == 'variable') { $ids = array_merge($ids, $product->get_children()); } else { $isOne = true; } } if (empty($ids)) { return true; } $query = 'UPDATE @__meta_data SET val_dec='; $whPrice = ' WHERE key_id=' . $keyPrice . ' AND product_id='; $whSalePrice = ' WHERE key_id=' . $keySalePrice . ' AND product_id='; foreach ($ids as $id) { if (!$isOne) { $product = wc_get_product( $id ); if (!$product) { return true; } } $price = ''; $salePrice = ''; $settings = new \WC_Price_Calculator_Settings( $product ); // user-defined calculator with pricing rules enabled (nothing needs to be changed for user-defined calculators with no pricing rules) if ( $settings->pricing_rules_enabled() ) { $price = $settings->get_pricing_rules_maximum_price(); $salePrice = $settings->pricing_rules_is_on_sale() ? $settings->get_pricing_rules_maximum_sale_price() : ''; // quantity calculator with per unit pricing } elseif ( $settings->is_quantity_calculator_enabled() && \WC_Price_Calculator_Product::pricing_per_unit_enabled( $product ) ) { $measurement = null; // for variable products we must synchronize price levels to our per unit price if ( $product->is_type( 'variable' ) ) { // synchronize to the price per unit pricing \WC_Price_Calculator_Product::variable_product_sync( $product, $settings ); // save the original price and remove the filter that we're currently within, to avoid an infinite loop $price = $product->get_variation_price( 'min' ); $salePrice = $product->get_variation_sale_price( 'min' ); // restore the original values \WC_Price_Calculator_Product::variable_product_unsync( $product ); // all other product types } else { $measurement = \WC_Price_Calculator_Product::get_product_measurement( $product, $settings ); if ( $measurement ) { $measurement->set_unit( $settings->get_pricing_unit() ); $measurementValue = $measurement ? $measurement->get_value() : null; if ( $measurement && $measurementValue ) { // convert to price per unit $price = floatval($product->get_price( 'edit' )) / $measurementValue; $salePrice = floatval($product->get_sale_price( 'edit' )) / $measurementValue; } } } } if (!empty($price)) { $q = $query . round($price, 4) . $whPrice . $id; if (!DbWpf::query($q)) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } } if (!empty($salePrice)) { $q = $query . round($salePrice, 4) . $whSalePrice . $id; if (!DbWpf::query($q)) { $this->pushError(DbWpf::getError()); $this->pushError($q); return false; } } } } return true; } public function hasEmojis( $string ) { $emojis_regex = '/[\x{1F600}-\x{1F64F}\x{2700}-\x{27BF}\x{1F680}-\x{1F6FF}\x{24C2}-\x{1F251}\x{1F30D}-\x{1F567}\x{1F900}-\x{1F9FF}\x{1F300}-\x{1F5FF}\x{1FA70}-\x{1FAF6}]/u'; preg_match($emojis_regex, $string, $matches); return ( empty($matches) ? false : true ); } public function controlMetaFieldType( $metaType, $keyName ) { if ( 'wcb2b_product_group_prices' == $keyName ) { $metaType = 8; } return DispatcherWpf::applyFilters('getMetaFieldType', $metaType, $keyName); } public function saveMetaArraywcb2b_product_group_prices( $keyId, $productId, $isVar, $data ) { $insert = ''; $queryValue = '(' . $productId . ',' . $isVar . ',' . $keyId . ','; $keys = $this->keysArray; $valsModel = $this->valsModel; foreach ($data as $k2 => $v2) { $keys['key2'] = $this->getCutKeyValue($k2); if (is_array($v2)) { $v = !empty($v2['sale_price']) ? $v2['sale_price'] : ( empty($v2['regular_price']) ? '0' : $v2['regular_price'] ); $id = $valsModel->insertValueId($keyId, $keys, round($v, 2)); if ($id) { $insert .= $queryValue . $id . '),'; } } } return $insert; } }