<?php

class ModelEntegrasyonAttribute extends Model
{

    public function check_required($selected_attributes,$product_info,$code)
    {

        $this->load->model('entegrasyon/category');
        $required=array();

        $variant_attributes=array();

        if($product_info['varianter']){
            $variant_attributes= $this->model_entegrasyon_category->getAttributes($product_info['category_id'],$code,false,true)['result'];
            }


       $attributes= $this->model_entegrasyon_category->getAttributes($product_info['category_id'],$code,true);
        foreach ($attributes['result'] as $attribute) {

          if($this->findInAttributes($attribute['market_attribute_id'],$selected_attributes)==false && !in_array($attribute,$variant_attributes)){
              $required[]=$attribute;
          }

       }

        return $required;


    }

    public function attributes_without_variants($selected_attributes,$product_info,$code)
    {
$variant_attributes= $this->model_entegrasyon_category->getAttributes($product_info['category_id'],$code,false,true)['result'];



        foreach ($selected_attributes as $key => $selected_attribute) {

            if($this->findInAttributes($selected_attribute['market_attribute_id'], $variant_attributes)==true ){
               unset( $selected_attributes[$key]);
            }


}
        return $selected_attributes;


    }

    private function findInAttributes($market_attribute_id,$attributes)
    {


        foreach ($attributes as $attribute) {

            if($attribute['market_attribute_id']==$market_attribute_id) return true;

        }

        return false;

    }



}
