Put default selected image on the first position
@param array $selected
@param array $product
@todo Replace with a trait
514155
protected function unshiftSelectedImageProduct($selected, &$product)
    {
        if (isset($selected['combination']['file_id']) && isset($product['images'][$selected['combination']['file_id']])) {
            $image = $product['images'][$selected['combination']['file_id']];
            unset($product['images'][$selected['combination']['file_id']]);
            $product['images'] = array($image['file_id'] => $image) + $product['images'];
        }
    }
656441
public function setDefaultOrderCartContent() {
    $this->orderCartContent = array();
    $product = new CartProduct();
    $product->setCartProductId(0)->setCartProductName("NA");
    $product->setCartProductUnitPrice(0)->setCartProductQuantity(1);
    $product->setCartProductBrand("NA")->setCartProductMPN("NA");
    $product->setCartProductCategoryName("NA")->setCartProductCategoryID(0);

    $this->orderCartContent[] = $product;
  }
1329459
protected function createPicturesFor($product, $attr)
    {
        $pictures = Images::parse($attr->get('pictures'))
            ->on($this->basePath. '/' . $product->id)
            ->store();

        $product->pictures()->createMany($pictures);
    }
13821
protected function prepareSelect(Select $select) {
		$select->reset(Select::COLUMNS)
		       ->reset(Select::LIMIT_OFFSET)
		       ->reset(Select::LIMIT_COUNT)
		       ->reset(Select::ORDER)
		       ->columns([self::COUNT_COLUMN => 'count(*)']);

		return $select;
	}
954827
protected function setIds(array $product)
    {
        $this->setLastEntityId(isset($product[MemberNames::ENTITY_ID]) ? $product[MemberNames::ENTITY_ID] : null);
    }
1057519
public function addProduct($product = array())
    {
        if (!is_array($product)) {
            $this->errorMessage[] = 'PRODUCT: Not a valid product!';
        }
        foreach ($this->productFields as $field) {
            if (array_key_exists($field, $product)) {
                $add[$field] = $this->cleanString($product[$field]);
            } elseif (!array_key_exists($field, $product)) {
                $add[$field] = ' ';
                $this->debugMessage[] = 'Missing product field: ' . $field;
            }
        }
        $this->products[] = $add;
    }
829699
protected function createSelectElement($options, $selected, $_attributes, &$return)
    {
        $return = '<select'.$this->attributes($_attributes).'>';

        if( is_array($options) ) foreach( $options as $key => $value )
        {
            if( is_array($selected) )
            {
                if( in_array($key, $selected) )
                {
                    $select = ' selected="selected"';
                }
                else
                {
                    $select = "";
                }
            }
            else
            {
                if( $selected == $key )
                {
                    $select = ' selected="selected"';
                }
                else
                {
                    $select = "";
                }
            }

            $return .= '<option value="'.$key.'"'.$select.'>'.$value.'</option>'.EOL;
        }

        $return .= '</select>'.EOL;
    }
1372442
public function selectMainImage(Image $image)
    {
        if (!$this->images->findImageByUUID($image->getMediaObjectId())) {
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
        }

        $oldMainImage = $this->images->getMain();

        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
            $this->apply(
                $this->createMainImageSelectedEvent($image)
            );
        }
    }
605216
protected function _order(Kwf_Db_Table_Select $select, $order)
    {
        if (!is_array($order)) {
            $order = array($order);
        }

        foreach ($order as $val) {
            $select->order($val);
        }

        return $select;
    }
912209
protected function setIds(array $product)
    {

        // pass the product to the parent method
        parent::setIds($product);

        // temporarily persist the row ID
        $this->setLastRowId($product[MemberNames::ROW_ID]);
    }
727882
public function editProduct($product_id = null)
    {
        $this->setProduct($product_id);
        $this->setTitleEditProduct();
        $this->setBreadcrumbEditProduct();

        $this->setData('product', $this->data_product);
        $this->setData('size_units', $this->convertor->getUnitNames('size'));
        $this->setData('weight_units', $this->convertor->getUnitNames('weight'));
        $this->setData('default_currency', $this->currency->getDefault());
        $this->setData('subtract_default', $this->config->get('product_subtract', 0));
        $this->setData('classes', $this->product_class->getList(array('status' => 1)));
        $this->setData('languages', $this->language->getList(array('enabled' => true)));

        $this->submitEditProduct();

        $this->setDataFieldsEditProduct();
        $this->setDataAuthorEditProduct();
        $this->setDataRelatedEditProduct();
        $this->setDataCategoriesEditProduct();
        $this->setDataImagesEditProduct();

        $this->setJsEditProduct();
        $this->outputEditProduct();
    }
962863
protected function indexProduct(array $product)
    {
        $snippet = $this->search->getSnippet($product, 'und');
        return $this->search->setIndex($snippet, 'product', $product['product_id'], 'und');
    }
204364
protected function getSelectedCombinationProduct(array $product)
    {
        $field_value_ids = array();

        if (!empty($product['default_field_values'])) {
            $field_value_ids = $product['default_field_values'];
        }

        $selected = $this->sku->selectCombination($product, $field_value_ids);
        $selected += $product;
        return $selected;
    }
916063
protected function prepare(array $product)
    {
        $data = array();
        foreach ($this->job['data']['header'] as $key => $value) {
            $data[$key] = isset($product[$key]) ? $product[$key] : '';
        }

        $this->prepareImages($data, $product);
        $this->preparePrice($data, $product);
        $this->prepareImages($data, $product);

        return $data;
    }
989701
public static function generateSelectOptionsFromArray( $data, $selected = null ) {

		$options	= "";

		if( isset( $data ) ) {

			if( isset($selected) ) {

				foreach ( $data as $key => $value ) {

					if( $selected === $key ) {

						$options .= "<option value='$key' selected>$value</option>";
					}
					else {
						$options .= "<option value='$key'>$value</option>";
					}
				}
			}
			else {

				foreach ( $data as $key => $value ) {

					$options .= "<option value='$key'>$value</option>";
				}
			}
		}

		return $options;
	}
1228820
private void setSelectPosition(int posX, int posY, int height, int width) {

        setSelectPositionX(posX, width);
        setSelectPositionY(posY, height);
    }
700158
public function update($productId, ProductImage &$productImage)
    {
        $data = $productImage->exportData();
        $endpoint = '/admin/products/'.$productId.'/images/'.$productImage->id.'.json';
        $response = $this->request(
            $endpoint, 'PUT', array(
            'image' => $data
            )
        );
        $productImage->setData($response['image']);
    }