Ejemplo n.º 1
0
 public function download_products($data)
 {
     $products = $this->model_catalog_product->getProducts($data);
     $add_product = true;
     foreach ($products as $product) {
         if (!empty($data['modified_date'])) {
             if ($product['date_added'] > $data['modified_date'] or $product['date_modified'] > $data['modified_date']) {
                 $add_product = true;
             } else {
                 $add_product = false;
             }
         }
         if ($add_product) {
             $product_options = $this->model_catalog_product->getProductOptions($product['product_id']);
             if (is_array($product_options) && count($product_options) > 0) {
                 // Here we have all of the options for this product.
                 //We need to get just the ones with a sku.
                 foreach ($product_options as $option) {
                     foreach ($option['product_option_value'] as $option_value) {
                         if (!empty($option_value['sku'])) {
                             $p = new DKProduct(Guid());
                             $p->Id = Guid();
                             //$product['product_id'];
                             //$p->Sku             = ($product['sku'] == '') ? $product['model'] : $product['sku'];
                             $p->Sku = $option_value['sku'];
                             $name = str_replace('  ', ' ', html_entity_decode(trim($product['name']), ENT_QUOTES) . ' ' . html_entity_decode(trim($option_value['name']), ENT_QUOTES));
                             $p->Name = $name;
                             $p->Description = '<![CDATA[' . $product['name'] . ' ' . $option_value['name'] . ']]>';
                             $p->LongDescription = '<![CDATA[' . $product['description'] . ']]>';
                             $p->SupplierPartNo = $product['upc'];
                             //$p->TaxRate       = $product['tax'];
                             $p->TaxCode = $this->TaxClassToTaxCodeMap($product['tax_class_id']);
                             if ($option_value['price_prefix'] == '-') {
                                 $p->SalePrice = $product['price'] - $option_value['price'];
                             } else {
                                 if ($option_value['price_prefix'] == '+') {
                                     $p->SalePrice = $product['price'] + $option_value['price'];
                                 } else {
                                     $p->SalePrice = $option_value['price'];
                                 }
                             }
                             if ($option_value['weight_prefix'] == '-') {
                                 $p->UnitWeight = $product['weight'] - $option_value['weight'];
                             } else {
                                 $p->UnitWeight = $product['weight'] + $option_value['weight'];
                             }
                             $p->Location = $product['location'];
                             $p->ImageURL = "http://" . $_SERVER['HTTP_HOST'] . '/image/' . $product['image'];
                             $p->ImageName = str_replace("data/", "", $product['image']);
                             //@TODO: This is the full image path, simply derive filename from this
                             $p->Publish = $product['status'];
                             //$p->DateCreated     = date("Y-m-d\TH:i:s", strtotime($product['date_added']));
                             //$p->DateModified    = date("Y-m-d\TH:i:s", strtotime($product['date_modified']));
                             $this->devkit->Products->Add($p);
                         }
                     }
                 }
             } else {
                 $p = new DKProduct(Guid());
                 $p->Id = Guid();
                 //$product['product_id'];
                 //$p->Sku             = ($product['sku'] == '') ? $product['model'] : $product['sku'];
                 $p->Sku = $product['sku'];
                 $p->Name = html_entity_decode(trim($product['name']), ENT_QUOTES);
                 $p->Description = '<![CDATA[' . $product['name'] . ']]>';
                 $p->LongDescription = '<![CDATA[' . $product['description'] . ']]>';
                 $p->SupplierPartNo = $product['upc'];
                 //$p->TaxRate       = $product['tax'];
                 $p->TaxCode = $this->TaxClassToTaxCodeMap($product['tax_class_id']);
                 //$p->Tax = $product['tax'];
                 $p->SalePrice = $product['price'];
                 if ($this->config->get('zynk_download_cost_price')) {
                     // Downloading Cost Prices
                     $p->LastCostPrice = $product['cost_price'];
                 }
                 $p->UnitWeight = $product['weight'];
                 $p->Location = $product['location'];
                 $p->ImageURL = "http://" . $_SERVER['HTTP_HOST'] . '/image/' . $product['image'];
                 $p->ImageName = str_replace("data/", "", $product['image']);
                 //@TODO: This is the full image path, simply derive filename from this
                 $p->Publish = $product['status'];
                 //$p->DateCreated     = date("Y-m-d\TH:i:s", strtotime($product['date_added']));
                 //$p->DateModified    = date("Y-m-d\TH:i:s", strtotime($product['date_modified']));
                 $this->devkit->Products->Add($p);
             }
         }
         $add_product = true;
     }
 }
Ejemplo n.º 2
0
<?php

