/** * Constructor * @param Element|String $element * @param Item $item * @param array $options */ function __construct($element, Item $item = null, $options = array()) { // get Zoo app $this->app = App::getInstance('zoo'); // set inner vars if (isset($options['elementId'])) { $this->_identifier = $options['elementId']; $this->_item = $item; $this->_element = $this->_item->getElement($this->_identifier); } else { if (is_object($element)) { $this->_element = $element; $this->_item = $element->getItem(); $this->_identifier = $element->identifier; } else { $this->_identifier = $element; } } // set repeatable flag if (is_object($this->_element) && is_subclass_of($this->_element, 'ElementRepeatable')) { $this->_isRepeatable = true; } // set Item object if (!$this->_item && $item) { $this->_item = $item; } // get current value for export) if ($this->_item && $this->_identifier && isset($this->_item->elements[$this->_identifier])) { $this->_value = $this->_item->elements[$this->_identifier]; } $this->_config = JBModelConfig::model(); $this->_exportParams = $this->_config->getGroup('export.items', array()); $this->_importParams = $this->_config->getGroup('import.items', array()); $this->_lastImportParams = $this->_config->getGroup('import.last.items', array()); }
/** * Render item element * @param string $elementId * @param Item $item * @param array $params * @return string */ public function renderItemElement($elementId, Item $item, $params = array()) { $element = $item->getElement($elementId); if ($element && $item && $element->hasValue()) { return parent::render("element.default", array('params' => $params, 'element' => $element, 'item' => $item)); } return null; }
/** * Render HTML image form item by elementId * @param Item $item * @param $elementId * @param bool $isLink * @return string|null */ public function renderImageFromItem(Item $item, $elementId, $isLink = false) { if (!$elementId) { return null; } $element = $item->getElement($elementId); if (JString::strtolower(get_class($element)) == 'elementjbimage') { return $element->render(array('width' => 50, 'height' => 50, 'template' => 'itemlink', 'display' => 'first')); } else { if (JString::strtolower(get_class($element)) == 'elementimage') { return $element->render(array('width' => 50, 'height' => 50)); } } return null; }
public function callElement() { // get request vars $element_identifier = YRequest::getString('elm_id', ''); $item_id = YRequest::getInt('item_id', 0); $type = YRequest::getString('type', ''); $this->method = YRequest::getCmd('method', ''); $this->args = YRequest::getVar('args', array(), 'default', 'array'); JArrayHelper::toString($this->args); // load element if ($item_id) { $item = YTable::getInstance('item')->get($item_id); } elseif (!empty($type)) { $item = new Item(); $item->application_id = $this->application->id; $item->type = $type; } // execute callback method if ($element = $item->getElement($element_identifier)) { echo $element->callback($this->method, $this->args); } }
/** * Get duration element from item, using mapping * * @param Item $item * @param string Subscription property name, that you wish to get (e.g. duration, etc.) * @return mixed */ public function getSubscriptionElements($item) { $duration = array(); if (!empty($item)) { $config = array(); $config[] = $item->getApplication()->application_group; $config[] = $item->type; $config[] = 'subscription'; $renderer = $this->app->renderer->create('item')->addPath(array($this->app->path->path("zoocart:mapping"))); $subs_config = $renderer->getConfig('item')->get(implode('.', $config)); if (!empty($subs_config)) { foreach ($subs_config as $property => $elements) { // Get first element from each position: $element = @array_shift($elements); if ($element) { $duration[$property] = $item->getElement($element['element']); } } } } return $duration; }
/** * @param Item $order * @return JBCartElementOrderMigration */ protected function _createOrderElement(Item $order) { /** @var JBCartElementOrderMigration $orderElement */ $orderElement = $this->app->jbcartelement->create('migration', JBCart::ELEMENT_TYPE_ORDER, array('name' => JText::_('JBZOO_MIGRATE_FIELDS_NAME'), 'identifier' => $this->app->utility->generateUUID())); $result = array(); foreach ($this->_fields as $elemId => $elemParams) { if ($element = $order->getElement($elemId)) { $name = $element->config->name; if ($elemParams['_value_map']) { $data = $this->app->data->create($element->data()); $content = $data->find($elemParams['_value_map']); } else { $content = $element->getSearchData(); } $result[$name] = $content; } } $orderElement->bindData(array('content' => $result)); return $orderElement; }
/** * @param Item $item * @return bool */ public function _convertItem(Item $item) { $oldPrices = $item->getElementsByType('jbpriceadvance'); $oldPrice = current($oldPrices); if (!$oldPrice) { return false; } $oldData = $this->app->data->create($oldPrice->data()); $params = $this->app->data->create($this->_migrate->getParams()->find('elements.' . $oldPrice->identifier)); $newPriceData = array('default_variant' => 0, 'variations' => array(array('_sku' => array('value' => $oldData->find('basic.sku')), '_balance' => array('value' => $oldData->find('basic.balance')), '_value' => array('value' => $oldData->find('basic.value') . ' ' . $oldData->find('basic.currency')), '_discount' => array('value' => $oldData->find('basic.discount') . ' ' . $oldData->find('basic.discount_currency')), '_description' => array('value' => $oldData->find('basic.description'))))); $variations = (array) $oldData->find('variations', array()); foreach ($variations as $vari) { /** @var AppData $vari */ $vari = $this->app->data->create($vari); $newPriceData['variations'][] = array('_value' => array('value' => $vari->get('value') . ' ' . $vari->get('currency')), '_balance' => array('value' => $vari->get('balance')), '_sku' => array('value' => $vari->get('sku')), 'param1' => array('value' => $params->find('map.param1.options-map.' . $vari->get('param1'))), 'param2' => array('value' => $params->find('map.param2.options-map.' . $vari->get('param2'))), 'param3' => array('value' => $params->find('map.param3.options-map.' . $vari->get('param3'))), 'old-description' => array('value' => $vari->get('description'))); } /** @var ElementJBPricePlain $newPrice */ $newPriceId = $params->get('id'); if ($newPriceId && ($newPrice = $item->getElement($newPriceId))) { $newPrice->bindData($newPriceData); } return true; }