Ejemplo n.º 1
0
    public function column_default($item, $column_name)
    {
        global $product;
        if (!$product || $product->id !== $item->id) {
            $product = new fflcommerce_product($item->id);
        }
        switch ($column_name) {
            case 'product':
                if ($sku = $product->get_sku()) {
                    echo $sku . ' - ';
                }
                echo $product->get_title();
                // Get variation data
                if ($product->is_type('variation')) {
                    $list_attributes = array();
                    $attributes = $product->get_available_attributes_variations();
                    foreach ($attributes as $name => $attribute) {
                        $list_attributes[] = $product->attribute_label(str_replace('pa_', '', $name)) . ': <strong>' . $attribute . '</strong>';
                    }
                    echo '<div class="description">' . implode(', ', $list_attributes) . '</div>';
                }
                break;
            case 'parent':
                if ($item->parent) {
                    echo get_the_title($item->parent);
                } else {
                    echo '-';
                }
                break;
            case 'stock_status':
                if ($product->is_in_stock() || !isset($product->meta['stock_manage']) && !isset($product->meta['stock_status']) && $product->get_stock() > 0) {
                    echo '<mark class="instock">' . __('In stock', 'fflcommerce') . '</mark>';
                } else {
                    echo '<mark class="outofstock">' . __('Out of stock', 'fflcommerce') . '</mark>';
                }
                break;
            case 'stock_level':
                echo $product->get_stock();
                break;
            case 'actions':
                ?>
<p>
				<?php 
                $actions = array();
                $action_id = $item->parent != 0 ? $item->parent : $item->id;
                $actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'fflcommerce'), 'action' => "edit");
                if ($product->is_visible()) {
                    $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'fflcommerce'), 'action' => "view");
                }
                $actions = apply_filters('fflcommerce_admin_stock_report_product_actions', $actions, $product);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'fflcommerce') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                ?>
				</p><?php 
                break;
        }
    }
Ejemplo n.º 2
0
    public function display()
    {
        global $post;
        // Get the attributes
        $attributes = (array) maybe_unserialize(get_post_meta($post->ID, 'product_attributes', true));
        // Get all variations of the product
        $variations = get_posts(array('post_type' => 'product_variation', 'post_status' => array('draft', 'publish'), 'numberposts' => -1, 'orderby' => 'id', 'order' => 'asc', 'post_parent' => $post->ID));
        ?>
		<div id='variable_product_options' class='panel'>
			<?php 
        if ($this->has_variable_attributes($attributes)) {
            ?>
				<div class="toolbar">
					<select name="variation_actions">
						<option value="default"><?php 
            _e('Bulk Actions', 'fflcommerce');
            ?>
</option>
						<option value="remove_all"><?php 
            _e('Remove All Variations', 'fflcommerce');
            ?>
</option>
						<optgroup label="<?php 
            _e('Set All', 'fflcommerce');
            ?>
:">
							<option value="set_all_regular_prices"><?php 
            _e('Regular Prices', 'fflcommerce');
            ?>
</option>
							<option value="set_all_sale_prices"><?php 
            _e('Sale Prices', 'fflcommerce');
            ?>
</option>
							<option value="set_all_stock"><?php 
            _e('Stock', 'fflcommerce');
            ?>
</option>
							<option value="set_all_weight"><?php 
            _e('Weight', 'fflcommerce');
            ?>
</option>
							<option value="set_all_width"><?php 
            _e('Width', 'fflcommerce');
            ?>
</option>
							<option value="set_all_length"><?php 
            _e('Length', 'fflcommerce');
            ?>
</option>
							<option value="set_all_height"><?php 
            _e('Height', 'fflcommerce');
            ?>
</option>
						</optgroup>
					</select>
					<input id="do_actions" type="submit" class="button-secondary" value="<?php 
            _e('Apply', 'fflcommerce');
            ?>
">
					<button type='button' class='button button-seconday add_variation'><?php 
            _e('Add Variation', 'fflcommerce');
            ?>
</button>
				</div>
			<?php 
        }
        ?>
			<div class='fflcommerce_variations'>
				<?php 
        if ($this->has_variable_attributes($attributes)) {
            ?>
					<?php 
            if ($variations) {
                foreach ($variations as $variation) {
                    echo $this->generate_panel($attributes, $variation);
                }
            }
            ?>
				<?php 
        }
        ?>
			</div>
			<div class="toolbar">
				<strong><?php 
        _e('Default selections:', 'fflcommerce');
        ?>
</strong>
				<?php 
        $default_attributes = (array) maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true));
        foreach ($attributes as $attr) {
            // If not variable attribute then skip
            if (!isset($attr['variation'])) {
                continue;
            }
            // Get current value for variation (if set)
            $selected = isset($default_attributes[sanitize_title($attr['name'])]) ? $default_attributes[sanitize_title($attr['name'])] : '';
            // Open the select & set a default value
            echo '<select name="default_attribute_' . sanitize_title($attr['name']) . '" >';
            $product = new fflcommerce_product($post->ID);
            echo '<option value="">' . __('No default', 'fflcommerce') . ' ' . $product->attribute_label('pa_' . $attr['name']) . '&hellip;</option>';
            // Get terms for attribute taxonomy or value if its a custom attribute
            if ($attr['is_taxonomy']) {
                $options = wp_get_object_terms($post->ID, 'pa_' . sanitize_title($attr['name']), array('orderby' => 'slug'));
                if (!is_wp_error($options)) {
                    foreach ($options as $option) {
                        echo '<option value="' . esc_attr($option->slug) . '" ' . selected($selected, $option->slug, false) . '>' . $option->name . '</option>';
                    }
                }
            } else {
                $options = explode(',', $attr['value']);
                foreach ($options as $option) {
                    $option = trim($option);
                    echo '<option ' . selected($selected, $option, false) . ' value="' . esc_attr($option) . '">' . $option . '</option>';
                }
            }
            // Close the select
            echo '</select>';
        }
        ?>
			</div>
		</div>
	<?php 
    }
