/** * Write a source object to an XML stream, mapping fields via a fieldset. * Fieldsets are nodes in config.xml * * @param string $fieldset * @param array|Varien_Object $source * @param XMLWriter $xml */ public function fieldsetToXml($fieldset, $source, XMLWriter $xml, $isBundle = 0, $fltConfigItemPrice = 0) { $fields = (array) Mage::getConfig()->getFieldset($fieldset); //Check for the importing the child product settings $intImportChildProducts = Mage::getStoreConfig('auctaneapi/general/import_child_products'); foreach ($fields as $field => $dest) { if (!$dest->auctaneapi) { continue; } $name = $dest->auctaneapi == '*' ? $field : $dest->auctaneapi; $value = $source instanceof Varien_Object ? $source->getDataUsingMethod($field) : @$source[$field]; //Set the child item price of bundle products to 0 if ($isBundle == 1 && $name == 'UnitPrice' && $intImportChildProducts == 1) { //continue; $value = 0; } //set the configurable product base price if ($name == 'UnitPrice' && $fltConfigItemPrice) { $value = $fltConfigItemPrice; } $xml->startElement((string) $name); if (is_numeric($value)) { $xml->text((string) $value); } elseif ($value) { $xml->writeCdata((string) $value); } $xml->endElement(); } }
/** * Return an entity's file full URL * * @param Varien_Object $entity Entity owning the file * @param string $attribute Code of the attribute corresponding to the file * @return string */ public function getEntityFileUrl($entity, $attributeCode) { if ($file = $entity->getDataUsingMethod($attributeCode)) { return $this->getFileUrl($file); } return false; }
/** * @param Varien_Object $object * @param string $key * * @return mixed */ public function getObjectData(Varien_Object $object, $key = null) { if ($key) { return $object->getDataUsingMethod($key); } else { return $object->getData(); } }
protected function getAttributeValue(Varien_Object $object) { switch ($this->getAttribute()) { case 'email_domain': $emailAddress = $object->getDataUsingMethod('customer_email'); $emailDomain = substr($emailAddress, strpos($emailAddress, '@') + 1); $emailDomain = trim(strtolower($emailDomain)); return $emailDomain; break; case 'remote_ip': $ipList = explode(',', $object->getDataUsingMethod('x_forwarded_for')); $ipList[] = $object->getDataUsingMethod('remote_ip'); $ipList = array_unique(array_filter(array_map('trim', $ipList))); return $ipList; break; default: return parent::getAttributeValue($object); } }
/** * Read in the attributes from a resource * * @param Varien_Object $resource * @param string[] $attributeCodes * @param mixed[] $data * * @return mixed[] */ protected function loadResourceAttributes(Varien_Object $resource, array $attributeCodes, array $data = []) { $attributeCodes = array_diff($attributeCodes, $this->manualAttributes); $attributeCodes = array_combine($attributeCodes, $attributeCodes); $attributeCodes = array_merge($attributeCodes, array_intersect_key($this->attributeMap, $attributeCodes)); foreach ($attributeCodes as $externalKey => $internalKey) { $data[$externalKey] = $resource->getDataUsingMethod($internalKey); } return $data; }
/** * Renders column * * @param Varien_Object $row * * @return string */ public function render(Varien_Object $row) { $renderActions = []; $actions = $this->getColumn()->getActions(); if (is_array($actions)) { foreach ($actions as $action) { if (isset($action['checks'])) { $fail = false; $checks = array_filter(array_map('trim', explode(',', $action['checks']))); foreach ($checks as $check) { $negativeCheck = substr($check, 0, 1) === '!'; $check = $negativeCheck ? substr($check, 1) : $check; $value = strpos($check, '/') === false ? $row->getDataUsingMethod($check) : $row->getData($check); if ((bool) $value === $negativeCheck) { $fail = true; break; } } if ($fail) { continue; } } $renderActions[] = $action; } } if (empty($renderActions)) { return ' '; } $linkLimit = $this->getColumn()->getNoLink() ? 0 : max(intval($this->getColumn()->getLinkLimit()), 1); $out = ''; if (count($renderActions) <= $linkLimit) { foreach ($renderActions as $action) { if (is_array($action)) { $out .= $this->_toLinkHtml($action, $row); } } } else { $out .= '<select class="action-select" onchange="varienGridAction.execute(this);">'; $out .= '<option value=""></option>'; foreach ($renderActions as $action) { if (is_array($action)) { $out .= $this->_toOptionHtml($action, $row); } } $out .= '</select>'; } return $out; }
/** * Renders grid column * * @param Varien_Object $row * * @return string */ public function render(Varien_Object $row) { $name = trim($this->getColumn()->getNamePattern()); if (!empty($name)) { $nameParams = array_map('trim', array_filter(explode(',', $this->getColumn()->getNameParams()))); if (count($nameParams)) { $params = [$name]; foreach ($nameParams as $key) { $params[] = $row->getDataUsingMethod($key); } $name = call_user_func_array([$this, '__'], $params); } $this->getColumn()->setName($name); } return parent::render($row); }
/** * Write a source object to an XML stream, mapping fields via a fieldset. * Fieldsets are nodes in config.xml * * @param string $fieldset * @param array|Varien_Object $source * @param XMLWriter $xml */ public function fieldsetToXml($fieldset, $source, XMLWriter $xml) { $fields = (array) Mage::getConfig()->getFieldset($fieldset); foreach ($fields as $field => $dest) { if (!$dest->auctaneapi) { continue; } $name = $dest->auctaneapi == '*' ? $field : $dest->auctaneapi; $value = $source instanceof Varien_Object ? $source->getDataUsingMethod($field) : @$source[$field]; $xml->startElement((string) $name); if (is_numeric($value)) { $xml->text((string) $value); } elseif ($value) { $xml->writeCdata((string) $value); } $xml->endElement(); } }
protected function getAttributeValue(Varien_Object $object) { $attribute = $this->getAttribute(); if (empty($attribute)) { return null; } /** @var Mage_Sales_Model_Order_Address $object */ if ($object instanceof Mage_Sales_Model_Order_Address && $attribute === 'all') { $value = $object->format("text"); } else { $value = $object->getDataUsingMethod($attribute); } if (is_scalar($value)) { // Convert 2+ spaces in a row into a single space $value = preg_replace('/ {2,}/u', ' ', $value); // Remove leading/trailing spaces $value = trim($value); } return $value; }
/** * Get data from specified object * * @param Varien_Object $object * @param string $key * @return mixed */ public function getObjectData(Varien_Object $object, $key) { return $object->getDataUsingMethod((string) $key); }
public function getObjectData(Varien_Object $object, $key) { $value = null; if (strpos($key, '/') === false) { $value = $object->getDataUsingMethod($key); } else { $key = explode('/', $key); $value = $object; foreach ($key as $i => $k) { if ($k === '') { $value = null; break; } if (is_array($value)) { if (!isset($value[$k])) { $value = null; break; } $value = $value[$k]; } elseif ($value instanceof Varien_Object) { $value = $value->getDataUsingMethod($k); } else { $value = null; break; } } } return $value; }
/** * init image * * @access public * @param Varien_Object $object * @param string $imageField * @return Zoffio_DiscountTypes_Helper_Image_Abstract * @author Ultimate Module Creator */ public function init(Varien_Object $object, $imageField = 'image') { $this->_imageProcessor = null; $this->_image = $object->getDataUsingMethod($imageField); if (!$this->_image) { $this->_image = '/' . $this->_placeholder; } $this->_width = null; $this->_height = null; $this->_scheduledResize = false; $this->_resized = false; $this->_adaptiveResize = 'center'; try { $this->_getImageProcessor()->open($this->getImageBaseDir() . $this->_image); } catch (Exception $e) { $this->_openError = $e->getMessage(); try { $this->_getImageProcessor()->open(Mage::getDesign()->getSkinUrl($this->_placeholder)); $this->_image = '/' . $this->_placeholder; } catch (Exception $e) { $this->_openError .= "\n" . $e->getMessage(); $this->_image = null; } } return $this; }
/** * init image * @access public * @param Varien_Object $object * @param string $imageField * @return Easylife_Switcher_Helper_Optimage * */ public function init(Varien_Object $object, $imageField = 'image') { $this->_imageProcessor = null; $this->_image = ltrim($object->getDataUsingMethod($imageField), '/\\ '); $this->_absImage = null; $this->_widht = null; $this->_height = null; $this->_scheduledResize = false; $this->_resized = false; $this->_adaptiveResize = 'center'; $this->_openError = ''; $checkImages = array(); if ($this->_image) { $this->_image = DS . $this->_image; $checkImages[$this->_image] = $this->getImageBaseDir() . $this->_image; } $_placeholder = DS . ltrim($this->_placeholder, ' \\/'); $checkImages[$_placeholder] = array_unique(array(Mage::getDesign()->getSkinBaseDir() . $_placeholder, Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default')) . $_placeholder, Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base')) . $_placeholder)); $_mediaPlaceholder = DS . basename($_placeholder); $checkImages[$_mediaPlaceholder] = $this->getImageBaseDir() . $_mediaPlaceholder; foreach ($checkImages as $_image => $_absImages) { if (!is_array($_absImages)) { $_absImages = array($_absImages); } foreach ($_absImages as $_absImage) { if (file_exists($_absImage)) { $this->_image = $_image; $this->_absImage = $_absImage; break 2; //break both foreach } } } if ($this->_absImage) { try { $this->_getImageProcessor()->open($this->_absImage); } catch (Exception $e) { $this->_openError .= $e->getMessage(); $this->_image = null; $this->_absImage = ''; } } return $this; }
protected function getAttributeValue(Varien_Object $object) { $attribute = $this->getAttribute(); if (!empty($attribute)) { return $object->getDataUsingMethod($attribute); } else { return null; } }