Jump to content

How to add fields matching each pg of tpl in module config & add to pg created by?


hellomoto
 Share

Recommended Posts

Need your kindly tips and guidance:

So I need for the configuration to have a field for every existing [template=]supplier, for matching with a dir (not already matched) within the module directory which contains the import & update scripts for that supplier.
Then on the admin page created by this module under Admin > Setup, all of the Suppliers need to be listed with corresponding links to Import or Update where available (for those matched to a directory);
and when one of those actions is executed it should load the results log in an iframe.

But, how?

Here is what I have so far, yet to try activated:

<?php
/**
 * Process Products Data (0.0.1)
 * Scrapes  imports products, and updates pricing, availability  variations synchronized with data feeds. Process tailored per source account/supplier.
 *
 * @author
 *
 * ProcessWire 3.x
 * Copyright (C) 2011 by Ryan Cramer
 * Licensed under GNU/GPL v2, see LICENSE.TXT
 *
 * http://www.processwire.com
 * http://www.ryancramer.com
 *
 */

class ImportProductsData extends Process implements ConfigurableModule {

	public static function getModuleInfo() {
		return array(
			'title' => "Process Products Data",
			'version' => "0.0.1",
			'summary' => "Scrapes &amp; imports products, and updates pricing, availability &amp; variations synchronized with data feeds. Process tailored per source account/supplier.",

			'permission' => array(""),
			'autoload' => false,
			'singular' => true,
			'permanent' => false,
			'permission' => 'products-impupd',

			'requires' => array("PHP>=5.4.0", "ProcessWire>=2.5.28", ""),
			//'installs' => array(""),

		);
	}

	const PAGE_NAME = 'products-impupd';

	static public function getDefaults() {
		return array(
		);
	}

	public function init() {
		// $this->addStyle("custom.css");
		// $this->addScript("custom.js");
		// $this->addHookAfter("class::function", $this, "yourFunction");
	}

	public function ___install() {
		// Create page "Product Data ImpUpd" under Setup
		$page = $this->pages->get('template=admin, name='.self::PAGE_NAME);
		if (!$page->id) {
				$page = new Page();
				$page->template = 'admin';
				$page->parent = $this->pages->get($this->config->adminRootPageID)->child('name=setup');
				$page->title = 'Products Import&amp;Update';
				$page->name = self::PAGE_NAME;
				$page->process = $this;
				$page->save();

			// tell the user we created this page
			$this->message("Created Page: {$page->path}");

		}

	}

	public function ___uninstall() {
		// Del page ImpUpd under Setup
		//$moduleID = $this->modules->getModuleID($this);
		$page = $this->pages->get('template=admin, name='.self::PAGE_NAME);

		if($page->id) {
			// if we found the page, let the user know and delete it
			$this->wire('pages')->delete($page, true);
			$this->message($this->_('Deleted Page: ') . $page->path);
		}
	}

	static public function getModuleConfigInputfields(array $data) {
		$inputfields = new InputfieldWrapper();

		$defaults = self::getDefaults();
		$data = array_merge($defaults, $data);

		return $inputfields;
		// foreach supplier select data set dir (each w/ import & update fct)
		// defaults = supplier.name
		// once selected execute import or update & log
		// in iframe & display results [log]
	}

}

 

Edited by hellomoto
more descriptive title
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...