Find sorted attribute values

@param Product $product

@return ArrayCollection
976203
public function findAttributeValues($product)
    {
        // select
        $qb = $this->getQueryBuilder()
            ->select('a.name attributeName, av.name, i.path imagePath');

        // join
        $qb->join('p.attributeValues', 'av')
            ->join('av.attribute', 'a')
            ->leftJoin('av.image', 'i');

        // where
        $qb->andWhere('p = :product')
            ->setParameter('product', $product);

        // order by
        $qb->orderBy('a.order', 'asc');

        return $qb->getQuery()
            ->getResult();
    }
176530
public function getData(ProductInterface $product)
    {
        $productItemData = [
            'id'          => $product->getId(),
            'sku'         => $product->getSku(),
            'name'        => $product->getName(),
            'price'       => $this->getProductPrice($product),
            'image'       => $this->getImageUrl($product),
            'score'       => $product->getDocumentScore(),
            'is_in_stock' => $this->isInStockProduct($product),
        ];

        return $productItemData;
    }
837863
final public function sort(array $attributes = array())
    {
        $product        = $this->find($attributes['movingId']);
        $positionEntity = $this->find($attributes['movedId']);

        if ($product instanceof Product) {
            if ($this->fireEvent('sorting', array($product)) === false) {
                return false;
            }

            $product->setCaller($this);
            $product->{$attributes['type']}($positionEntity);

            $this->fireEvent('sorted', array($product));

            return $product;
        }

        throw new Exception(sprintf(Exception::CANT_UPDATE_MODEL,
            'Subbly\\Model\\Product',
            $this->name()
        ));
    }
755940
public function getFields($product_class_id)
    {
        $result = &gplcart_static("product.class.fields.$product_class_id");

        if (isset($result)) {
            return $result;
        }

        $result = array();
        $fields = $this->field->getList();

        $ops = array(
            'product_class_id' => $product_class_id
        );

        foreach ((array) $this->product_class_field->getList($ops) as $product_class_field) {
            if (isset($fields[$product_class_field['field_id']])) {

                $data = array('values' => $this->field_value->getList(array(
                    'field_id' => $product_class_field['field_id'])));

                $data += $fields[$product_class_field['field_id']];
                $data += $product_class_field;

                $result[$fields[$product_class_field['field_id']]['type']][$product_class_field['field_id']] = $data;
            }
        }

        return $result;
    }
693151
public function getProductCode(ProductInterface $product)
    {
        foreach ($this->products as $code => $productDescription) {
            $className = $productDescription->getManager()->getClass();
            if ($product instanceof $className) {
                return $code;
            }
        }
    }
732786
public function showAction(Product $product)
    {

        if (!$product) {
            throw $this->createNotFoundException('Unable to find Product entity.');
        }

        $deleteForm = $this->createDeleteForm($product->getId());

        return array(
            'entity' => $product,
            'delete_form' => $deleteForm->createView(),
        );
    }
720768
public function prepareCollection(ProductCollection $collection)
    {
        $collection->addAttributeToSelect($this->attributes);
        $collection->addPriceData();

        return $collection;
    }
753984
private function getMinPrices($product)
    {
        if ($product->getTypeId() == 'configurable') {
            foreach ($product->getTypeInstance()->getUsedProducts($product) as $childProduct) {
                $childPrices[] = $childProduct->getPrice();
                if ($childProduct->getSpecialPrice() !== null) {
                    $childSpecialPrices[] = $childProduct->getSpecialPrice();
                }
            }
            $this->price = isset($childPrices) ? min($childPrices) : null;
            $this->specialPrice = isset($childSpecialPrices) ? min($childSpecialPrices) : null;
        } elseif ($product->getTypeId() == 'bundle') {
            $this->price = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
            $this->specialPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
            //if special price equals to price then its wrong.)
            $this->specialPrice = ($this->specialPrice === $this->price) ? null : $this->specialPrice;
        } elseif ($product->getTypeId() == 'grouped') {
            foreach ($product->getTypeInstance()->getAssociatedProducts($product) as $childProduct) {
                $childPrices[] = $childProduct->getPrice();
                if ($childProduct->getSpecialPrice() !== null) {
                    $childSpecialPrices[] = $childProduct->getSpecialPrice();
                }
            }
            $this->price = isset($childPrices) ? min($childPrices) : null;
            $this->specialPrice = isset($childSpecialPrices) ? min($childSpecialPrices) : null;
        } else {
            $this->price = $product->getPrice();
            $this->specialPrice = $product->getSpecialPrice();
        }
        $this->formatPriceValues();
    }
