protected function setTrackingReqeust() { $r = new Varien_Object(); $id = $this->getConfigData('id'); $r->setId($id); $this->_rawTrackRequest = $r; }
/** * @loadFixture ../../../var/fixtures/aliases.yaml */ public function testGetStoredAliasForCustomer() { $reflectionClass = new ReflectionClass(get_class($this->_block)); $method = $reflectionClass->getMethod("getStoredAliasForCustomer"); $method->setAccessible(true); $this->assertNull($method->invoke($this->_block)); $configMock = $this->getModelMock('ops/config', array('isAliasManagerEnabled')); $configMock->expects($this->any())->method('isAliasManagerEnabled')->will($this->returnValue(true)); $this->replaceByMock('model', 'ops/config', $configMock); $aliases = Mage::getModel('ops/alias')->getCollection()->addFieldToFilter('customer_id', 1)->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC); $alias = $aliases->getFirstItem(); $aliasHelperMock = $this->getHelperMock('ops/alias', array('getAliasesForAddresses')); $aliasHelperMock->expects($this->once())->method('getAliasesForAddresses')->will($this->returnValue($aliases)); $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock); $customerMock = $this->getHelperMock('customer/data', array('isLoggedIn')); $customerMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->replaceByMock('helper', 'customer/data', $customerMock); $fakeCustomer = new Varien_Object(); $fakeCustomer->setId(1); $fakeQuote = new Varien_Object(); $fakeQuote->setCustomer($fakeCustomer); $blockMock = $this->getBlockMock('ops/form', array('getQuote')); $blockMock->expects($this->once())->method('getQuote')->will($this->returnValue($fakeQuote)); $this->replaceByMock('block', 'ops/form', $blockMock); $reflectionClass = new ReflectionClass(get_class($blockMock)); $method = $reflectionClass->getMethod("getStoredAliasForCustomer"); $method->setAccessible(true); $this->assertEquals($alias->getData(), $method->invoke($blockMock)); }
/** * Prepare grid collection */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $layout = $this->getLayout(); $update = $layout->getUpdate(); $design = Mage::getSingleton('core/design_package'); $layoutXML = $update->getFileLayoutUpdatesXml('frontend', $design->getPackageName(), $design->getTheme('layout'), 0); $xpath = $layoutXML->xpath('//action[@method="setEsi"]'); foreach ($xpath as $x) { $esi = new Varien_Object(); $handle = $x->xpath('ancestor::node()[last()-2]'); $handleName = $handle[0]->label ? $handle[0]->label : $handle[0]->getName(); $parentBlock = $x->xpath('parent::*'); $parentBlockName = $parentBlock[0]->getAttribute('name'); $parentBlockDescription = $parentBlock[0]->getAttribute('description'); $cacheType = $x->params->cache_type ? $x->params->cache_type : "global"; $esi->setId($parentBlockName); $esi->setHandle($handleName); $esi->setBlockName($parentBlockName); $esi->setDescription($parentBlockDescription); $esi->setCacheType($cacheType); try { $collection->addItem($esi); } catch (Exception $e) { Mage::logException($e); } } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Prepare page object * * @param array $data * @return Varien_Object */ protected function _prepareObject(array $data) { $object = new Varien_Object(); $object->setId($data[$this->getIdFieldName()]); $object->setUrl($data['url']); return $object; }
/** * Update attribute values for entity list per store * * @param array $entityIds * @param array $attrData * @param int $storeId * @return Mage_Catalog_Model_Product_Action */ public function updateAttributes($entityIds, $attrData, $storeId) { $object = new Varien_Object(); $object->setIdFieldName('entity_id')->setStoreId($storeId); $this->_getWriteAdapter()->beginTransaction(); try { foreach ($attrData as $attrCode => $value) { $attribute = $this->getAttribute($attrCode); if (!$attribute->getAttributeId()) { continue; } $i = 0; foreach ($entityIds as $entityId) { $object->setId($entityId); // collect data for save $this->_saveAttributeValue($object, $attribute, $value); // save collected data every 1000 rows if ($i % 1000 == 0) { $this->_processAttributeValues(); } } } $this->_processAttributeValues(); $this->_getWriteAdapter()->commit(); } catch (Exception $e) { $this->_getWriteAdapter()->rollBack(); throw $e; } return $this; }
/** * Converts map array to microdata Object * * @param array $map map array returned by the generator * @return null|Varien_Object */ protected function _createRowObject($map) { if (empty($map['price']) || empty($map['availability']) || empty($map['title'])) { return null; } $microdata = new Varien_Object(); $microdata->setName($map['title']); $microdata->setId($map['id']); if (!empty($map['sale_price'])) { $price = $map['sale_price']; } else { $price = $map['price']; } $microdata->setPrice(Zend_Locale_Format::toNumber($price, array('precision' => 2, 'number_format' => '#0.00'))); $microdata->setCurrency(Mage::app()->getStore()->getCurrentCurrencyCode()); if ($map['availability'] == 'in stock') { $microdata->setAvailability('http://schema.org/InStock'); } else { $microdata->setAvailability('http://schema.org/OutOfStock'); } if (array_key_exists('condition', $map)) { if (strcasecmp('new', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/NewCondition'); } else { if (strcasecmp('used', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/UsedCondition'); } else { if (strcasecmp('refurbished', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/RefurbishedCondition'); } } } } return $microdata; }
protected function _prepareObject(array $data) { $object = new Varien_Object(); $object->setId($data['post_id']); $object->setUrl($data['url']); $object->setDate($data['date']); return $object; }
/** * Prepare category * * @param array $categoryRow * @return Varien_Object */ protected function _prepareCategory(array $categoryRow) { $category = new Varien_Object(); $category->setId($categoryRow[$this->getIdFieldName()]); $categoryUrl = $this->getCategoryUrl($categoryRow, $category); $category->setUrl($categoryUrl); return $category; }
protected function _beforeSave(Varien_Object $object) { if (!$object->getId() && $object->getSku()) { $object->setId($this->getIdBySku($object->getSku())); } if (is_array($object->getData('category_ids'))) { $object->setData('category_ids', implode(',', $object->getData('category_ids'))); } return parent::_beforeSave($object); }
/** * Add new massaction item * * $item = array( * 'label' => string, * 'complete' => string, // Only for ajax enabled grid (optional) * 'url' => string, * 'confirm' => string, // text of confirmation of this action (optional) * 'additional' => string // (optional) * ); * * @param string $itemId * @param array|Varien_Object $item * @return Mage_Backend_Block_Widget_Grid_Massaction_Abstract */ public function addItem($itemId, $item) { if (is_array($item)) { $item = new Varien_Object($item); } if ($item instanceof Varien_Object) { $item->setId($itemId); $item->setUrl($this->getUrl($item->getUrl())); $this->_items[$itemId] = $item; } return $this; }
public function testGetRecommendedCategoryIds() { $productType = new Varien_Object(); $productType->setId('test_id_1'); $productTypeId = 'test_id_1'; $expectedResult = array(1, 2, 3); $selectMock = $this->_getSelectMock(array('category_id'), 'mapping_product_type_id', 'test_id_1'); $adapterMock = $this->_getAdapterMock($selectMock, $expectedResult); $this->_mockReadAdapter($adapterMock); $result = $this->_object->getRecommendedCategoryIds($productTypeId); $this->assertEquals($expectedResult, $result); }
public function _ToHtml() { $json = array(); $data = Mage::helper('core')->jsonDecode($this->getRequest()->getPost('data')); foreach ($data as $f) { $row = new Varien_Object(); $row->setId($f[0]); $row->setCronExpr($f[1]); $status = new Wyomind_Simplegoogleshopping_Block_Adminhtml_Simplegoogleshopping_Renderer_Status(); $json[] = array("id" => $f[0], "content" => $status->render($row)); } return Mage::helper('core')->jsonEncode($json); }
protected function _prepareProduct(array $productRow) { $product = new Varien_Object(); $product->setId($productRow[$this->getIdFieldName()]); $id = $product->getId(); $productMedia = Mage::getModel('catalog/product')->load($id)->getImage(); $product->setMedia($productMedia); $productName = Mage::getModel('catalog/product')->load($id)->getName(); $product->setName($productName); $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); $product->setUrl($productUrl); return $product; }
public function jsonProductInfoAction() { $response = new Varien_Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = Mage::getModel('catalog/product')->load($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(Mage::helper('catalog')->__('Unable to get the product ID.')); } $this->getResponse()->setBody($response->toJSON()); }
public function testGetAffectedFields() { $valueId = 2345; $attributeId = 345345; $attribute = $this->getMock('Mage_Eav_Model_Entity_Attribute_Abstract', array('getBackendTable', 'isStatic', 'getAttributeId', 'getName'), array(), '', false); $attribute->expects($this->any())->method('getName')->will($this->returnValue('image')); $attribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($attributeId)); $attribute->expects($this->any())->method('isStatic')->will($this->returnValue(false)); $attribute->expects($this->any())->method('getBackendTable')->will($this->returnValue('table')); $this->_model->setAttribute($attribute); $object = new Varien_Object(); $object->setImage(array('images' => array(array('value_id' => $valueId)))); $object->setId(555); $this->assertEquals(array('table' => array(array('value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()))), $this->_model->getAffectedFields($object)); }
/** * Mage_Catalog_Model_Resource_Eav_Mysql4_Import_Product_Action::update() * * @param mixed $entityId * @param mixed $data = array('statics' => , 'attributes' => , 'inventories' => ) * @param mixed $storeId * @return void */ public function update($entityId, $data, $storeId, $obj = null) { $object = new Varien_Object(); $object->setIdFieldName('entity_id')->setStoreId($storeId); $this->_getWriteAdapter()->beginTransaction(); try { if ($obj == null) { $obj = new Varien_Object(); } if (!$obj->getId()) { $this->simpleLoad($obj, $entityId); } //update attributes foreach ($data['attributes'] as $attrCode => $value) { $attribute = $this->getAttribute($attrCode); if (!$this->__checkApply($obj, $attribute)) { continue; } $object->setId($entityId); // collect data for save $this->_saveAttributeValue($object, $attribute, $value); // save collected data every 1000 rows } //update $this->__updateProductValues($entityId, $data['statics']); //update inventory if (count($data['inventories']) > 0) { $stockItem = Mage::getSingleton('cataloginventory/stock_item'); $stockItem->setData(array()); $stockItem->loadByProduct($entityId)->setProductId($entityId); $stockDataChanged = false; foreach ($data['inventories'] as $k => $v) { $stockItem->setDataUsingMethod($k, $v); if ($stockItem->dataHasChangedFor($k)) { $stockDataChanged = true; } } if ($stockDataChanged) { $stockItem->save(); } } $this->_processAttributeValues(); $this->_getWriteAdapter()->commit(); } catch (Exception $e) { $this->_getWriteAdapter()->rollBack(); throw $e; } }
public function getCollection($storeId) { $pages = parent::getCollection($storeId); $select = Mage::getModel('amlanding/page')->getCollection()->addFieldToFilter('is_active', 1)->getSelect()->join(array('amlanding_page_store' => $this->getTable('amlanding/page_store')), 'main_table.page_id = amlanding_page_store.page_id', array())->where('amlanding_page_store.store_id IN (?)', array($storeId)); $query = $this->_getWriteAdapter()->query($select); $urlSuffix = Mage::helper('catalog/category')->getCategoryUrlSuffix($storeId); $urlSuffix = $urlSuffix ? $urlSuffix : ''; while ($row = $query->fetch()) { $object = new Varien_Object(); $object->setId($row['page_id']); $object->setUrl($row['identifier'] . $urlSuffix); $object->setTitle($row['title']); $pages[] = $object; } return $pages; }
/** * Test order revers method * * @test * @throws \Exception */ public function testReverseOrder() { $a = new \Varien_Object(); $a->setId(1); $b = new \Varien_Object(); $b->setId(2); $collection = new \Magemock_Sample_Model_Resource_Vehicle_Collection(); $collection->addItem($a); $collection->addItem($b); $collection->reverse(); $items = $collection->getItems(); $this->assertSame(1, $items[1]->getId()); $this->assertSame(2, $items[2]->getId()); $this->assertSame(2, $collection->getFirstItem()->getId()); $this->assertSame(1, $collection->getLastItem()->getId()); }
private function setUpHelperMock($returnStatus, $setStoreId = true) { $paymentHelperMock = $this->getHelperMock('ops/payment', array('applyStateForOrder', 'shaCryptValidation')); $paymentHelperMock->expects($this->any())->method('applyStateForOrder')->will($this->returnValue($returnStatus)); $paymentHelperMock->expects($this->any())->method('shaCryptValidation')->will($this->returnValue(true)); $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock); $fakePayment = new Varien_Object(); $fakePayment->setMethodInstance(Mage::getModel('ops/payment_cc')); $fakeOrder = new Varien_Object(); $fakeOrder->setPayment($fakePayment); $fakeOrder->setId(1); if ($setStoreId) { $fakeOrder->setStoreId(1); } $orderHelperMock = $this->getHelperMock('ops/order', array('getOrder')); $orderHelperMock->expects($this->any())->method('getOrder')->will($this->returnValue($fakeOrder)); $this->replaceByMock('helper', 'ops/order', $orderHelperMock); }
public function testGetEventDataObjectAdmin() { $this->setCurrentStore(0); $adminUser = new Varien_Object(); $adminUser->setId(1); $adminUser->setUsername('username'); $adminUser->setEmail('email'); $adminUser->setFirstname('firstname'); $adminUser->setLastname('lastname'); $adminSessionMock = $this->getModelMockBuilder('admin/session')->disableOriginalConstructor()->setMethods(array('getUser'))->getMock(); $adminSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($adminUser)); $this->replaceByMock('singleton', 'admin/session', $adminSessionMock); $adminSessionQuoteMock = $this->getModelMockBuilder('adminhtml/session_quote')->disableOriginalConstructor()->setMethods(null)->getMock(); $this->replaceByMock('singleton', 'adminhtml/session_quote', $adminSessionQuoteMock); $factory = new DEG_OrderLifecycle_Model_Lifecycle_Event_Factory(); $eventObject = $factory->getEventDataObject(); $this->assertInstanceOf('DEG_OrderLifecycle_Model_Lifecycle_Event_Admin_Event', $eventObject); }
protected function _prepareCollection() { /** @var $connector Smile_DigitalOceanManager_Model_Connector*/ $connector = Mage::getModel('digitaloceanmanager/connector'); $droplets = $connector->getDropletList(); $collection = new Varien_Data_Collection(); foreach ($droplets as $droplet) { $obj = new Varien_Object(); $obj->setId($droplet->id); $obj->setName($droplet->name); $obj->setVcpus($droplet->vcpus); $obj->setMemory($droplet->memory); $obj->setDisk($droplet->disk); $obj->setStatus($droplet->status); $obj->setRegion($droplet->region->name); $collection->addItem($obj); } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Prepare collection of errors * * @return Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Grid */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $removeButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button', '', array('class' => 'delete', 'label' => '', 'onclick' => 'addBySku.removeFailedItem(this)', 'type' => 'button'))->toHtml(); /* @var $parentBlock Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Abstract */ $parentBlock = $this->getParentBlock(); foreach ($parentBlock->getFailedItems() as $affectedItem) { // Escape user-submitted input if (isset($affectedItem['item']['qty'])) { $affectedItem['item']['qty'] = empty($affectedItem['item']['qty']) ? '' : (double) $affectedItem['item']['qty']; } $item = new Varien_Object(); $item->setCode($affectedItem['code']); if (isset($affectedItem['error'])) { $item->setError($affectedItem['error']); } $item->addData($affectedItem['item']); $item->setId($item->getSku()); /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); if (isset($affectedItem['item']['id'])) { $productId = $affectedItem['item']['id']; $item->setProductId($productId); $product->load($productId); /* @var $stockStatus Mage_CatalogInventory_Model_Stock_Status */ $stockStatus = Mage::getModel('cataloginventory/stock_status'); $status = $stockStatus->getProductStatus($productId, $this->getWebsiteId()); if (!empty($status[$productId])) { $product->setIsSalable($status[$productId]); } $item->setPrice(Mage::helper('core')->formatPrice($product->getPrice())); } $descriptionBlock = $this->getLayout()->createBlock('enterprise_checkout/adminhtml_sku_errors_grid_description', '', array('product' => $product, 'item' => $item)); $item->setDescription($descriptionBlock->toHtml()); $item->setRemoveButton($removeButtonHtml); $collection->addItem($item); } $this->setCollection($collection); return $this; }
/** * Prepare grid collection */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $cache = Mage::helper('varnish')->getRedisCache()->getFrontend(); $ids = $cache->getIdsMatchingTags(array('VARNISH-CACHETYPE-PER-PAGE')); foreach ($ids as $id) { $data = unserialize($cache->load($id)); $item = new Varien_Object(); $item->setId($id); $item->setStoreId($data->getStoreId()); $item->setParentUrl($data->getParentUrl()); $item->setBlockName($data->getNameInLayout()); $item->setFingerprint($id); $item->setProbeUrl($data->getUrl()); $collection->addItem($item); } $this->setCollection($collection); $sort = $this->getParam($this->getVarNameSort()) ? $this->getParam($this->getVarNameSort()) : $this->getDefaultSort(); $dir = $this->getParam($this->getVarNameDir()) ? $this->getParam($this->getVarNameDir()) : $this->getDefaultDir(); $this->_sortCollectionBy($sort, $dir); return parent::_prepareCollection(); }
/** * Prepare product * * @param array $productRow * @return Varien_Object */ protected function _prepareProduct(array $productRow) { $product = new Varien_Object(); $product->setId($productRow[$this->getIdFieldName()]); $productLoaded = Mage::getModel('catalog/product')->setData($productRow); $requestPath = $productLoaded->getUrl(); $idPath = sprintf('product/%d', $productLoaded->getEntityId()); if (($categoryIdAsc = Mage::helper('ascurl')->getCategoryIdAsc($productLoaded, true)) && Mage::getStoreConfig(self::USE_CANONICAL_URL_AT_GOOGLE_SITEMAP, $productLoaded->getStoreId())) { $idPath = sprintf('%s/%d', $idPath, $categoryIdAsc); } $rewrited = $this->_getWriteAdapter()->query(str_replace('to_replace', $idPath, $this->rewriteQuery))->fetch(); if (isset($rewrited['request_path'])) { $product->setUrl($rewrited['request_path']); } try { if (Mage::getStoreConfig(AW_Ascurl_Model_Sitemap::USE_IMAGES, $productLoaded->getStoreId())) { $product->setImageUrl($productLoaded->getImageUrl()); } } catch (Exception $ex) { } return $product; }
/** * Prepare catalog object * * @param array $row * @return Varien_Object */ protected function _prepareObject(array $row) { $entity = new Varien_Object(); $entity->setId($row[$this->getIdFieldName()]); $entity->setUrl($this->_getEntityUrl($row, $entity)); return $entity; }
/** * Prepare product * * @param array $productRow * @return Varien_Object */ protected function _prepareProduct(array $productRow) { $product = new Varien_Object(); $product->setId($productRow[$this->getIdFieldName()]); $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); $product->setUrl($productUrl); return $product; }
/** * Process product data before save * * @param Varien_Object $object * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product */ protected function _beforeSave(Varien_Object $object) { if (!$object->getId() && $object->getSku()) { $object->setId($this->getIdBySku($object->getSku())); } $categoryIds = $object->getCategoryIds(); if ($categoryIds) { $categoryIds = AO::getModel('catalog/category')->verifyIds($categoryIds); } $object->setData('category_ids', implode(',', $categoryIds)); return parent::_beforeSave($object); }
/** * Submit action * * @return string */ public function submitAction() { $params = $this->getRequest()->getParams(); $response = new Varien_Object(); try { $request = $this->_getRequestModel()->setRequest($params['request'])->dispatch(); $response->setStatus('OK'); $response->setRequest($params['request']); $response->setMessage($request->getMessage()); $response->setType($request->getType()); if ($request->getType() == MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_PROMPT) { $key = $this->_savePrompt($params['request']); $response->setId($key); } } catch (Exception $e) { $response->setStatus('ERROR'); $response->setType(MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_ERROR); $response->setMessage($e->getMessage()); } if ($response->getType() == 'FILE') { $requestDetails = preg_split('/\\s+/', $params['request']); $this->_prepareDownloadResponse($requestDetails[1] . '_export.csv', $response->getMessage()); } else { $this->getResponse()->setBody($response->toJson()); } }
/** * Returns Google Base recommended Item Types * * @param string $targetCountry Two-letters country ISO code * @return array */ public function getItemTypes($targetCountry) { $locale = Mage::getSingleton('googlebase/config')->getCountryInfo($targetCountry, 'locale'); $location = self::ITEM_TYPES_LOCATION . '/' . $locale; $itemTypes = array(); foreach ($this->getGuestService()->getFeed($location)->entries as $entry) { if (isset($entry->extensionElements[1])) { // has attributes node? $typeAttributes = $entry->extensionElements[1]->extensionElements; if (is_array($typeAttributes) && !empty($typeAttributes)) { // only items with attributes allowed $type = $entry->extensionElements[0]->text; $item = new Varien_Object(); $item->setId($type); $item->setName($entry->title->text); $item->setLocation($entry->id->text); $itemTypes[$type] = $item; $attributes = array(); foreach ($typeAttributes as $attr) { $name = $attr->extensionAttributes['name']['value']; $type = $attr->extensionAttributes['type']['value']; $attribute = new Varien_Object(); $attribute->setId($name); $attribute->setName($name); $attribute->setType($type); $attributes[$name] = $attribute; } ksort($attributes); $item->setAttributes($attributes); } } } ksort($itemTypes); $this->_itemTypes = $itemTypes; return $itemTypes; }
public function getTemplateInfo() { $apikey = Mage::helper('mailchimp')->getApiKey(); if (!$apikey || !$this->getTemplateId()) { return false; } $this->MCAPI($apikey); $retval = $this->templateInfo($this->getTemplateId(), $this->getTid()); if ($this->errorCode) { $this->setErrorOutput(); return false; } $template = new Varien_Object(); $template->addData($retval); $template->setId($this->getTemplateId()); return $template; }