Gökmen Korkmaz

Opencart N11 API İşlemleri Bölüm 2: Ürün Servisleri

Opencart N11 API Entegrasyon Bölüm 2: Ürün Servisleri

Merhaba, bu devam yazımda Opencart N11 API entegrasyon işlemerimize kaldığımız yerden devam ediyoruz. Okumadıysanız ilk yazıya buradan ulaşabilirsiniz: Opencart N11 API İşlemleri

Hatırlayacağınız üzere önceki yazıda admin tarafını tamamlamış API Anahtarı ve API Key’i N11’den edinerek sistemimizin ayarlarına kaydetmiştik. Şimdi ise API entegrasyonuna başlayabiliriz.

Kullandığımız dosyalar,

  1. /admin/language/tr-tr/extension/module/n11.php
  2. /admin/controller/extension/module/n11.php
  3. /admin/view/template/extension/module/n11.tpl
  4. Bir de artık bu dosyaların yanında yeni olarak bir model dosyası oluşturacağız. Bu dosyayı da /admin/model/extension/n11/n11.php olarak oluşturdum.

Şimdi dosyalarımız şu hali aldı;

  1. /admin/language/tr-tr/extension/module/n11.php
  2. /admin/controller/extension/module/n11.php
  3. /admin/view/template/extension/module/n11.tpl
  4. /admin/model/extension/n11/n11.php

Şimdi ürün servisleri için N11 tarafında request edeceğimiz adres bilgisine ihtiyacımız var. Bu adresi dökümantasyondan da bulabilirsiniz, ben şimdilik belirteyim;

https://api.n11.com/ws/ProductService.wsdl

Artık controller dosyamızda geçerek aşağıda fonksiyonu ekleyelim.

protected function getN11ProductList($cp,$ps){
		$this->load->model('setting/setting');
		$n11_api_key = $this->model_setting_setting->getSettingValue('n11_api_key', $this->request->get['store_id']);
		$n11_api_pass = $this->model_setting_setting->getSettingValue('n11_api_pass', $this->request->get['store_id']);
		if($n11_api_key != '' && $n11_api_pass != ''){
			$client = new SoapClient('https://api.n11.com/ws/ProductService.wsdl');
			$parameters['auth'] = array('appKey' => $n11_api_key, 'appSecret' => $n11_api_pass);
			$parameters['pagingData'] = array('currentPage' => $cp, 'pageSize' => $ps);
			if($return = $client->GetProductList($parameters)){
				return $return->products->product;
			} else {
				return NULL;
			}
		}
	}

Bu fonksiyonu index fonksiyonumuzdan şu şekilde çağırabiliriz;

$data['products'] = $this->getN11ProductList(0,20);

Buradaki 0,20 bölümü 0. sayfa 20 kayıt için kullanılıyor. Sayfalama yaparken kullanabilirsiniz. Örnek olarak oluşturduğum view dosyama da aşağıdaki kodları ekledim.

	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
		</div>
		<div class="panel-body">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#tab-products" data-toggle="tab"><?php echo $text_products; ?></a></li>
			</ul>
			<div class="tab-content">
				<div id="tab-products" class="tab-pane active">
					<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form-product">
					  <div class="table-responsive">
						<table class="table table-bordered table-hover">
						  <thead>
							<tr>
							  <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
							</tr>
						  </thead>
						  <tbody>
							<?php if ($products) { ?>
							<?php foreach ($products as $product) { ?>
							<tr>
							  <td class="text-center"><?php if (in_array($product->id, $selected)) { ?>
								<input type="checkbox" name="selected[]" value="<?php echo $product->id; ?>" checked="checked" />
								<?php } else { ?>
								<input type="checkbox" name="selected[]" value="<?php echo $product->id; ?>" />
								<?php } ?></td>
							  <td class="text-left"><?php echo $product->id; ?></td>
							  <td class="text-left"><?php echo $product->productSellerCode; ?></td>
							  <td class="text-left"><?php echo $product->title; ?></td>
							  <td class="text-left"><?php echo $product->subtitle; ?></td>
							  <td class="text-left"><?php echo $product->price; ?></td>
							  <td class="text-left"><?php echo $product->displayPrice; ?></td>
							  <td class="text-left"><?php echo $product->saleStatus; ?></td>
							  <td class="text-left"><?php echo $product->approvalStatus; ?></td>
							  <td class="text-right"><a href="#" data-toggle="tooltip" title="<?php echo $button_edit; ?>" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
							</tr>
								<?php foreach ($product->stockItems->stockItem as $stockItem) { ?>
								<tr>
									<td colspan="9" class="text-left">
										<table class="table table-bordered table-hover" style="margin:3px;">
											<tr>
												<td class="text-left"> </td>
												<td class="text-left"><?php echo $stockItem->id; ?></td>
												<td class="text-left"><?php echo $stockItem->sellerStockCode; ?></td>
												<td class="text-left"><?php echo $stockItem->optionPrice; ?></td>
												<td class="text-left"><?php echo $stockItem->currencyAmount; ?></td>
												<td class="text-left"><?php echo $stockItem->displayPrice; ?></td>
												<td class="text-left"><?php echo $stockItem->gtin; ?></td>
												<td class="text-left"><?php echo $stockItem->quantity; ?></td>
												<td class="text-left"><?php echo $stockItem->attributes->attribute->id; ?></td>
												<td class="text-left"><?php echo $stockItem->attributes->attribute->name; ?></td>
												<td class="text-left"><?php echo $stockItem->attributes->attribute->value; ?></td>
											</tr>
										</table>
									</td>
									
								</tr>
								<?php } ?>
							<?php } ?>
							<?php } else { ?>
							<tr>
							  <td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
							</tr>
							<?php } ?>
						  </tbody>
						</table>
					  </div>
					</form>
				</div>
			</div>
		</div>
	</div>
N11 API İşlemleri Ürün Listeleme

Gördüğünüz üzere ben bu şekilde admin panelimde N11’de yayınlanan ürünlerimi listelettim. Ayrıca bir düzenleme butonu da koydum. Yaptığım değişikleri API aracılığı ile N11’e post edebiliyorum. Bir sonraki yazıma kadar da silme ve ürün onayını kaldırma butonlarını da ekleyeceğim. Anlaşılacağı üzere bu yazının bir sonraki bölümünde;

Opencart N11 API ile ürünü düzenleme, ürünü silme ve/veya yayından alma, ürün arama gibi işlemlerinden bahsedeceğim.

Not: Bir sonraki yazıyı 09.02.2019 Cumartesi günü yazmayı planlıyorum.

Exit mobile version