/**
  * Delete a product attribute
  *
  * @param int $idAttribute The attribute ID
  * @param int $idProduct The product ID
  *
  * @return array
  */
 public function ajaxProcessDeleteProductAttribute($idAttribute, $idProduct)
 {
     if (!\CombinationCore::isFeatureActive()) {
         return false;
     }
     if ($idProduct && \ValidateCore::isUnsignedId($idProduct) && \ValidateCore::isLoadedObject($product = new \ProductCore($idProduct))) {
         if (($depends_on_stock = \StockAvailableCore::dependsOnStock($idProduct)) && \StockAvailableCore::getQuantityAvailableByProduct($idProduct, $idAttribute)) {
             return array('status' => 'error', 'message' => 'It is not possible to delete a combination while it still has some quantities in the Advanced Stock Management. You must delete its stock first.');
         } else {
             $product->deleteAttributeCombination((int) $idAttribute);
             $product->checkDefaultAttributes();
             \ToolsCore::clearColorListCache((int) $product->id);
             if (!$product->hasAttributes()) {
                 $product->cache_default_attribute = 0;
                 $product->update();
             } else {
                 \ProductCore::updateDefaultAttribute($idProduct);
             }
             if ($depends_on_stock && !\StockCore::deleteStockByIds($idProduct, $idAttribute)) {
                 return array('status' => 'error', 'message' => 'Error while deleting the stock');
             } else {
                 return array('status' => 'ok', 'message' => 'Successful deletion');
             }
         }
     } else {
         return array('status' => 'error', 'message' => 'You cannot delete this attribute.');
     }
 }
Пример #2
0
function save_product_combination($ProductId,$itemNumber,$list, $decoration){
        global $webService,$webservice_exi,$result_xml, $count;
        StockAvailableCore::deleteStockInventoryBYProductID($ProductId);
        
        $opt = array('resource' => 'combinations');
        
        $parameter = array("ItemNumber"=>$itemNumber,
			"key"=>EXIMAGEN_KEY);
        $i=0;
        $inventory_details = $webservice_exi->GetInventory($parameter);
		$color_array = array();
		if(isset($inventory_details->GetInventoryResult->InventoryData->SKU))
            $inventory_details = $inventory_details->GetInventoryResult;
        else
            $inventory_details = $inventory_details->GetInventoryResult->InventoryData;
        foreach ($inventory_details as $inventory){
                $color_id = AttributeCore::getColorAttributeIdByValue($inventory->HexValue);
                         getIdStockAvailableAndSet($ProductId, $inventory->Available,
                   $inventory->OnTransit,$inventory->Date,$color_id);
                
            $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);
        }
}
Пример #3
0
 /**
  * Gets available stock for a given product / combination / shop.
  *
  * @param object $product
  * @param null $id_product_attribute
  * @param null $id_shop
  * @return StockAvailable
  */
 public function getStockAvailableByProduct($product, $id_product_attribute = null, $id_shop = null)
 {
     return new \StockAvailableCore(\StockAvailableCore::getStockAvailableIdByProductId($product->id, $id_product_attribute, $id_shop));
 }
Пример #4
0
function save_product_combination($ProductId,$itemNumber,$list, $decoration,$color_name){
	global $webService,$webservice_exi,$result_xml, $count;
        deleteImagesToProducts($ProductId);
        $comb_ids = CombinationCore::getIdsByProductId($ProductId);
        StockAvailableCore::deleteStockInventoryBYProductID($ProductId);
        
        $opt = array('resource' => 'combinations');
        foreach ($comb_ids as $comb){
             $opt['id'] = (int)$comb['id_product_attribute'];
             $xml = $webService->delete($opt);             
        }
        
        $product_xml = $result_xml->ProductListResult->ProductListResult;
        $parameter = array("ItemNumber"=>$itemNumber,
			"key"=>"8770471727");
        $i=0;
        $inventory_details = $webservice_exi->GetInventory($parameter);
		$color_array = array();
		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);
                $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);
                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[0]  = $product_xml[$count-1]->Color;
                    $resources1->name->language[1]  = $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(in_array($color_id,$color_array))
					continue;
				else
					array_push($color_array,$color_id);
				
                var_dump($color_id);
                $resources->associations->product_option_values->product_option_values->id=$color_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);
        }
}
Пример #5
0
 /**
  * Set if a product depends on stock (ASM). For a product or a combination.
  *
  * Does work only in Advanced stock management.
  *
  * @param \ProductCore $product
  * @param boolean $dependsOnStock
  * @param integer $forAttributeId
  */
 public function processDependsOnStock(\ProductCore $product, $dependsOnStock, $forAttributeId = 0)
 {
     \StockAvailableCore::setProductDependsOnStock((int) $product->id, $dependsOnStock, null, $forAttributeId);
 }