|
From: <os...@us...> - 2015-03-19 09:27:41
|
Revision: 5257
http://sourceforge.net/p/oscss/svn/5257
Author: oscim
Date: 2015-03-19 09:27:40 +0000 (Thu, 19 Mar 2015)
Log Message:
-----------
Add listener class for Pid id string product
Added Paths:
-----------
trunk/catalog/common/classes/cart/CartPidFormat.class.php
Added: trunk/catalog/common/classes/cart/CartPidFormat.class.php
===================================================================
--- trunk/catalog/common/classes/cart/CartPidFormat.class.php (rev 0)
+++ trunk/catalog/common/classes/cart/CartPidFormat.class.php 2015-03-19 09:27:40 UTC (rev 5257)
@@ -0,0 +1,199 @@
+<?php
+/**
+ @licence GPL 2005-2015 The osCSS developers - osCSS Open Source E-commerce
+ @package oscss-2 <www http://www.oscss.org>
+ @version 2.2.0
+ @date 2015-03-18 10:44:22
+ @author oscim <mail aur...@os...> <www http://www.oscim.fr>
+ @encode UTF-8
+ @brief Formated Pid for support other extends in cart
+ Use for attribute, bundle, master products ...
+*/
+
+
+
+class CartPidFormat {
+
+ /**
+ @var pid int value id of products
+ */
+ public $pid ;
+
+ /**
+ @var string name product completed by attribute and other option
+ */
+ protected $_extends;
+ /**
+ @var string name product completed by attribute and other option
+ */
+ protected $_id_string;
+ /**
+ @var
+ */
+ protected $_separator = '____';
+
+ /**
+ @brief constructor
+ */
+ public function __construct(){
+ $args = func_get_args();
+ $list = $args[0];
+
+ $this->reset();
+ if ( count($list) > 0 ) {
+ $this->pid = (int)$list[0];
+
+ $this->SetExtends('attribute', $list[1]);
+ $this->SetExtends('parent', $list[2]);
+ $this->FixFormatIdString();
+ }
+ }
+
+ /**
+ @brief reset
+ */
+ function reset(){
+ $this->pid = 0;
+ $this->_extends = array();
+ $this->_id_string='';
+ }
+
+ /**
+ @brief init object for extract all data based on string id coded for transport data
+ @return none
+ */
+ public function SetIdString($uprid){
+ $this->reset();
+
+ preg_match('#^(.*)'.$this->_separator.'(.*)#i', $uprid, $match);
+
+ if(isset($match[1]))
+ $this->SetExtends('parent', $match[1]);
+
+ if(isset($match[2]))
+ $pieces = explode('{', $match[2]);
+ else
+ $pieces = explode('{', $uprid);
+
+ if (is_numeric((int)$pieces[0]) && (int)$pieces[0] > 0 )
+ $this->pid = (int)$pieces[0];
+ else
+ return false;
+
+ $attrib=array();
+ for($i=1, $m=count($pieces); $i< $m ; $i++ ){
+ $r=explode('}', $pieces[$i]);
+ $attrib[$r[0]]=(is_array($r[1])? implode(',',$r[1]) :$r[1] );
+ }
+
+ if( count($attrib) > 0 )
+ $this->SetExtends('attribute', $attrib);
+
+
+
+ $this->FixFormatIdString();
+ }
+
+ /**
+ @brief Set other data
+ @return none
+ */
+ protected function SetExtends($Name, $value){
+ $this->_extends[$Name] = $value;
+ }
+
+ /**
+ @brief Get other data
+ @param $Name string name of data
+ @return false || sub data (object, array, string)
+ */
+ public function GetExtends($Name){
+ if(!isset($this->_extends[$Name]))
+ return false;
+
+ return $this->_extends[$Name] ;
+ }
+
+ /**
+ @brief Get string id product composed data
+ @return id string
+ */
+ public function GetIdString(){
+ return $this->_id_string ;
+ }
+
+ /**
+ @brief Get Id int product
+ @return int id
+ */
+ public function GetId(){
+ return $this->pid ;
+ }
+
+
+
+
+ /**
+ @brief Return a product ID with attributes
+ */
+ function FixFormatIdString() {
+
+ $uprid = '';
+ if( ($prev = $this->GetExtends('parent') ) && $prev != false)
+ $uprid .= $prev.'____';
+
+
+// ($parent_id!=0)?$parent_id.'_':'').
+
+ $uprid .= $this->GetId();
+
+
+ if( ($params = $this->GetExtends('attribute') ) && $params != false)
+ if ( (is_array($params)) && (!strstr($prid, '{')) ) {
+
+ while (list($option, $value) = each($params)) {
+ $val = '';
+ if( !is_array($value) )
+ $val .= htmlspecialchars(stripslashes(trim($value)) , ENT_QUOTES);
+ else{
+ foreach($value as $row)
+ if( is_array($row) )
+ $val.='§'.implode(',',$row).'§,';
+ else
+ $val.=$row.',';
+
+ $val = substr($val,0,-1);
+ }
+ //CLR 030714 Add processing around $value. This is needed for text attributes.
+ $uprid = $uprid . '{' . $option . '}' . $val;
+ }
+ }
+ // else {
+ // $uprid = htmlspecialchars(stripslashes(trim($value)) , ENT_QUOTES);
+ // }
+
+ $this->_id_string = $uprid;
+ }
+
+ /**
+ @brief Clean id product and Return
+ remove product with attributes information
+ @param $uprid string (14{1}1)
+ @return int product id Or false
+ */
+ function GetIdStringPid($uprid) {
+ if (is_numeric($this->pid)) return $this->pid;
+ else return false;
+ }
+
+ /**
+ Converti un $uprid en array des attributs
+ */
+ public function GetPidStringArray($uprid){
+ if( ($attrib = $this->GetExtends('attribute') ) && $attrib != false)
+ return $attrib;
+
+ return false;
+ }
+}
+?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|