I have an array of information of places and I wanna use them to create multiple pages in a phpfox site.
First I tried to manually insert data in phpfox database (in tables of phpfox_pages and phpfox_pages_text).
The page is shown up in the site but when opening it's link, the site says:
The page you are looking for cannot be found.
Do you know what other tables should I manipulate to make it work?
Or do you know any plugin for phpfox to do the same?
Thanks,
Solved ( With #Purefan Guide):
"Pages" also has a user
If you take a look at phpfox_user table, you'll found out how to fetch new records on that. But there are two ambiguous fields in that table ( password & password_salt). You can use this script to create values for the fields:
<?php
function generateRandomString()
{
$length = 164;
$characters = '-_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
$sSalt = '';
for ($i = 0; $i < 3; $i++)
{
$sSalt .= chr(rand(33, 91));
}
$sPossible = generateRandomString();
$sPassword = '';
$i = 0;
while ($i < 10)
{
$sPassword .= substr($sPossible, mt_rand(0, strlen($sPossible)-1), 1);
$i++;
}
$password_Salt_Field = $sSalt;
$password_Field = md5(md5($sPassword) . md5($sSalt));
Phpfox has 2 very similar modules: "Pages" and "Page", you create "Pages" if you want people to "like" them, post in them, add photos... a "Page" is static so I think this is what you want, in that case I would add to phpfox_page and phpfox_page_text
Edit: Ok then you are probably forgetting to insert into phpfox_user, a "Pages" also has a user, the following should shed some light:
$iUserId = $this->database()->insert(Phpfox::getT('user'), array(
'profile_page_id' => $iId,
'user_group_id' => NORMAL_USER_ID,
'view_id' => '7',
'full_name' => $this->preParse()->clean($aVals['title']),
'joined' => PHPFOX_TIME,
'password' => Phpfox::getLib('hash')->setHash($sPassword, $sSalt),
'password_salt' => $sSalt
)
);
Look in the file /module/pages/include/service/process.class.add around line 338 (depending on your version).
Related
I'm creating 192 html pages using this function in the web.php file, but when it creates the fifth page gives me the error.
function()
{
$homepage = Page::find(1);
$articles_show = Article::where(function ($query) {
$query->where(function ($query2) {
$query2->where('draft', 0)->whereNull('publication_date');
})->orWhere(function ($query2) {
$query2->where('draft', 0)->where('publication_date', '<=', DateHelper::currentDateTime());
});
})->orderBy('publicated_at', 'DESC')->get();
$last_page = ceil($articles_show->count() / 8);
$articles = [];
$count = 0;
for ($i = 5; $i <= $last_page; $i++) {
$filename = 'page'.$i.'.html';
$max_desc_id = $i * 8;
$min_desc_id = $max_desc_id - 7;
foreach ($articles_show as $article) {
$count++;
if ($article->desc_id >= $min_desc_id && $article->desc_id <= $max_desc_id) {
$articles[] = $article;
}
if (($count % 8) == 0) {
$count = 0;
File::put(
resource_path('views/allArticlesHtml/'.$filename),
view('allArticlesTemplate')->with([
"articles" => $articles,
"homepage" => $homepage,
"this_page" => $i,
"last_page" => $last_page
])->render()
);
continue;
}
}
$articles = [];
// if(($count % 8) == 0){
// }
}
}
The pages are created correctly but it's way too slow.
I don't really know if i am doing this in the right way or not, i'm still very new at programming and i don't know how to improve or recreate this code.
I had this issue the other day. You can do this workaround:
Every time you create 1 file under that command put this:
set_time_limit(30);
It will reset the time limit to 30 seconds and every time reset it.
Reference: https://www.php.net/manual/en/function.set-time-limit.php
I read your code. I'll try to suggest you best solution.
why you are trying to create html files with same content?
you can easily use blade engine and extend a template in different file.
to solve the error Maximum execution time of 60 seconds exceeded
you need to increase max_execution_time value in php.ini file.
or put ini_set('max_execution_time', 180) at the top of php file .
but if you want an alternative way of creating files describe your initial problem.
In wordpress, when a post category (or tag) is clicked, all posts that match the clicked category (or tag) is returned, because of <?php the_content(); ?>
In my case, every post has an image in it, so how can I only fetch the images when a category (or tag) is clicked? I'm not familiar what code I need to use.
Update: I'm trying not to use plugins. My apologies for not mentioning that earlier. What I'm trying to achieve is something like The Sartorialist - All posts have images, click on any category (or tag) associated with any post and only images are fetched.
Update 2: I tried this:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '</li>';
}
}
?>
The only weird thing is, and I'm trying to figure out, another image from the media library also shows up, without it being in any of my posts.
I also found this plugin which is very close to what I want, but unfortunately it has to be in a separate page, not the in category page.
You can achieve this with something like this:
<?php
function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo ''.$image[$num].""; }
$more = 0;
}
?>
source
I'm trying to read the list of products from Magento over the SOAP API (V2) and try to do some/any type of pagination.
Simple scenario:
var filters = new filters();
var products = catalogProductList(out pe, Connection.Session, filters, null);
This crashes Magento with: "Allowed memory size of 1073741824 bytes exhausted (tried to allocate 72 bytes."
I've tried to add pagination by specifying two complex filters on the product_id:
filters.complex_filter = new complexFilter[]
{
new complexFilter()
{
key = "product_id",
value = new associativeEntity()
{
key = "gt",
value = "400"
}
},
new complexFilter()
{
key = "product_id",
value = new associativeEntity()
{
key = "lt",
value = "1000"
}
}
};
However in this scenario only the second filter is applied, the first one is ignored.
I was thinking of reading the category tree and then the assigned products but there are lots of products that are not assigned to any category or to multiple categories so I'll either miss them or get them multiple times.
Is there a way to read the products list using some type of pagination so I don't read the complete list at once?
(Note: Requesting to increase memory is not really an option)
I've come up with a pretty good solution for this. Hope this helps someone.
$in = array();
for ($i = ($page * $size) - $size; $i < ($page * $size); $i++) {
$in[] = $i + 1;
}
$complexFilter = array('complex_filter' =>
array(
array(
'key' => 'product_id',
'value' => array(
'key' => 'in',
'value' => join(",", $in)
)
)
)
);
It looks like the answer you need is described at https://stackoverflow.com/a/22874035/2741137
Apparently, you can capitalize PRODUCT_ID in one of the two filter conditions to work around Magento's limitation that prevents two filter conditions on the same key.
I've successfully done the following in PHP:
$filters = new StdClass();
$filters->complexFilter = array(
array( 'key' =>'sku', 'value' => array('lt'=>'03969999')),
array( 'key' => 'sku', 'value' => array('gt'=>'03969000')),
);
Although, according to
<complexType name="filters"><all><element name="filter" type="typens:associativeArray" minOccurs="0"/><element name="complex_filter" type="typens:complexFilterArray" minOccurs="0"/></all></complexType>
Maybe it needs to be "$filters->complex_filter = array();"? The first code appeared to have worked for me.
Ugly as hell, but works for me :
public catalogProductEntity[] GetProducts()
{
int storeId;
catalogProductEntity[] catalogEntity;
List<catalogProductEntity> res = new List<catalogProductEntity>();
Client.catalogProductCurrentStore(out storeId, SessionId, null);
var filters = new filters();
filters.complex_filter = new complexFilter[1];
filters.complex_filter[0] = new complexFilter();
complexFilter filter = filters.complex_filter[0];
filter.key = "name";
filter.value = new associativeEntity();
associativeEntity assoc = filter.value;
assoc.key = "like";
//A to Z.
for (char i = 'A'; i <= 'Z'; i++)
{
assoc.value = i + "%";
Client.catalogProductList(out catalogEntity, SessionId, filters, null);
res.AddRange(catalogEntity);
}
//Starts with #.
assoc.value = "#%";
Client.catalogProductList(out catalogEntity, SessionId, filters, null);
res.AddRange(catalogEntity);
//0 to 9
for (int i = 0; i <= 9; i++)
{
assoc.value = i + "%";
Client.catalogProductList(out catalogEntity, SessionId, filters, null);
res.AddRange(catalogEntity);
}
return res.ToArray();
}
When a new simple product is added (via CSV or manually) we need to check if the appropriate configurable product has been added (where SKU = "item_number-item_colour_code" e.g. BLEA2606B-BK001). If the configurable product exists then associate the simple product. If the configurable product does not exist then create using the data in the simple product AND then associate the simple product.
I found some help from HERE but don't know how check if configurable product already exists, and if not how to create one.
Here is the script file that I downloaded. Can anybody advice if this will work with my scenario?
EDITED
I have scraped the idea of creating configurable product in import. I am doing it by capturing the catalog_product_save_after event now. Hopefully that will get me somewhere.
EDITED 2
OK, Finally, I have it working. I'm doing it in the observer. I know it slows down the product save process but couldn't think of any other way. Thats what I'm doing:
public function productSave($observer)
{
$p = $observer->getProduct();
$pr = Mage::getModel('catalog/product')->load($p->getId());
$attributeValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($pr->getId(), 'size'); //loads attribute option value
$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($pr)->getQty();
Mage::log('Qty: '.$qtyStock.$pr->getId(), null, 'test.txt');
if ($pr->getTaxClassId() == '0' || !isset($pr->getTaxClassId)) {
$taxClass = 'None';
} elseif ($pr->getTaxClassId() == '2') {
$taxClass = 'Taxable Goods';
} elseif ($pr->getTaxClassId() == '4') {
$taxClass = 'Shipping (not used by AvaTax)';
} elseif ($pr->getTaxClassId() == '5') {
$taxClass = 'General';
}
$_configSku = $pr->getItemNumber().'-'.$pr->getItemColourCode();
$category = array();
$categoryCollection = $pr->getCategoryCollection();
foreach ($categoryCollection as $cat) {
$category[] = $cat->getId();
}
$_configExist = Mage::getModel('catalog/product')->loadByAttribute('sku',$_configSku);
if($_configExist && $_configSku != '-') {
//Mage::log($_configExist, null, 'test.txt');
//Mage::log($_configSku, null, 'test.txt');
$new_ids = array();
$current_ids = $_configExist->getTypeInstance()->getUsedProductIds();
foreach($current_ids as $temp_id)
{
$new_ids[] = $temp_id;
}
}
if(!$_configExist && $_configSku != '-') {
$att_size = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product','size');
$att_sizes = $this->__getAttList('size');
$confProduct = Mage::getModel('catalog/product');
$confProduct->setAttributeSetId('10');
$confProduct->setSku($_configSku);
$confProduct->setTypeId('configurable');
$confProduct->setName($pr->getName());
$confProduct->setDescription($pr->getDescription());
$confProduct->setShortDescription($pr->getShortDescription());
$confProduct->setCreatedAt(strtotime('now'));
$confProduct->setPrice($pr->getPrice());
$confProduct->setStatus(1);
$confProduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$confProduct->setWebsiteIDs(array(1));
$confProduct->setStockData(array(
'is_in_stock' => 1,
'qty' => 9999
));
$confProduct->setTaxClassId( $taxClass );
$confProduct->setCategoryIds( $category );
/* Set Configurable Attributes */
$confProduct->setConfigurableAttributesData($tmp = array(
array_merge($att_size->getData(), array('label' => '', 'values' => $size_values))
));
$simpleProducts = array(
$pr->getId()=>array( 'attribute_id'=>'145', 'label'=>'size', 'value_index'=>$attributeValue, 'is_percent'=>0, 'pricing_value'=>'' )
);
/* Set Associated Products */
$confProduct->setConfigurableProductsData( $simpleProducts );
//print_r( get_class_methods( $confProduct ) );
$confProduct->save();
}
elseif ($_configExist && !in_array($pr->getId(), $new_ids)) {
$new_ids = array();
$current_ids = $_configExist->getTypeInstance()->getUsedProductIds();
$current_ids[] = $pr->getId();
$current_ids = array_unique($current_ids);
foreach($current_ids as $temp_id)
{
parse_str("position=", $new_ids[$temp_id]);
}
Mage::log('inside', null, 'test.txt');
Mage::log($current_ids, null, 'test.txt');
$_configExist->setConfigurableProductsData($new_ids)->save();
}
All works fine with manual product save/update and import csv (it is slow but works). The only thing is, in configurable product, the Attribute Name field is empty. How to set attribute name there?
with magmi you can easily create configurable products, and more awesome stuff
I have found the way. See EDITED 2 section in the question for the solution.
I have a model to fetch data from mysql database. I am using the table and pagination library to display data. When displaying the data there is a column called "DELETE", which is used for deleting each rows. Instead of using the text "DELETE" I want to use an image. I have tried a lot to add it in the model but it is not working. Would you please kindly help me?
Thanks in Advance :)
function batch_list()
{
$config['per_page'] = 15;
$this->db->select('batchname, class, batchinstructor');
$this->db->order_by("batchid", "desc");
$rows = $this->db->get('batch',$config['per_page'],$this->uri->segment(3))->result_array();
$sl = $this->uri->segment(3) + 1; // so that it begins from 1 not 0
foreach ($rows as $count => $row)
{
array_unshift($rows[$count], $sl.'.');
$sl = $sl + 1;
$rows[$count]['batchname'] = anchor('batch_list/get/'.$row['batchname'],$row['batchname']);
$rows[$count]['Edit'] = anchor('update_student/update/'.$row['batchname'],'Edit');
$rows[$count]['Delete'] = anchor('report/'.$row['batchname'],'<img src="base_url().support/images/icons /cross.png" alt="Delete" />"'); //<<< This is where I actually tried/want to add the image
}
return $rows;
}
Please clarify what you mean by not working.
Anyway,
for now I am guessing your problem is your escaping, try:
anchor('report/'.$row['batchname'], '<img src="'.base_url().'support/images/icons/cross.png" alt="Delete" />');
or if you are using the html helper you can use
anchor('report/'.$row['batchname'], img('support/images/icons/cross.png'));
(if you want the alt attribute you will need to use the array form)
$img = array(
'src' => 'support/images/icons/cross.png',
'alt' => 'Delete'
);
anchor('report/'.$row['batchname'], img($img));