protected function validateRelatedProduct()
    {
        $field = 'related';

        if ($this->isExcluded($field) || $this->isError('store_id')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->setSubmitted($field, array());
            return null;
        }

        $store_id = $this->getSubmitted('store_id');

        $product_ids = array();

        foreach (array_unique($value) as $product_id) {

            $product = $this->product->get($product_id);

            if (empty($product['store_id'])) {
                $this->setError($field, $this->translation->text('Some of related products are invalid'));
                return false;
            }

            if ($product['store_id'] != $store_id) {
                $this->setError($field, $this->translation->text('All related product must belong to the same store'));
                return false;
            }

            $product_ids[$product['product_id']] = $product['product_id'];
        }

        $updating = $this->getUpdating();

        if (isset($updating['product_id'])) {
            // Exclude the current product from the related products
            unset($product_ids[$updating['product_id']]);
        }

        $this->setSubmitted('related', $product_ids);
        return true;
    }
protected function validateRelatedProduct()
    {
        $field = 'related';

        if ($this->isExcluded($field) || $this->isError('store_id')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->setSubmitted($field, array());
            return null;
        }

        $store_id = $this->getSubmitted('store_id');

        $product_ids = array();

        foreach (array_unique($value) as $product_id) {

            $product = $this->product->get($product_id);

            if (empty($product['store_id'])) {
                $this->setError($field, $this->translation->text('Some of related products are invalid'));
                return false;
            }

            if ($product['store_id'] != $store_id) {
                $this->setError($field, $this->translation->text('All related product must belong to the same store'));
                return false;
            }

            $product_ids[$product['product_id']] = $product['product_id'];
        }

        $updating = $this->getUpdating();

        if (isset($updating['product_id'])) {
            // Exclude the current product from the related products
            unset($product_ids[$updating['product_id']]);
        }

        $this->setSubmitted('related', $product_ids);
        return true;
    }
protected function validateRelatedProduct ( ) { $ field = 'related' ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( 'store_id' ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setSubmitted ( $ field , array ( ) ) ; return null ; } $ store_id = $ this -> getSubmitted ( 'store_id' ) ; $ product_ids = array ( ) ; foreach ( array_unique ( $ value ) as $ product_id ) { $ product = $ this -> product -> get ( $ product_id ) ; if ( empty ( $ product [ 'store_id' ] ) ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'Some of related products are invalid' ) ) ; return false ; } if ( $ product [ 'store_id' ] != $ store_id ) { $ this -> setError ( $ field , $ this -> translation -> text ( 'All related product must belong to the same store' ) ) ; return false ; } $ product_ids [ $ product [ 'product_id' ] ] = $ product [ 'product_id' ] ; } $ updating = $ this -> getUpdating ( ) ; if ( isset ( $ updating [ 'product_id' ] ) ) { // Exclude the current product from the related products unset ( $ product_ids [ $ updating [ 'product_id' ] ] ) ; } $ this -> setSubmitted ( 'related' , $ product_ids ) ; return true ; }
Validates related products
@return boolean|null
Validates related products