Ejemplo n.º 3
0
/** Show variation info if set
 *
 * @param fflcommerce_product $product
 * @param array $variation_data
 * @param bool $flat
 * @return string
 */
function fflcommerce_get_formatted_variation(fflcommerce_product $product, $variation_data = array(), $flat = false)
{
    $return = '';
    if (!is_array($variation_data)) {
        $variation_data = array();
    }
    if ($product instanceof fflcommerce_product_variation) {
        $variation_data = array_merge(array_filter($variation_data), array_filter($product->variation_data));
        if (!$flat) {
            $return = '<dl class="variation">';
        }
        $variation_list = array();
        $added = array();
        foreach ($variation_data as $name => $value) {
            if (empty($value)) {
                continue;
            }
            $name = str_replace('tax_', '', $name);
            if (in_array($name, $added)) {
                continue;
            }
            $added[] = $name;
            if (taxonomy_exists('pa_' . $name)) {
                $terms = get_terms('pa_' . $name, array('orderby' => 'slug', 'hide_empty' => '0'));
                foreach ($terms as $term) {
                    if ($term->slug == $value) {
                        $value = $term->name;
                    }
                }
                $name = get_taxonomy('pa_' . $name)->labels->name;
                $name = $product->attribute_label('pa_' . $name);
            }
            // TODO: if it is a custom text attribute, 'pa_' taxonomies are not created and we
            // have no way to get the 'label' as submitted on the Edit Product->Attributes tab.
            // (don't ask me why not, I don't know, but it seems that we should be creating taxonomies)
            // this function really requires the product passed to it for: $product->attribute_label( $name )
            if ($flat) {
                $variation_list[] = $name . ': ' . $value;
            } else {
                $variation_list[] = '<dt>' . $name . ':</dt><dd>' . $value . '</dd>';
            }
        }
        if ($flat) {
            $return .= implode(', ', $variation_list);
        } else {
            $return .= implode('', $variation_list);
        }
        if (!$flat) {
            $return .= '</dl>';
        }
    }
    return $return;
}