include "../src/helpers.php";
$result = Guid();
var_dump($result);
$result = Guid(16);
var_dump($result);
Ejemplo n.º 3
0
 public function Upload($data)
 {
     $xml = new SimpleXMLElement($data);
     // Customers
     if (count($xml->Customers->Customer) > 0) {
         foreach ($xml->Customers->Customer as $customer) {
             $c = $this->Customers->Add(new DKCustomer("{$customer->AccountReference}"));
             foreach ($customer as $key => $value) {
                 if ($key == 'CustomerInvoiceAddress' || $key == 'CustomerDeliveryAddress') {
                     $ca = $c->{$key} = new DKContact(Guid());
                     foreach ($value[0] as $key2 => $value2) {
                         $ca->{$key2} = $value2;
                     }
                 } else {
                     $c->{$key} = $value;
                 }
             }
         }
     }
     // Salesorders
     if (count($xml->SalesOrders->SalesOrder) > 0) {
         foreach ($xml->SalesOrders->SalesOrder as $salesOrder) {
             $s = $this->SalesOrders->Add(new DKSalesOrder("{$salesOrder->Id}"));
             foreach ($salesOrder as $key => $value) {
                 $s->{$key} = $value;
             }
         }
     }
     // Invoices
     if (count($xml->Invoices->Invoice) > 0) {
         foreach ($xml->Invoices->Invoice as $invoice) {
             $s = $this->Invoices->Add(new DKInvoice("{$invoice->InvoiceNumber}"));
             foreach ($invoice as $key => $value) {
                 $s->{$key} = $value;
             }
         }
     }
     // Products
     #$counttemp = count($xml->Products->Product);
     #echo $counttemp;exit;
     if (count($xml->Products->Product) > 0) {
         foreach ($xml->Products->Product as $product) {
             $p = $this->Products->Add(new DKProduct("{$product->Sku}"));
             foreach ($product as $key => $value) {
                 if ($key != 'Attributes' && $key != 'ProductQtyBreaks') {
                     $p->{$key} = $value;
                 }
             }
             $attribs = $p->Attributes = new Collection('DKAttribute');
             if (is_array($product->Attributes->Attribute) && count($product->Attributes->Attribute) > 0) {
                 foreach ($product->Attributes->Attribute as $attrib) {
                     $a = $attribs->Add(new DKAttribute((string) $attrib->Name));
                     foreach ($attrib as $key => $value) {
                         $a->{$key} = $value;
                     }
                 }
                 $qtyBreaks = $p->ProductQtyBreaks = new Collection('DKProductQtyBreak');
             }
             if (is_array($product->ProductQtyBreaks->ProductQtyBreak) && count($product->ProductQtyBreaks->ProductQtyBreak) > 0) {
                 foreach ($product->ProductQtyBreaks->ProductQtyBreak as $qtyBreak) {
                     $pb = $qtyBreaks->Add(new DKProductQtyBreak(Guid()));
                     foreach ($qtyBreak as $key => $value) {
                         $pb->{$key} = $value;
                     }
                 }
             }
         }
     }
     // Price Lists
     if (count($xml->PriceLists->PriceList) > 0) {
         foreach ($xml->PriceLists->PriceList as $priceList) {
             $pl = $this->PriceLists->Add(new DKPriceList("{$priceList->Reference}"));
             foreach ($priceList as $key => $value) {
                 if ($key != 'Prices') {
                     $pl->{$key} = $value;
                 }
             }
             $prices =& $priceList->Prices;
             $pc = $pl->Prices = new Collection('DKPrice');
             foreach ($prices->Price as $price) {
                 $p = $pc->Add(new DKPrice("{$price->StockCode}"));
                 foreach ($price as $key => $value) {
                     $p->{$key} = $value;
                 }
             }
             /*
             $prices =& $priceList['Prices'][0][''];
             $pc = $pl->Prices = new Collection('Price');
             
             foreach($prices as $price)
             {
                 $p = $pc->Add(new Price($price['StockCode']));
                 
                 foreach($price as $key => $value)
                 {
                     $p->$key = $value;
                 }
             }
             */
         }
     }
     // Inventories
     if (count($xml->Inventories->Inventory) > 0) {
         foreach ($xml->Inventories->Inventory as $inventory) {
             $i = $this->Inventories->Add(new DKInventory(Guid()));
             foreach ($inventory as $key => $value) {
                 if ($key != 'Locations') {
                     $i->{$key} = $value;
                 }
             }
             $ls = $i->Locations = new Collection('Location');
             if (count($inventory->Locations->Location) > 0) {
                 foreach ($inventory->Locations->Location as $location) {
                     $l = $ls->Add(new DKLocation(Guid()));
                     foreach ($location as $key => $value) {
                         $l->{$key} = $value;
                     }
                 }
             }
         }
     }
     // Transactions
     if (count($xml->Transactions->Transaction) > 0) {
         foreach ($xml->Transactions->Transaction as $transaction) {
             $t = $this->Transactions->Add(new DKTransaction("{$transaction->Id}"));
             foreach ($transaction as $key => $value) {
                 $t->{$key} = $value;
             }
         }
     }
     // Rewards
     if (count($xml->Rewards->Reward) > 0) {
         foreach ($xml->Rewards->Reward as $reward) {
             $r = $this->Rewards->Add(new DKReward("{$reward->Id}"));
             foreach ($reward as $key => $value) {
                 $r->{$key} = $value;
             }
         }
     }
 }