Last active
December 18, 2015 04:29
-
-
Save CameronGilroy/5726072 to your computer and use it in GitHub Desktop.
Here is part of the code that I have written for the module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') or exit('No direct script access allowed'); | |
/** | |
* This file is part of FireSale, a PHP based eCommerce system built for | |
* PyroCMS. | |
* | |
* Copyright (c) 2013 Moltin Ltd. | |
* http://github.com/firesale/firesale | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
* | |
* @package firesale/prices | |
* @author FireSale <[email protected]> | |
* @copyright 2013 Moltin Ltd. | |
* @version master | |
* @link http://github.com/firesale/firesale | |
* | |
*/ | |
class Module_Firesale_prices extends Module | |
{ | |
public $version = '0.1'; | |
public $language_file = 'firesale_prices/firesale'; | |
public function __construct() | |
{ | |
parent::__construct(); | |
// Load in the FireSale library | |
$this->load->library('firesale/firesale'); | |
$this->lang->load($this->language_file); | |
} | |
public function info() | |
{ | |
$info = array( | |
'name' => array( | |
'en' => 'FireSale Prices', | |
'fr' => 'FireSale Marques', | |
'it' => 'FireSale Marche' | |
), | |
'description' => array( | |
'en' => 'Price Management', | |
'fr' => 'Gestion des marques', | |
'it' => 'Gestione Marche' | |
), | |
'frontend' => FALSE, | |
'backend' => TRUE, | |
'author' => 'Cameron Gilroy', | |
); | |
return $info; | |
} | |
public function install() | |
{ | |
if ($this->firesale->is_installed()) { | |
// Load requirements | |
$this->load->driver('Streams'); | |
$this->load->model('firesale/products_m'); | |
$this->lang->load('firesale/firesale'); | |
##################### | |
## APPEND PRODUCTS ## | |
##################### | |
$template = array( | |
'namespace' => 'firesale_products', | |
'assign' => 'firesale_products', | |
'type' => 'text', | |
'title_column' => FALSE, | |
'required' => TRUE, | |
'unique' => FALSE | |
); | |
$fields[] = array( | |
'name' => 'Church Price', | |
'slug' => 'church_price', | |
'type' => 'decimal', | |
'instructions' => 'The price for churches', | |
'extra' => array('decimal_places' => '2', 'min_value' => '0.00') | |
); | |
$fields[] = array( | |
'name' => 'Church Price Tax', | |
'slug' => 'church_price_tax', | |
'type' => 'decimal', | |
'extra' => array('decimal_places' => '2', 'min_value' => '0.00') | |
); | |
$fields[] = array( | |
'name' => 'Reseller Price', | |
'slug' => 'reseller_price', | |
'type' => 'decimal', | |
'instructions' => 'The price for resellers', | |
'extra' => array('decimal_places' => '2','min_value' => '0.00') | |
); | |
$fields[] = array( | |
'name' => 'Reseller Price Tax', | |
'slug' => 'reseller_price_tax', | |
'type' => 'decimal', | |
'extra' => array('decimal_places' => '2','min_value' => '0.00') | |
); | |
// Add fields to stream | |
foreach( $fields AS &$field ) { $field = array_merge($template, $field); } | |
$this->streams->fields->add_fields($fields); | |
return TRUE; | |
} | |
} | |
public function uninstall() | |
{ | |
// Load required items | |
$this->load->driver('Streams'); | |
$this->load->model('firesale/categories_m'); | |
$this->load->model('firesale/products_m'); | |
// Remove prices field from products | |
$this->streams->fields->delete_field('church_price', 'firesale_products'); | |
$this->streams->fields->delete_field('church_price_tax', 'firesale_products'); | |
$this->streams->fields->delete_field('reseller_price', 'firesale_products'); | |
$this->streams->fields->delete_field('reseller_price_tax', 'firesale_products'); | |
return TRUE; | |
} | |
public function upgrade($old_version) | |
{ | |
return TRUE; | |
} | |
public function help() | |
{ | |
return "Some Help Stuff"; | |
} | |
} |
@AJSturrock I've posted the full file as I have it now - any suggestions? & it's still not working. :(
It's working now - lines 107-109 is where the problem was
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've missed out combining $template and $fields before adding the fields to the stream hence the empty field namespace error. Just add the below:
You can also just add all the key value pairs in $template to each of the $fields individually if you want (e.g. some fields might be required etc).