/** * singleton pattern * * @return PlentyItemDataPushProducer */ public static function getInstance() { if (!isset(self::$instance) || !self::$instance instanceof PlentyItemDataPushProducer) { self::$instance = new PlentyItemDataPushProducer(); } return self::$instance; }
public function __construct() { /* * select some data, we will use them for new items */ PlentyItemDataPushCategory::getInstance()->execute(); PlentyItemDataPushWarehouse::getInstance()->execute(); PlentyItemDataPushProducer::getInstance()->execute(); $this->warehouseId = PlentyItemDataPushWarehouse::getInstance()->getFirstWarehouseId(); }
/** * * @param string $categoryId * @param array $itemUrl */ private function generateItem($categoryId, $itemUrl) { $content = file_get_contents($itemUrl); $itemName = $itemName2 = $itemName3 = ''; $shortDescription = $longDescription = ''; /* * item name */ preg_match('/class="play" align="center">(.*?)</ims', $content, $result); if (isset($result[1])) { $itemName = trim($result[1]); } preg_match('/<title>(.*?)<\\//ims', $content, $result); if (isset($result[1])) { $itemName2 = trim($result[1]); } preg_match('/ \\| (Act .*?)</ims', $content, $result); if (isset($result[1])) { $itemName3 = trim($result[1]); } /* * short description */ preg_match('/<p><blockquote>\\n<i>(.*?)<\\//ims', $content, $result); if (isset($result[1])) { $shortDescription = trim(strip_tags($result[1])); } /* * description */ preg_match('/\\/h3>(.*?)<table/ims', $content, $result); if (isset($result[1])) { $longDescription = trim($result[1]); $longDescription = strip_tags($longDescription, '<i>,<p>,<br>,<b>,<blockquote>'); $longDescription .= chr(10) . chr(10) . '<p>reference: <a href="' . $itemUrl . '">' . $itemUrl . '</a></p>'; } if (strlen($itemName) && strlen($itemName2) && strlen($longDescription)) { /* * push result to plenty soap object */ $plentySoapObject_ItemTexts = new PlentySoapObject_ItemTexts(); $plentySoapObject_ItemTexts->Lang = $this->lang; $plentySoapObject_ItemTexts->Name = $itemName . (strlen($itemName3) ? ' / ' . $itemName3 : ''); $plentySoapObject_ItemTexts->Name2 = $itemName2; $plentySoapObject_ItemTexts->Name3 = $itemName3; $plentySoapObject_ItemTexts->MetaDescription = $this->procuder . ' ' . $plentySoapObject_ItemTexts->Name; $plentySoapObject_ItemTexts->ShortDescription = $shortDescription; $plentySoapObject_ItemTexts->LongDescription = $longDescription; /* * push category */ $plentySoapObject_ItemCategory = new PlentySoapObject_ItemCategory(); $plentySoapObject_ItemCategory->ItemCategoryPath = $categoryId . ';;;;;'; $plentySoapObject_AddItemsBaseItemBase = new PlentySoapObject_AddItemsBaseItemBase(); $plentySoapObject_AddItemsBaseItemBase->Texts = $plentySoapObject_ItemTexts; /* * category is a list so add as an array */ $plentySoapObject_AddItemsBaseItemBase->Categories[] = $plentySoapObject_ItemCategory; /* * producer */ $producerId = PlentyItemDataPushProducer::getInstance()->checkProducer($this->procuder); if (!$producerId) { PlentyItemDataPushProducer::getInstance()->saveNewProducer($this->procuder); $producerId = PlentyItemDataPushProducer::getInstance()->checkProducer($this->procuder); } if ($producerId > 0) { $plentySoapObject_AddItemsBaseItemBase->ProducerID = $producerId; } /* * push to stack */ $this->itemList[] = $plentySoapObject_AddItemsBaseItemBase; $this->getLogger()->debug(__FUNCTION__ . ' add new item text / item name: ' . $plentySoapObject_ItemTexts->Name); } }