1047887
public function showGalleryItemAction(Product $product)
    {
        $entity = $product->getMediaGallery();

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Gallery entity.');
        }

        $deleteForm = $this->createDeleteForm($product->getId());

        return array(
            'entity' => $entity,
            'product' => $product,
            'delete_form' => $deleteForm->createView(),
        );
    }
103461
private function getDefaultCartItemAttributes(Buyable $product, $qty)
    {
        return [
            'product_type' => $product->morphTypeName(),
            'product_id'   => $product->getId(),
            'quantity'     => $qty,
            'price'        => $product->getPrice()
        ];
    }
646465
final public function sort(array $attributes = array())
    {
        $productImage   = $this->find($attributes['movingId']);
        $positionEntity = $this->find($attributes['movedId']);

        if ($productImage instanceof ProductImage) {
            if ($this->fireEvent('sorting', array($productImage)) === false) {
                return false;
            }

            $productImage->setCaller($this);
            $productImage->{$attributes['type']}($positionEntity);

            $this->fireEvent('sorted', array($productImage));

            return $productImage;
        }

        throw new Exception(sprintf(Exception::CANT_UPDATE_MODEL,
            'Subbly\\Model\\Product',
            $this->name()
        ));
    }
111589
protected function completeWithRandomProducts(Collection $products) : Collection
	{
		$currentLimit = $this->limit - $products->count();

		return Product::whereNotIn('id', $this->excluding->all())
			->orderBy('rate_val', 'desc')
			->take($currentLimit)
			->get();
	}
1140849
public function findProductPrice(PriceProduct $product)
    {
        $priceConfigurationFilter = new PriceConfigurationFilter();
        $priceConfigurationFilter->addProduct($product);

        $result = $this->findPrice($priceConfigurationFilter);
        if (isset($result[0])) {
            return $result[0];
        }

        return null;
    }
479609
public function getSelectedRelatedProducts()
    {
        $products = [];
        foreach ($this->getPost()->getRelatedProducts() as $product) {
            $products[$product->getId()] = ['position' => 0];
        }

        return $products;
    }
25915
protected function attachFields(array &$product)
    {
        if (empty($product)) {
            return $product;
        }

        $product['field'] = $this->product_field->getList($product['product_id']);

        if (empty($product['field']['option'])) {
            return $product;
        }

        foreach ($product['field']['option'] as &$field_values) {
            $field_values = array_unique($field_values);
        }

        return $product;
    }
431692
function (productTypes, department) {

            function sizeMapToArray(sizeMap, departmentName) {
                var ret = [];
                for (var sizeName in sizeMap) {
                    if (sizeMap.hasOwnProperty(sizeName)) {
                        ret.push({
                            name: sizeName,
                            sizeWeight: sizeMap[sizeName].sizeWeight,
                            departmentName: departmentName,
                            productTypes: sizeMap[sizeName].productTypes
                        });
                    }
                }

                ret.sort(function(a, b) {
                    return (a.sizeWeight || 0) - (b.sizeWeight || 0)
                });

                return ret;
            }

            var departmentSizeMap = productTypeDepartmentToSizeMap;

            if (productTypes) {
                var departmentHash,
                    key, departments;

                departmentSizeMap = {};
                productTypes.each(function (productType) {
                    if (department) {
                        departments = [department];
                    } else {
                        departments = productTypeToDepartmentsMap[productType.$.id];
                    }
                    if (departments) {
                        for (var i = 0; i < departments.length; i++) {
                            key = departments[i].$.name;
                            departmentHash = departmentSizeMap[key] = departmentSizeMap[key] || {};
                            if (productType.$.sizes) {
                                productType.$.sizes.each(function (size) {
                                    if (!departmentHash[size.$.name]) {
                                        departmentHash[size.$.name] = {
                                            productTypes: [],
                                            sizeWeight: size.$.weight
                                        };
                                    }
                                    departmentHash[size.$.name].productTypes.push(productType);
                                });
                            }
                        }
                    }
                });
            }
            var groups = [],
                group;
            for (var departmentName in departmentSizeMap) {
                if (departmentSizeMap.hasOwnProperty(departmentName)) {
                    group = {
                        name: departmentName,
                        items: sizeMapToArray(departmentSizeMap[departmentName], departmentName)
                    };
                    groups.push(group);
                }
            }

            return groups;

        }
1140434
public function getLineItemForProduct(Product $product)
    {
        foreach ($this->getLineItems() as $lineItem)
        {
            if ($lineItem->getProduct()->getId() == $product->getId())
            {
                return $lineItem;
            }
        }

        return $this->createLineItemForProduct($product);
    }