/** * (non-PHPdoc) * * @see Magmi_ItemProcessor::processItemAfterId() */ public function processItemAfterId(&$item, $params = null) { if ($params["new"] == true) { $this->initializeBaseCols($item); $this->initializeBaseAttrs($item); //force url key for new items for magento > 1.7.x if ($this->getMagentoVersion() > "1.7.x" && empty($item['url_key'])) { $item["url_key"] = Slugger::slug($item["name"]); } } // forcing default values for mandatory processing columns foreach ($this->_forcedefault as $k => $v) { if (isset($item[$k]) && trim($item[$k]) == "") { $item[$k] = $v; } } return true; }
/** * (non-PHPdoc) * * @see Magmi_ItemProcessor::processItemAfterId() */ public function preprocessItemAfterId(&$item, $params = null) { if ($params["new"] == true) { $this->initializeBaseCols($item); $this->initializeBaseAttrs($item); //force url key for new items for magento > 1.7.x if ($this->checkMagentoVersion("1.7.x", ">") && empty($item['url_key'])) { $item["url_key"] = Slugger::slug($item["name"]); } } else { //if we have an existing item, get some structural info from identification meta if (!isset($item["type"])) { $item["type"] = $params["type"]; } } // forcing default values for mandatory processing columns foreach ($this->_forcedefault as $k => $v) { if (isset($item[$k]) && trim($item[$k]) == "") { $item[$k] = $v; } } return true; }
public function builProductUrlRewrite($pid, $dorewrite = false) { //new url $sql = "SELECT ea.attribute_code,cpei.value,cpev.attribute_id,cpev.value \n\t\t\t FROM {$this->tns["cpe"]} AS cpe\n\t\t\t JOIN {$this->tns["ea"]} as ea ON ea.attribute_code IN ('url_key','name')\n\t\t\t JOIN {$this->tns["cpev"]} as cpev ON cpev.entity_id=cpe.entity_id AND cpev.attribute_id=ea.attribute_id\n\t\t\t JOIN {$this->tns["cpei"]} as cpei ON cpei.entity_id=cpe.entity_id AND cpei.attribute_id=? AND cpei.value>1\n\t\t\t WHERE cpe.entity_id=?"; $result = $this->selectAll($sql, array($this->visinf["attribute_id"], $pid)); // nothing to build, product is not visible,return if (count($result) == 0) { return; } // see what we get as available product attributes foreach ($result as $row) { if ($row["attribute_code"] == "url_key") { $pburlk = nullifempty($row["value"]); } if ($row["attribute_code"] == "name") { $pname = $row["value"]; } } $baseurl = isset($pburlk) ? $pburlk : Slugger::slug($pname); // if we've got an url key use it, otherwise , make a slug from the product name as url key $urlend = $this->getParam("OTFI:useurlending", 1) == 1 ? $this->getParam("OTFI:urlending", ".html") : ""; //check duplicates if (!isset($this->usedurls)) { $this->usedurls = array(); $sql = "SELECT product_id,request_path as path FROM {$this->tns["curw"]}"; $data = $this->selectAll($sql); foreach ($data as $line) { $this->usedurls[$line['path']] = $line['product_id']; } unset($data); } $candidate = $baseurl . $urlend; $index = 0; while (isset($this->usedurls[$candidate]) && $this->usedurls[$candidate] != $pid) { $index++; $candidate = $baseurl . '-' . $index . $urlend; } $purlk = $candidate; $this->usedurls[$candidate] = $pid; if ($dorewrite) { //rewrites SQL $rewurlsql = "SELECT cpe.entity_id,cs.store_id,\n \t\t\t\t UUID() as id_path,\n \t\t\t\t curw.request_path as target_path,\n \t\t\t\t ? AS request_path,\n \t\t\t\t 0 as is_system,\n \t\t\t\t 'RP' as options\n \t\t\t\t FROM {$this->tns["cpe"]} as cpe\n \t\t\t\t JOIN {$this->tns["cpw"]} as cpw ON cpw.product_id=cpe.entity_id\n \t\t\t\t JOIN {$this->tns["cs"]} as cs ON cs.website_id=cpw.website_id\n \t\t\t\t JOIN {$this->tns["ccp"]} as ccp ON ccp.product_id=cpe.entity_id\n \t\t\t\t JOIN {$this->tns["cce"]} as cce ON ccp.category_id=cce.entity_id\n \t\t\t\t JOIN {$this->tns["curw"]} as curw ON curw.product_id=cpe.entity_id\n AND curw.store_id=cs.store_id AND curw.request_path!=?\n \t\t\t\t WHERE cpe.entity_id=?"; //read rewrites $rewrites = $this->selectAll($rewurlsql, array($purlk, $purlk, $pid)); } // delete old "system" url rewrite entries for product $sql = "DELETE FROM {$this->tns["curw"]} WHERE product_id=? AND is_system=1"; $this->delete($sql, $pid); // product url index info $produrlsql = "SELECT cpe.entity_id,cs.store_id,\n\t\t\t\t CONCAT('product/',cpe.entity_id) as id_path,\n\t\t\t\t CONCAT('catalog/product/view/id/',cpe.entity_id) as target_path,\n\t\t\t\t ? AS request_path,\n\t\t\t\t 1 as is_system\n\t\t\t\t FROM {$this->tns["cpe"]} as cpe\n\t\t\t\t JOIN {$this->tns["cpw"]} as cpw ON cpw.product_id=cpe.entity_id\n\t\t\t\t JOIN {$this->tns["cs"]} as cs ON cs.website_id=cpw.website_id\n\t\t\t\t JOIN {$this->tns["ccp"]} as ccp ON ccp.product_id=cpe.entity_id\n\t\t\t\t JOIN {$this->tns["cce"]} as cce ON ccp.category_id=cce.entity_id\n\t\t\t\t WHERE cpe.entity_id=?"; // insert lines $sqlprod = "INSERT INTO {$this->tns["curw"]} (product_id,store_id,id_path,target_path,request_path,is_system) {$produrlsql} ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; $this->insert($sqlprod, array($purlk, $pid)); //insert rewrites if ($dorewrite && count($rewrites) > 0) { $fields = $this->arr2values(array_values($rewrites[0])); $data = array(); $ins = array(); for ($i = 0; $i < count($rewrites); $i++) { $data = array_merge($data, array_values($rewrites[$i])); $ins[] = "({$fields})"; } //insert rewrites $sqlrew = "INSERT INTO {$this->tns["curw"]} (product_id,store_id,id_path,target_path,request_path,is_system,options) VALUES " . implode(",", $ins) . " ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; $this->insert($sqlrew, $data); unset($ins); unset($data); } return $purlk; }
public function extractCatAttrs(&$catdef) { $cdefs = explode($this->_tsep, $catdef); $odefs = array(); $clist = array(); foreach ($cdefs as $cdef) { $parts = explode("::", $cdef); $cp = count($parts); $cname = trim($parts[0]); $odefs[] = $cname; $attrs = array("name" => $cname, "is_active" => $cp > 1 ? $parts[1] : 1, "is_anchor" => $cp > 2 ? $parts[2] : 1, "include_in_menu" => $cp > 3 ? $parts[3] : 1, "url_key" => Slugger::slug($cname), "url_path" => Slugger::slug(implode("/", $odefs), true) . $this->getParam("CAT:urlending", ".html")); $clist[] = $attrs; } $catdef = implode($this->_tsep, $odefs); return $clist; }
public function builProductUrlRewrite($pid) { $sql = "SELECT ea.attribute_code,cpei.value,cpev.attribute_id,cpev.value \n\t\t\t FROM {$this->tns["cpe"]} AS cpe\n\t\t\t JOIN {$this->tns["ea"]} as ea ON ea.attribute_code IN ('url_key','name')\n\t\t\t JOIN {$this->tns["cpev"]} as cpev ON cpev.entity_id=cpe.entity_id AND cpev.attribute_id=ea.attribute_id\n\t\t\t JOIN {$this->tns["cpei"]} as cpei ON cpei.entity_id=cpe.entity_id AND cpei.attribute_id=? AND cpei.value>1\n\t\t\t WHERE cpe.entity_id=?"; $result = $this->selectAll($sql, array($this->visinf["attribute_id"], $pid)); //nothing to build, product is not visible,return if (count($result) == 0) { return; } //see what we get as available product attributes foreach ($result as $row) { if ($row["attribute_code"] == "url_key") { $pburlk = nullifempty($row["value"]); } if ($row["attribute_code"] == "name") { $pname = $row["value"]; } } //if we've got an url key use it, otherwise , make a slug from the product name as url key $urlend = $this->getParam("OTFI:urlending", ".html"); $purlk = (isset($pburlk) ? $pburlk : Slugger::slug($pname)) . $urlend; //delete old "system" url rewrite entries for product $sql = "DELETE FROM {$this->tns["curw"]} WHERE product_id=? AND is_system=1"; $this->delete($sql, $pid); //product url index info $produrlsql = "SELECT cpe.entity_id,cs.store_id,\n\t\t\t\t CONCAT('product/',cpe.entity_id) as id_path,\n\t\t\t\t CONCAT('catalog/product/view/id/',cpe.entity_id) as target_path,\n\t\t\t\t ? AS request_path,\n\t\t\t\t 1 as is_system\n\t\t\t\t FROM {$this->tns["cpe"]} as cpe\n\t\t\t\t JOIN {$this->tns["cpw"]} as cpw ON cpw.product_id=cpe.entity_id\n\t\t\t\t JOIN {$this->tns["cs"]} as cs ON cs.website_id=cpw.website_id\n\t\t\t\t JOIN {$this->tns["ccp"]} as ccp ON ccp.product_id=cpe.entity_id\n\t\t\t\t JOIN {$this->tns["cce"]} as cce ON ccp.category_id=cce.entity_id\n\t\t\t\t WHERE cpe.entity_id=?"; //insert lines $sqlprod = "INSERT INTO {$this->tns["curw"]} (product_id,store_id,id_path,target_path,request_path,is_system) {$produrlsql} ON DUPLICATE KEY UPDATE request_path=VALUES(`request_path`)"; $this->insert($sqlprod, array($purlk, $pid)); return $purlk; }
/** * Extract attributes like is_anchor and include_in_menu * * @param String &$catdef A category string. Will be cleaned from options. * * @return Array A list of category info */ public function extractCatAttrs(&$catdef) { $cdefs = explode($this->_tsep, $catdef); $odefs = array(); $s_odefs = array(); $clist = array(); foreach ($cdefs as $cdef) { $parts = explode("::", $cdef); $cname = trim($parts[0]); $s_cname = $cname; $last = array_pop($parts); // Check for storename::[defaultname] syntax if ($cname !== $last && stripos($last, '[') === 0) { $cname = trim($last, '[]'); } else { // If not translation add $last back to array $parts[] = $last; } $cp = count($parts); $odefs[] = $cname; $s_odefs[] = $s_cname; $attrs = array("name" => $cname, "is_active" => $cp > 1 ? $parts[1] : 1, "is_anchor" => $cp > 2 ? $parts[2] : 1, "include_in_menu" => $cp > 3 ? $parts[3] : 1, "url_key" => Slugger::slug($cname), "url_path" => Slugger::slug(implode("/", $odefs), true) . $this->getParam("CAT:urlending", ".html")); if ($cname !== $s_cname) { $attrs['translated_name'] = $s_cname; $attrs['translated_url_key'] = Slugger::slug($s_cname); $attrs['translated_url_path'] = Slugger::slug(implode('/', $s_odefs), true) . $this->getParam('CAT:urlending', '.html'); } $clist[] = $attrs; } $catdef = implode($this->_tsep, $odefs); return $clist; }