예제 #1
0
파일: Create_1.php 프로젝트: Eximagen/3m
function save_product_combination($ProductId,$itemNumber,$list, $decoration,$color_name){
	global $webService,$webservice_exi,$result_xml, $count;
        $product_xml = $result_xml->ProductListResult->ProductListResult;
        $parameter = array("ItemNumber"=>$itemNumber,
			"key"=>"8770471727");
        $i=0;
        $inventory_details = $webservice_exi->GetInventory($parameter);
        if(isset($inventory_details->GetInventoryResult->InventoryData->SKU))
            $inventory_details = $inventory_details->GetInventoryResult;
        else
            $inventory_details = $inventory_details->GetInventoryResult->InventoryData;
        foreach ($inventory_details as $inventory){
            attachImages($inventory->SKU, $ProductId);
            if(isset($decoration->areasimp->ItemNumber))
                $decorationData = $decoration;
            else 
                $decorationData = $decoration->areasimp;
            foreach ($decorationData as $method){
                $xml = $webService -> get(array('url' => PS_SHOP_PATH . '/api/combinations?schema=synopsis'));
                $resources = $xml -> children() -> children();
                $resources->id_product  = $ProductId;
                $resources->quantity = $inventory->Available;
                if($i==0){
                    $resources->default_on = true;
                    $i++;
                }
                $resources->minimal_quantity = 1;
                $resources->reference = $inventory->SKU;
                $color_id = AttributeCore::getColorAttributeIdByValue($inventory->HexValue);
                $decoration_id = AttributeCore::getDecorationAttributeIdByValue($method->TecnicaFull);
                if(!$color_id){
                    $xml1 = $webService -> get(array('url' => PS_SHOP_PATH . '/api/product_option_values?schema=synopsis'));
                    $resources1 = $xml1 -> children() -> children();
                    $resources1->id_attribute_group  = 3;
                    $resources1->color  = "#".$inventory->HexValue;
                    $resources1->name->language  = $product_xml[$count-1]->Color;
                     try {
                        $opt1 = array('resource' => 'product_option_values');
                        $opt1['postXml'] = $xml1->asXML();
                        $xml1 = $webService->add($opt1);
                        $result1 = $xml1->children()->children();
                        $color_id = $result1->{'id'};
                    }catch (PrestaShopWebserviceException $ex) {
                            echo "<b>Error al setear la cantidad  ->Error : </b>".$ex->getMessage().'<br>';
                    }
                }
                
                if(!$decoration_id){
                    $xml1 = $webService -> get(array('url' => PS_SHOP_PATH . '/api/product_option_values?schema=synopsis'));
                    $resources1 = $xml1 -> children() -> children();
                    $resources1->id_attribute_group  = 4;
                    $resources1->name->language  = $method->TecnicaFull;
                     try {
                        $opt1 = array('resource' => 'product_option_values');
                        $opt1['postXml'] = $xml1->asXML();
                        $xml1 = $webService->add($opt1);
                        $result1 = $xml1->children()->children();
                        $decoration_id = $result1->{'id'};
                    }catch (PrestaShopWebserviceException $ex) {
                            echo "<b>Error al setear la cantidad  ->Error : </b>".$ex->getMessage().'<br>';
                    }
                }
                
                $resources->associations->product_option_values->product_option_values->id=$color_id;
                $resources->associations->product_option_values->addChild('product_option_values')->addChild('id',$decoration_id);
               try {
                        $opt = array('resource' => 'combinations');
                        $opt['postXml'] = $xml->asXML();
                        $xml = $webService->add($opt);
                         getIdStockAvailableAndSet($ProductId, $inventory->Available,
                   $inventory->OnTransit,$inventory->Date,$color_id);
                         $count++;
                }catch (PrestaShopWebserviceException $ex) {
                        echo "<b>Error al setear la cantidad  ->Error : </b>".$ex->getMessage().'<br>';
                }
            }
            $intransit_date = $inventory->Date;
            if($intransit_date=='N/A')
                $intransit_date = date("Y-m-d");
                StockAvailableCore::setStockInventory($ProductId, 1, 0,$inventory->Available,$color_id,
                   $inventory->OnTransit,$intransit_date);
        }
}