当前位置: 首页>>代码示例>>PHP>>正文


PHP wpshop_tools::wpshop_clean方法代码示例

本文整理汇总了PHP中wpshop_tools::wpshop_clean方法的典型用法代码示例。如果您正苦于以下问题:PHP wpshop_tools::wpshop_clean方法的具体用法?PHP wpshop_tools::wpshop_clean怎么用?PHP wpshop_tools::wpshop_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wpshop_tools的用法示例。


在下文中一共展示了wpshop_tools::wpshop_clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: reduce_product_stock_qty

    /**
     * Update quantity for a product
     * @param integer $product_id The product we want to update quantity for
     * @param decimal $qty The new quantity
     */
    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
    {
        global $wpdb;
        $product = self::get_product_data($product_id);
        /** Check if there is variation ***/
        if (!empty($variation_id) && $variation_id != $product_id) {
            $variation_post_type = get_post_type($variation_id);
            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                /** Check if variation def is combined **/
                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
                    /** Get post meta of variation */
                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
                        $product = self::get_product_data($variation_id);
                        $product_id = $variation_id;
                    }
                }
            }
        }
        if (!empty($product)) {
            $newQty = $product['product_stock'] - $qty;
            $value_id = 0;
            if ($newQty >= 0) {
                $query = '
					SELECT wp_wpshop__attribute_value_decimal.value_id
					FROM wp_wpshop__attribute_value_decimal
					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
					LIMIT 1
				';
                $value_id = $wpdb->get_var($query);
                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
            }
            // Historic
            $attribute_histo_content = array();
            $attribute_histo_content['status'] = 'valid';
            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
            $attribute_histo_content['creation_date_value'] = !empty($attribute_histo[0]->creation_date_value) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
            $attribute_histo_content['original_value_id'] = $value_id;
            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
            $attribute_histo_content['entity_id'] = $product_id;
            $attribute_histo_content['value'] = $product['product_stock'];
            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
            $product_meta['product_stock'] = $newQty;
            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
        }
    }
开发者ID:fedeB-IT-dept,项目名称:fedeB_website,代码行数:57,代码来源:products.class.php


注:本文中的wpshop_tools::wpshop_clean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。